The Raspberry Pi OS (I believe since Jessie) uses dhcpcd to manage the network interfaces instead of the traditional networking service like other Linux distributions. The recommended method of setting a static IP (on either the ethernet or wlan interfaces) is to edit dhcpcd.conf . However, dhcpcd only supports a single static IP Address – you are out of luck if you need more.
So, you need to disable dhcpcd, re-enable the networking service, and edit the /etc/network/interfaces file. Before beginning this process, you will need to know your default gateway’s IP and what DNS servers you want to use since this info will be manually entered in /etc/network/interfaces.
If you are doing this re-configuration remotely, be sure to make all the edits before rebooting the RPi so you don’t leave it inaccessible.
Here is the original RPi interfaces file, including the original notes regarding dhcpcd.conf, edited with the new info:
# 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'
12/20/21 - dhcpcd service disabled to allow multiple IP addresses on eth0
auto lo eth0 eth0:0
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet static
address 192.168.73.12/24
iface eth0:0 inet static
address 192.168.1.100/24
gateway 192.168.73.1
dns-nameservers 192.168.73.2
Include files from /etc/network/interfaces.d:
#source-directory /etc/network/interfaces.d
Note that you are configuring a static IP for the eth0 interface (192.168.73.12) and a second static IP (192.168.1.100) using a new interface called eth0:0 . The new interface syntax is recognized by the networking service at boot and it will create the second IP for the RPi’s NIC.
If you want to do the same with the wlan0 interface instead of the eth0 interface, substitute wlan0 & wlan0:0 in the configuration above. Add this line to the end of the interfaces file, so your network’s WiFi credentials are configured properly (you may need to configure this file manually as well):
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Now that the interfaces file is ready to go, you need to configure the services. First, disable dhcpcd:
$ sudo systemctl disable dhcpcd
Then, enable the networking service:
$ sudo systemctl enable networking
Now perform a reboot:
$ sudo reboot
Testing the new configuration. Run ifconfig -a to check the assigned IPs:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.73.12 netmask 255.255.255.0 broadcast 192.168.73.255
inet6 fe80::ba27:ebff:feb9:7135 prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:b9:71:35 txqueuelen 1000 (Ethernet)
RX packets 742587 bytes 51572238 (49.1 MiB)
RX errors 0 dropped 242159 overruns 0 frame 0
TX packets 8546 bytes 1113109 (1.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
ether b8:27:eb:b9:71:35 txqueuelen 1000 (Ethernet)
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 2 bytes 182 (182.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2 bytes 182 (182.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Both eth0 & eth0:0 have been configured with the correct addresses.
This procedure is designed to be used from the Terminal on a remote system using ssh. If you are running the GUI on the RPi, it may disable the GUI configuration panels and force you to make all changes to /etc/network/interfaces and /etc/wpa_supplicant/wpa_supplicant.conf manually going forward.