Configure Additional IPv4 using NetPlan on Ubuntu 18.04 and Up

From Ubuntu 18.04, a switch was made to configure network using NetPlan written in YAML. In this article, we will learn how to configure additional IPs in newer versions of Ubuntu, such as Ubuntu 18.04, 19.04, 19.10 and 20.04 using Netplan.

If you're looking to configure static IPv4 network, click on here.

Find the Additional IPv4 assigned to you

To find out the IPv4 Address assigned to you, login to CrownPanel and navigate to Manage Network tab.

A side note on this, YAML is strict on indentation so we will use 2 spaces through out the guide.

We will have 2 cases while configuring Additional IPv4.

  1. All the IPv4 belong to one subnet.

    Example: 23.228.232.82/24, 23.228.232.83/24 and 23.228.232.84/24 belong to a single subnet.

  2. IPv4 belong to a different subnets.

    Example: 23.228.232.65/24 and 45.128.156.7/24 belong to a different subnet.

In Case 1, we will configure additional IPv4 belonging to one subnet

Edit the default configuration file,

vi /etc/netplan/01-netcfg.yam

Make the following changes to it.

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: no      
      addresses:
        - 23.228.232.82/27
        - 23.228.232.83/27
        - 23.228.232.84/27
      gateway4: 23.228.232.65
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4

Then apply the changes made to the configuration file by

netplan apply

Test if the network is up by running

ip a

This should show all the IPs configured in ens3 interface.

In Case 2, we will configure additional IPv4 which belongs to different subnets

We will not modify the default configuration file BUT we will create a new configuration file for each IP that belongs to a different subnet.

We will create a new network configuration file,

vi /etc/netplan/02-netcfg.yaml

Add the following content into it

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: no
      addresses:
        - 45.128.156.7/24
      gateway4: 45.128.156.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4

Apply the configuration changes by running

netplan apply

You can create more number of network configuration files depending on the subnets you have.

And to confirm if the additional IPs are working, run

ip a

You should get something similar to the following output:

My new IPs

This concludes our topic of configuring additional IPv4 on Ubuntu.

If you can not configure and facing technical difficulties, kindly reach out to us via Support Ticket.