Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


[Tutorial] How to add multiple IP addresses using single network interface on Debian/Ubuntu server
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

[Tutorial] How to add multiple IP addresses using single network interface on Debian/Ubuntu server

ShakibShakib Member, Patron Provider

Important Notes:

1.) Before making any changes to your network configuration, please make sure you obtain any relevant information such as Gateway, Subnet and allocated IP Block details to ensure no mistakes are made!

2.) Make a backup of your existing configuration in case you need to fall back to this at a later stage: sudo cp /etc/network/interfaces /etc/network/interfaces_backup

Old Debian/Ubuntu OS uses eth and new version use ens as network interface. You can check your current network interface by using command ifconfig -a

Now edit it’s time to edit your configuration: sudo vi /etc/network/interfaces

We’re only interested in updating the eth or ens part of the configuration so ignore the loopback section if present. It looks like that:

auto lo
iface lo inet loopback

Rearrange your existing configuration to look as follows (feel free to remove the broadcast and network entries):

auto eth0

iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0
gateway 192.168.1.254

Now add your new entries so the finish configuration looks like:

auto eth0

iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0
gateway 192.168.1.254

auto eth0:0

iface eth0:0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.254

auto eth0:1

iface eth0:1 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.254

If you are using a latest version of OS and network interface is ens, you'll be need to replace eth0 on ens0/ens3/ens25 whatever you can see on your current network configuration usingifconfig -a with your current IP address.

You should be able to see a pattern emerging, keep adding new entries as necessary!

Once you have finished adding your IPs you can save and close the file and finally, for the new changes to take effect, issue: reboot

Thanked by 1Trav

Comments

  • Why do a complete reboot if you can restart the networking service with sudo ifdown -a && sudo ifup -a?

  • ShakibShakib Member, Patron Provider

    @Vinnyletje said: Why do a complete reboot if you can restart the networking service with sudo ifdown -a && sudo ifup -a?

    You can restart the network only using sudo /etc/init.d/networking restart or sudo service networking restart

    But, the better and recommended way is perform a reboot for complete network changes over the server.

  • This howto is kind of pointless for anyone who wants to run KVMs; You'll want to migrate your setup to a bridge device and make your ethernet interface a member of it.

  • ShakibShakib Member, Patron Provider

    @WSS said: This howto is kind of pointless for anyone who wants to run KVMs; You'll want to migrate your setup to a bridge device and make your ethernet interface a member of it.

    Hello @WSS,

    Thanks for your comment. I believable that it's will still help someone to setup his IPs on most type of Debian/Ubuntu server. Setting up multiple IPs is also needed for setup multiple SSL for multiple sites on LAMP server without SNI with dedicated IP.

    - Shakib Khan

Sign In or Register to comment.