Skip to content

Instantly share code, notes, and snippets.

@JoSSte
Created February 2, 2025 10:49
Show Gist options
  • Save JoSSte/3b04034a62797f9aaffb24edbaa6819d to your computer and use it in GitHub Desktop.
Save JoSSte/3b04034a62797f9aaffb24edbaa6819d to your computer and use it in GitHub Desktop.
Configuration for multiple IPS on the same network card in linux

Dual IP configuration

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.

Legacy /etc/network/interfaces

sample configuration

# 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.

applying changes

#Debian
sudo service networking restart

netplan /etc/netplan/00-network-config.yaml

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

applying changes

#Ubuntu
sudo netplan apply
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment