steve103
Posts: 16
Joined: Sun Oct 29, 2017 1:11 pm

How set multiple static ip addresses on single interface with stretch

Tue Jan 02, 2018 10:49 pm

I require to set multiple static ip addresses on a single interface (i.e. with the same interface ip address) using the raspbian stretch OS: VERSION = "9 (stretch)"

Having read many articles, I believe with stretch that I need to update dhcpcd.conf. I am able to set a single static ip address, but have not been able to set multiple ip addresses.

Can you clarify if it is possible (if so how?) - do I need to use /etc/network/interfaces (I've read this has been deprecated).

thank you...

mattmiller
Posts: 1776
Joined: Thu Feb 05, 2015 11:25 pm

Re: How set multiple static ip addresses on single interface with stretch

Tue Jan 02, 2018 10:53 pm

what's your use case as there are many ways of doing this depending on why?

steve103
Posts: 16
Joined: Sun Oct 29, 2017 1:11 pm

Re: How set multiple static ip addresses on single interface with stretch

Tue Jan 02, 2018 11:12 pm

I am polling several devices having different ip addresses on different subnets. Currently I manually create the static ip addresses using
ip address add [ip]/[mask-digits] dev eth0

jbudd
Posts: 484
Joined: Mon Dec 16, 2013 10:23 am

Re: How set multiple static ip addresses on single interface with stretch

Wed Jan 03, 2018 2:44 am

Not sure this is exactly what you need, but you can create static ip aliases for different networks by means of a file /etc/dhcpcd.exit-hook. Something like this:

Code: Select all

aliasip=
if $if_up; then
    # Wireless alias
    case "$ifssid" in
       EE-BrightBox-maryann) aliasip="192.168.1.142/24";;
       hootoo) aliasip="10.10.10.142/24";;
    esac

    # Ethernet alias
    case "$interface" in
       eth0) aliasip="192.168.1.142/24";;
    esac

    if [ -n "$aliasip" ]; then
       echo "Adding alias of $aliasip to $interface"
       ip a a "$aliasip" dev "$interface"
    fi
fi

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 21 guests