I initially had one static IP assigned to one of my Raspberry Pi’s (ex: 192.168.0.20), and recently found myself in a situation where I also needed it to respond over a second (ex: 192.168.0.21).
To set this up, I left my /etc/dhcpcd.conf
file alone with the existing static config:
interface eth0
static ip_address=192.168.0.20/24
static routers=192.168.0.1
I then created /etc/network/interfaces.d/eth0-subs
with the following info to configure the secondary IP:
auto eth0:1
allow-hotplug eth0:1
iface eth0:1 inet static
vlan-raw-device eth0
address 192.168.0.21
netmask 255.255.255.0
gateway 192.168.0.1
After a quick reboot, both IP’s were up and functional as demonstrated by running a quick ip a
command:
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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 mq state UP group default qlen 1000
link/ether dc:a6:32:dc:68:84 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.21/24 brd 192.168.0.255 scope global eth0:1
valid_lft forever preferred_lft forever
inet 192.168.0.20/24 brd 192.168.0.255 scope global secondary noprefixroute eth0
valid_lft forever preferred_lft forever