How to assign additional IP's on Ubuntu using Netplan Print

  • ubuntu, netplan, additional ip, ip
  • 0

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.


Dependencies

  • Netplan.io
  • Net-tools

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:

ip a



As can be seen in the example above, on the interface eth0 we find the address of 45.88.231.113. 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:

/etc/netplan/*.yaml

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.  

nano /etc/netplan/50-cloud-init.yaml

This is what our YAML file should look like- in a rough format:

network:
    version: 2
    renderer: NetworkManager
    ethernets:
        eth0:
            dhcp4: false
            addresses:
                - 45.88.231.113/24
            nameservers:
                addresses:
                    - 1.1.1.1
            gateway4: 45.88.231.1

Within this file, we have to add the additional IP we are trying to assign. In this case, the additional IP is 45.88.231.114. We have to add this under the addresses field.

network:
    version: 2
    renderer: NetworkManager
    ethernets:
        eth0:
            dhcp4: false
            addresses:
                - 45.88.231.113/24
                - 45.88.231.114/24
            nameservers:
                addresses:
                    - 1.1.1.1
            gateway4: 45.88.231.1

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:

ip a

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.


Was this answer helpful?

« Back

Powered by WHMCompleteSolution