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, 20.04, 22.04 and so on using Netplan.
If you're looking to configure static IPv4 network, click on here.
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.
All the IPv4 belong to one subnet.
Example: 184.108.40.206/24, 220.127.116.11/24 and 18.104.22.168/24 belong to a single subnet.
IPv4 belong to a different subnets.
Example: 22.214.171.124/24 and 126.96.36.199/24 belong to a different subnet.
Edit the default configuration file,
Make the following changes to it.
network: version: 2 renderer: networkd ethernets: ens3: dhcp4: false addresses: - 188.8.131.52/27 - 184.108.40.206/27 - 220.127.116.11/27 nameservers: addresses: - 18.104.22.168 - 22.214.171.124 routes: - to: default via: 126.96.36.199
A detailed explanation is given below on where you can find the Prefix and Gateway IPs.
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,
Add the following content into it
network: version: 2 renderer: networkd ethernets: ens3: dhcp4: false addresses: - 188.8.131.52/24 nameservers: addresses: - 184.108.40.206 - 220.127.116.11 routes: - to: default via: 18.104.22.168
You can create more number of network configuration files depending on the subnets you have.
addresses, we've added the Main IP of the server followed by it's prefix.
If your netmask is "255.255.255.0", then use
You can find more info on how to use the right prefix here.
routes, we've put the gateway IP of the IP block.
This can be found in the "Manage Network" page in CrownPanel.
For nameservers, we are using google's public DNS.
You can also try CloudFlare's public DNS as well.
After the IPs have been added to the configuration file(s), Save and exit the config.
Run the following command to test the changes.
If the configuration fails, changes will be reverted in 120 seconds.
If you are able to view the countdown and connected to the server, this means the configuration is correct.
Enter key to save and apply the changes.
This should effectively configure the IPv4 from DHCP to Static and to test if the network is still up.
And to confirm if the additional IPs are working, run
You should get something similar to the following output:
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.