An additional IP is an address that is not bound to a specific device and therefore can be moved. In this article, we will cover how to configure an additional IP as an alias within Ubuntu.
Prerequisites
- Dedicated Server
- Getting Started with Additional IP Addresses
Topics
- Configuring an Additional IP Address within Ubuntu 16.04
- Configuring an Additional IP Address within Ubuntu 18.04
- Configuring an Additional IP Address within Ubuntu 20.04
Configuring an Additional IP Address within Ubuntu 16.04
To begin, use the ip
command to list the network interface name(s):
$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1 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 mq state UP group default qlen 1000 link/ether 00:00:5e:00:53:3a brd ff:ff:ff:ff:ff:ff inet <SERVER'S_IP>/24 brd <SERVER'S_BROADCAST> scope global eth0 valid_lft forever preferred_lft forever inet6 <SERVER'S_IPv6>::/64 scope global valid_lft forever preferred_lft forever inet6 fe80::a6bf:1ff:fe1a:57c2/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:5e:00:53:3b brd ff:ff:ff:ff:ff:ff
eth0
in our example, is used for public (i.e., Internet) traffic. The second one, eth1
in our example, is used for private networking. For more information on this, please check out our Getting Started with vRack article.From the output, note the public interface name, which for us is eth0
.
Next, open the /etc/network/interfaces
file using a text editor of your choice:
$ sudo vi /etc/network/interfaces
Then, assign your additional IP to a subinterface, also known as a virtual interface, by adding the following to the file:
auto eth0:1 iface eth0:1 inet static address <ADDITIONAL_IP> netmask 255.255.255.255
eth0
) with your actual interface name followed by an unused subinterface (e.g., :1
) and an additional IP address that is assigned to your server.Finally, use the systemctl
command to restart the networking service:
$ sudo systemctl restart networking
Job for networking.service failed because the control process exited with error code. See "systemctl status networking.service" and "journalctl -xe" for details.
Comment (#) out the following lines under the
iface eth0 inet6 static
section of the /etc/network/interfaces
file:#post-up sleep 5; /sbin/ip -family inet6 route add <IPv6_GATEWAY> dev <INT>
#post-up sleep 5; /sbin/ip -family inet6 route add default via <IPv6_GATEWAY>
Then, flush the interface and restart the networking service with the following command:
$ sudo ip addr flush dev <INT> && systemctl restart networking
Finally, from your local machine, use the ping
command to test that the system can communicate via the additional IP address:
$ ping <ADDITIONAL_IP>
If you do not receive a response, review the configuration for any inaccuracies and/or restart the operating system.
Configuring an Additional IP Address within Ubuntu 18.04
Canonical, the developer of Ubuntu, implemented the use of Netplan for easy-to-use network configuration as of version 17.x. However, as of this writing, a known issue with IPv6 configuration exists between Netplan and systemd.network
(the system service that manages networks). Although we are working with an IPv4 address, each Dedicated server is configured with an IPv6 address, which means network configurations are stored with systemd.network
directly. As a result, we will be adding to its configuration file, bypassing Netplan entirely.
To begin, open the /etc/systemd/network/50-default.network
file using a text editor of your choice:
$ sudo vi /etc/systemd/network/50-default.network
Then, add the following to the file, under the [Network]
section:
address=<ADDITIONAL_IP>/32
Finally, use the systemctl
command to restart the networking service, which applies the configuration:
$ sudo systemctl restart systemd-networkd
Lastly, from your local machine, use the ping
command to test that the system can communicate via the additional IP address:
$ ping <ADDITIONAL_IP>
If you do not receive a response, review the configuration for any inaccuracies and/or restart the operating system.
Configuring an IP Address within Ubuntu 20.04
To begin, log into your Ubuntu instance via SSH. Find and open your network configuration file in a text editor of your choice. On a Dedicated Server, it will be the following file:
$ sudo vi /etc/netplan/50-cloud-init.yaml
Add the line in red to the file, replacing the IP address in the example with your additional IP address. In our example, our additional IP address is 203.0.113.1.
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
version: 2
ethernets:
eno1:
dhcp4: true
addresses: [203.0.113.1/32]
match:
macaddress: d0:50:99:d4:f3:63
set-name: eno1
Next apply the configuration using the following command:
$ sudo netplan apply
If you have any syntax errors in your file, follow the instructions from the output of this command. If you have no syntax errors, you will see no output. Make sure the alias is properly configured by exiting your server and pinging the additional IP address.
Conclusion
Having read this article, you should be familiar with the steps required to configure an interface with an additional IP address within Ubuntu.