Assigning Additional IPs on Ubuntu 20.04 | 22.04
Over the following guide, you will be shown how to assign additional IPs using netplan.io.
To install these dependencies use the following:
sudo apt install net-tools sudo apt install netplan.io
Finding your IP
First, we have to issue a command in order to check the current IP address of our system:
As can be seen in the example above, on the interface eth0 we find the address of 126.96.36.199. This will be the interface we will be working with in this instance.
Assigning our additional IPs
With Netplan, an additional IP address can be assigned by editing:
In order to actually assign our additional addresses we need to create a YAML file for the interface to generate in- we are going to use the file 50-cloud-init.yaml in this instance.
This is what our YAML file should look like- in a rough format:
network: version: 2 renderer: NetworkManager ethernets: eth0: dhcp4: false addresses: - 188.8.131.52/24 nameservers: addresses: - 184.108.40.206 gateway4: 220.127.116.11
Within this file, we have to add the additional IP we are trying to assign. In this case, the additional IP is 18.104.22.168. We have to add this under the addresses field.
network: version: 2 renderer: NetworkManager ethernets: eth0: dhcp4: false addresses: - 22.214.171.124/24 - 126.96.36.199/24 nameservers: addresses: - 188.8.131.52 gateway4: 184.108.40.206
For more configuration options regarding your netplan- you can view this page. After this, we exit nano and save the modified buffer, please also bare in mind that YAML, has very strict formatting/indentation requirements, you may need to use an external editor in some cases where you are unfamiliar with the indentations.
Testing Our Address Change
We can test the changed we have just made by running the following command:
sudo netplan try
As long as everything has been formatted properly and no errors are presented- we can now run:
Our new address should now be listed under inet.
And that's it! There are a variety of other ways in which you can assign additional addresses- though in this example we have used Netplan for simplicity.