Adding an additional IP is routine for any system administrator. When you set up a new server, it will have a single IP address linked with the server hostname. You might need to set up an additional IP address on your system for several reasons. Some of them are listed below:
- To set up Internet sharing with Squid proxy server.
- To run the same service multiple times.
- To use different hostnames in reverse DNS lookups.
- To avoid being blacklisted in spam filters.
- To host multiple SSL sites.
Ubuntu allows you to add multiple virtual IP addresses on a single network interface card without buying an additional network adapter.
This tutorial will explain how to add an IP address on an Ubuntu 18.04 server.
Add an Additional IP Address Permanently
Configuring an IP address on an Ubuntu 18.04 server differs from the older method used in the older version of Ubuntu. Ubuntu 18.04 uses the Netplan utility to configure networking.
You can permanently add an IP address to your system by editing the file /etc/netplan/01-netcfg.yaml.
First, you can see your existing IP address with the following command:
ip addr
You should see the following output:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:00:d8:62:0b:e6 brd ff:ff:ff:ff:ff:ff inet 216.98.11.230/24 brd 216.98.11.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::200:d8ff:fe62:be6/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 00:00:0a:62:0b:e6 brd ff:ff:ff:ff:ff:ff
You can also see your existing network configuration with the following command:
cat /etc/netplan/01-netcfg.yaml
You should see your existing network configuration in the following output:
network: version: 2 renderer: networkd ethernets: eth0: addresses: - 216.98.11.230/24 gateway4: 216.98.11.1 nameservers: addresses: - 209.208.127.65 - 209.208.25.18
In the above output, you should see that the IP address 216.98.11.230 is assigned to the interface.
Here’s a brief explanation of each parameter:
- enp0s3: A device name to be configured.
- dhcp4: Used to enable or disable dhcp4.
- dhcp6: Used to enable or disable dhcp6.
- addresses: The IP address of the device.
- gateway4: The IP address of your gateway.
- nameservers: The IP address of your DNS server.
Next, we will add an additional IP address, 192.168.0.100, to the server.
To do so, open your file /etc/netplan/01-netcfg.yaml in your preferred text editor:
nano /etc/netplan/01-netcfg.yaml
After adding the IP address, your file should look something like this:
network: version: 2 renderer: networkd ethernets: eth0: addresses: - 216.98.11.230/24 - 192.168.0.100/24 gateway4: 216.98.11.1 nameservers: addresses: - 209.208.127.65 - 209.208.25.18
Save and close the file when you are finished. Then, enable the new configuration with the following command:
netplan apply
Now, check your unique IP address in the following order:
ip addr
You should see both IP addresses in the following output:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:00:d8:62:0b:e6 brd ff:ff:ff:ff:ff:ff inet 216.98.11.230/24 brd 216.98.11.255 scope global eth0 valid_lft forever preferred_lft forever inet 192.168.0.100/24 brd 192.168.0.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::200:d8ff:fe62:be6/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 00:00:0a:62:0b:e6 brd ff:ff:ff:ff:ff:ff
Add an Additional IP Address Temporarily
You can also temporarily add an IP address to your server with the ip addr command.
For example, add the IP address 192.168.0.101 temporarily with the following command:
ip addr add 192.168.0.101/24 dev eth0 label eth0:1
Now, check your IP address with the following command:
ip addr
You should see that the new IP address 192.168.0.101 is assigned to the interface eth0:1.
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:00:d8:62:0b:e6 brd ff:ff:ff:ff:ff:ff inet 216.98.11.230/24 brd 216.98.11.255 scope global eth0 valid_lft forever preferred_lft forever inet 192.168.0.100/24 brd 192.168.0.255 scope global eth0 valid_lft forever preferred_lft forever inet 192.168.0.101/24 scope global secondary eth0:1 valid_lft forever preferred_lft forever inet6 fe80::200:d8ff:fe62:be6/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 00:00:0a:62:0b:e6 brd ff:ff:ff:ff:ff:ff
Conclusion
Congratulations! You have successfully configured multiple IP addresses on a single network interface. I hope you now have enough knowledge to add multiple IP addresses to your system per your requirements. If you’re ready to start configuring various IPs on a VPS, check out Atlantic.Net’s VPS Hosting options.