Hello and good day my dear Linux Yogi’s,
in today’s illustration I am going to show you how to add multiple IP addresses to a single Network Interface Card (NIC). This can become handy for example if you have to run multiple services of the same server and you like to assign each service a unique IP address. We don’t need to install anything additional everything we need should already be there. Let’s get started.
We need to edit the /etc/network/interface file which contains the network configuration. After you opened it up with your favorite editor you should see something similar to the following:
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto enp0s17 iface enp0s17 inet dhcp
So first of all it is best to use static IP addresses on a Server or at the very least you should statically assign an IP address in DHCP for your Server. I will show you very quick how to change it from DHCP to static IP on the Server. You should already be in the /etc/network/interface file, so go ahead and adjust the section for the primary network interface to the following:
# The primary network interface auto enp0s17 iface enp0s17 inet static address 192.168.14.230 network 192.168.14.0 broadcast 192.168.14.255 netmask 255.255.255.0 gateway 192.168.14.1
Ok go ahead and save the file and reboot your server and test if it is still working and we have not broken it yet. 😉 Let’s run a ping and you should see something similar like the following:
ping 192.168.14.230 PING 192.168.14.230 (192.168.14.230) 56(84) bytes of data. 64 bytes from 192.168.14.230: icmp_seq=1 ttl=64 time=0.166 ms 64 bytes from 192.168.14.230: icmp_seq=2 ttl=64 time=0.164 ms 64 bytes from 192.168.14.230: icmp_seq=3 ttl=64 time=0.135 ms ^C --- 192.168.14.230 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 1998ms rtt min/avg/max/mdev = 0.135/0.155/0.166/0.014 ms
Ok great we did not break it. Open up the file /etc/network/interface and add the following to the end of the file:
iface enp0s17 inet static address 192.168.14.232/24 iface enp0s17 inet static address 192.168.14.234/24
In this case I added two more IP addresses to the configuration but you can add only one if you need to or more than two as well it is totally up to your requirements.
Go and save the file and reboot your server once more. When its back up lets ping the additional IP addresses from a machine in your network and you should see something like the following:
ping 192.168.14.232 PING 192.168.14.232 (192.168.14.232) 56(84) bytes of data. 64 bytes from 192.168.14.232: icmp_seq=1 ttl=64 time=0.207 ms 64 bytes from 192.168.14.232: icmp_seq=2 ttl=64 time=0.231 ms 64 bytes from 192.168.14.232: icmp_seq=3 ttl=64 time=0.130 ms ^C --- 192.168.14.232 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2000ms rtt min/avg/max/mdev = 0.130/0.189/0.231/0.044 ms ping 192.168.14.234 PING 192.168.14.234 (192.168.14.234) 56(84) bytes of data. 64 bytes from 192.168.14.234: icmp_seq=1 ttl=64 time=0.095 ms 64 bytes from 192.168.14.234: icmp_seq=2 ttl=64 time=0.131 ms 64 bytes from 192.168.14.234: icmp_seq=3 ttl=64 time=0.163 ms ^C --- 192.168.14.234 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2000ms rtt min/avg/max/mdev = 0.095/0.129/0.163/0.030 ms
Ok awesome it is all working as it should.
I hope you liked this illustration. Please consider subscribing to my blog or register to the forum. If you need me to write about something please use my contact for and drop me a line explaining what you need.
Thank you for reading. Until next time, Namaste my friends 😉