Source: Here
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
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.