Sometimes it is useful to have multiple IP addresses on the same network interface. This is a note to myself on how to do it. The Distribution in the comments is the dist that I have verified the command on. This does not mean that it is the only way to do the application of the changes.
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 10.0.10.240
netmask 255.0.0.0
gateway 10.0.0.1
auto eth0:0
iface eth0:0 inet static
address 192.168.1.200
netmask 255.255.255.0
#gateway 192.168.1.1 #this should only be uncommented if the gateway config for the main interface is commented out. Dual gateway configs will cause the interface not to come up.
#Debian
sudo service networking restart
network:
ethernets:
# make sure that this adapter name matches the adapter
eno1:
addresses:
- 10.0.1.202/16
- 192.168.1.202/24
nameservers:
# note that if 10.0.0.1 is not available, this configuration will wait for a request to time out before trying dns #2 etc.
addresses: [10.0.0.1, 4.2.2.2, 8.8.8.8]
routes:
- to: default
#only one of these can be active at a given time. so if you are switching out the router/gw make sure the correct one is active.
#via: 10.0.0.1
via: 192.168.1.1
version: 2
#Ubuntu
sudo netplan apply