Hello,
I am wondering how I go about setting multiple static IPs on the same subnet to the same interface?
I have tried editing the /etc/dhcpcd.conf file as such..
interface eth0
static ip_address=192.168.1.10/24
static routers=192.168.1.1
static domain_name_servers=127.0.0.1
interface eth0:1
static ip_address=192.168.1.15/24
static routers=192.168.1.1
static domain_name_servers=127.0.0.1
Re: Setting Multiple Static IPs
I may be wrong, but I think this may be one time that you can actually put the definition in /etc/network/interfaces or in a file in /etc/network/interfaces.d as dhcpcd won't know about the interface.
I just tested this and it works, except that ip addr doesn't show the interface and ifconfig does?
I just tested this and it works, except that ip addr doesn't show the interface and ifconfig does?
Re: Setting Multiple Static IPs
I'm not sure what the syntax should look like in that file...
I did a and that appeared to do the trick. But... it doesn't persist beyond a restart?
I did a
Code: Select all
ifconfig eth0:0 192.168.1.15
Code: Select all
$> ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether b8:27:eb:9c:a4:29 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.10/24 brd 192.168.1.255 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.1.15/24 brd 192.168.1.255 scope global secondary eth0:0
valid_lft forever preferred_lft forever
inet6 fe80::1dcf:330c:d3c9:f493/64 scope link
valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether b8:27:eb:c9:f1:7c brd ff:ff:ff:ff:ff:ff
inet 192.168.1.11/24 brd 192.168.1.255 scope global wlan0
valid_lft forever preferred_lft forever
inet6 fe80::f513:52d8:ca02:8509/64 scope link
valid_lft forever preferred_lft forever
Re: Setting Multiple Static IPs
My current /etc/network/interfaces file..
Code: Select all
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
Re: Setting Multiple Static IPs
Ok, it looks like it's not that simple. I will work on this and see if I can come up with a way to do it. I'll be needing this myself as I plan to upgrade all of my Raspberrys to Stretch at some point and some of them have aliased intefaces.
Re: Setting Multiple Static IPs
I have been battling this issue also. Did much as the OP did, added static 'eth0' and 'eth0:1' entries to /etc/dhcpcd.conf, rebooted to ensure they took, but 'ifconfig', 'ip addr', 'hostname -I', 'netstat -nr' are all only showing the one 'eth0' address.
I have had it working in the past to some degree; it worked when both IP were on the same network ( eg 192.168.0.110 and 192.168.0.210 ), though not when they were not ( eg 192.168.0.110 and 172.16.0.110 ), which is why I had reverted back to using /etc/network/interfaces.
No need to "guess what?"; it works perfectly well with /etc/network/interfaces ...
My /etc/network/interfaces in its entirety is ...
I don't have a problem with using 'dhcpcd' and would be using it and recommending it if it actually worked and would do what I want it to do. Unfortunately it doesn't. Despite people saying it will, and no end of suggestions and searching for information, it never has for what I want. I am tired of hearing "this should work" when it doesn't, and it now seems more broken than it was before.
It took just a few minutes to edit /etc/network/interfaces and get things working; I have wasted hours on dhcpcd, quite possibly days in total.
I have had it working in the past to some degree; it worked when both IP were on the same network ( eg 192.168.0.110 and 192.168.0.210 ), though not when they were not ( eg 192.168.0.110 and 172.16.0.110 ), which is why I had reverted back to using /etc/network/interfaces.
No need to "guess what?"; it works perfectly well with /etc/network/interfaces ...
Code: Select all
pi@Pi3B:~$ hostname -I
192.168.0.210 172.16.0.210 192.168.0.110 172.16.0.110
pi@Pi3B:~$
Code: Select all
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.0.210
gateway 192.168.0.1
netmask 255.255.255.0
broadcast 192.168.0.255
auto eth0:1
iface eth0:1 inet static
address 192.168.0.110
gateway 192.168.0.1
netmask 255.255.255.0
broadcast 192.168.0.255
auto eth0:2
iface eth0:2 inet static
address 172.16.0.210
gateway 172.16.0.1
netmask 255.255.255.0
broadcast 172.16.0.255
auto eth0:3
iface eth0:3 inet static
address 172.16.0.110
gateway 172.16.0.1
netmask 255.255.255.0
broadcast 172.16.0.255
auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
It took just a few minutes to edit /etc/network/interfaces and get things working; I have wasted hours on dhcpcd, quite possibly days in total.
Re: Setting Multiple Static IPs
hippy, I agree. I suspect I will end up removing dhcpcd from the Pis where I need non-standard interface definitions and just using the interfaces file instead.
Just to emphasise though, this is a bit of a special case and normall I would just edit dhcpcd.conf for a simple static address assignment.
Just to emphasise though, this is a bit of a special case and normall I would just edit dhcpcd.conf for a simple static address assignment.
Re: Setting Multiple Static IPs
I agree. Most Pi users will simply use DHCP or assign one static IP address, and it seems fine for that.
It does however appear that the unusual cases crop up fairly regularly and people are often told 'don't edit /etc/network/interfaces - that's not the way to do it!'. And I would agree with that; it's not. But the way it should be done needs to work.
Re: Setting Multiple Static IPs
thanks @hippy, i would like to follow you, but have 2 questions:
-1- how you disable dhcpcd?
-2- what is the way to change back to the eth0 name under STRETCH?
OR is this the way?
because i still have on a RPI2 with wlan adapter using STRETCH ( new install, not upgrade from JESSIE )
would be nice if you could add that two things to your post pls.pi@RPI2:~ $ ls /sys/class/net/
enxb827eb6e15fc lo wlx48022a53056d
pi@RPI2:~ $
Last edited by KLL on Sat Aug 26, 2017 2:46 pm, edited 2 times in total.
Re: Setting Multiple Static IPs
There must be something I am missing here. I tried your suggestion with an RPi3 and Stretch. My ethernet interface will not even start. It doesn't appear in ifconfig. What am I missing?
My advice applies to RaspiOS only. Please mention if you use another OS.
-
- Posts: 2
- Joined: Mon Mar 04, 2019 8:11 am
Re: Setting Multiple Static IPs
Hello,
I'm beginner for using it, would you help me what first i can do to set up multiple IP for my raspberry pi. I mean, i wanna set up one from PC and one from Wireless ? Please help, Thanks Before.
I'm beginner for using it, would you help me what first i can do to set up multiple IP for my raspberry pi. I mean, i wanna set up one from PC and one from Wireless ? Please help, Thanks Before.
Re: Setting Multiple Static IPs
Agung Setiawan wrote: ↑Tue Apr 02, 2019 4:06 amHello,
I'm beginner for using it, would you help me what first i can do to set up multiple IP for my raspberry pi. I mean, i wanna set up one from PC and one from Wireless ? Please help, Thanks Before.
This is what I did in dhcpcd.conf for setting different static IPs for LAN and WiFi:
Code: Select all
interface eth0
static ip_address=192.168.1.aaa/24
static routers=192.168.1.1
static domain_name_servers=xxx.xxx.xxx.xxx
interface wlan0
static ip_address=192.168.1.bbb/24
static routers=192.168.1.1
static domain_name_servers=xxx.xxx.xxx.xxx
Just replace aaa and bbb and asign the DNS. If your router has a different IP range (e.g. 192.168.0.xxx) then just edit static_routers and change the IP to have the first 3 numbers the same as router's IP.
Chupo_cro
Re: Setting Multiple Static IPs
cw84 wrote: ↑Fri Aug 25, 2017 2:56 amHello,
I am wondering how I go about setting multiple static IPs on the same subnet to the same interface?
I have tried editing the /etc/dhcpcd.conf file as such..
interface eth0
static ip_address=192.168.1.10/24
static routers=192.168.1.1
static domain_name_servers=127.0.0.1
interface eth0:1
static ip_address=192.168.1.15/24
static routers=192.168.1.1
static domain_name_servers=127.0.0.1
I am curious what is the use case of having two different IP addresses when using one router?
I've found this thread because I am looking for a solution for specifying different static IP addresses for using them with different routers which work in different IP subnets (e.g. one router is at 192.168.1.1 and the other one is at 192.168.0.1). I am looking for a way to setup the static IP address which depends on the connection - if Pi is connected to the router which has IP 192.168.1.1 then static IP should be 192.168.1.xx and if it is connected to the router which has IP 192.168.0.1 then static IP should be 192.168.0.xx
Chupo_cro
Re: Setting Multiple Static IPs
I would like to add my thanks to Hippy for his working solution. Had exactly the same problem - i.e. the recommended method just did not work. Wasted hours on it. 

-
- Posts: 10
- Joined: Mon Aug 24, 2020 5:00 pm
Re: Setting Multiple Static IPs
FYI, in Raspbian Buster, dhcpcd runs as a service, and editing the /etc/dhcpcd.conf file requires reloading the service configuration file.
Make your changes in /etc/dhcpcd.conf to have separate static IPs for various interfaces. Here's how the relevant section in the dhcpcd.conf file should look:
Then, have systemctl update the changes with:
Then, restart the dhcpcd service with:
You may need to reboot if you're dealing with a wireless interface, but this will work.
Make your changes in /etc/dhcpcd.conf to have separate static IPs for various interfaces. Here's how the relevant section in the dhcpcd.conf file should look:
Code: Select all
# Example static IP configuration:
interface eth0
static ip_address=192.168.10.25/25
static routers=192.168.10.1
static domain_name_servers=8.8.8.8
interface wlan0
static ip_address=192.168.10.26/25
static routers=192.168.10.1
static domain_name_servers=8.8.8.8
Code: Select all
sudo systemctl daemon-reload
Code: Select all
sudo systemctl restart dhcpcd