Software & AppsOperating SystemLinux

Configuring Multiple IP Addresses on Ubuntu Server 20.04 using Netplan

Ubuntu 1

In this article, we will delve into the process of configuring multiple IP addresses on a single network card in Ubuntu Server 20.04 using Netplan. Netplan is a utility for easily configuring networking on a Linux system. You can use it to configure network interfaces, as well as to set up more advanced features like VPNs, tunnels, and more.

Quick Answer

To configure multiple IP addresses on Ubuntu Server 20.04 using Netplan, you need to edit the Netplan configuration file and add the additional IP addresses under the addresses key. After saving the configuration file, apply the changes using the sudo netplan generate and sudo netplan apply commands. A reboot may be required for the changes to take effect.

Understanding Netplan

Netplan reads network configuration from /etc/netplan/*.yaml which are written in YAML syntax. It then generates backend specific configuration files and uses those to configure network interfaces.

Preparing the Environment

Before we start, ensure that you have SSH access to your Ubuntu Server 20.04 and have sudo privileges. If you’re not sure how to do this, you can follow this guide.

Configuring Multiple IP Addresses

To add multiple IP addresses, you need to edit the Netplan configuration file. The default configuration file is usually located at /etc/netplan/01-netcfg.yaml. Open this file with your preferred text editor. Here, we’ll use nano:

sudo nano /etc/netplan/01-netcfg.yaml

In this file, you’ll see a YAML configuration that looks something like this:

network:
 version: 2
 renderer: networkd
 ethernets:
 enp2s0:
 dhcp4: no
 addresses: [192.168.1.100/24]
 gateway4: 192.168.1.1
 nameservers:
 addresses: [1.1.1.1, 1.0.0.1]

To add another IP address, simply append it to the addresses key:

network:
 version: 2
 renderer: networkd
 ethernets:
 enp2s0:
 dhcp4: no
 addresses:
 - 192.168.1.100/24
 - 192.168.1.99/24
 gateway4: 192.168.1.1
 nameservers:
 addresses: [1.1.1.1, 1.0.0.1]

In this configuration, enp2s0 is the network interface name which might be different on your server. The addresses key is a list of IP addresses that you want to assign to this interface. Each IP address is followed by a slash and the number of bits in the network mask, e.g., /24 for a subnet mask of 255.255.255.0. The gateway4 key is the default gateway for IPv4 traffic. The nameservers key is a list of DNS servers that the system will use to resolve domain names.

Applying the Configuration

After saving the configuration file, you can apply the changes using the following commands:

sudo netplan generate
sudo netplan apply

The sudo netplan generate command generates the configuration files for the backend, and sudo netplan apply applies the new configuration to the system.

In some cases, a reboot may be required for the changes to take effect. If the network does not come up after applying the configuration, try restarting the systemd-networkd service:

sudo systemctl restart systemd-networkd

Troubleshooting

If you encounter any errors or issues, check the syslog for error messages related to the network configuration. You can use the following command to check the syslog:

sudo tail -f /var/log/syslog

In conclusion, configuring multiple IP addresses on a single network card in Ubuntu Server 20.04 using Netplan is a straightforward process that involves defining the addresses in the YAML configuration file, applying the changes, and potentially rebooting the system for the configuration to take effect.

Can I configure multiple IP addresses on a single network card in Ubuntu Server 20.04 using Netplan?

Yes, you can configure multiple IP addresses on a single network card in Ubuntu Server 20.04 using Netplan. Netplan allows you to define multiple IP addresses in the YAML configuration file.

How do I edit the Netplan configuration file?

To edit the Netplan configuration file, you can use a text editor such as nano. Open the terminal and run the command sudo nano /etc/netplan/01-netcfg.yaml to open the configuration file in nano.

How do I add another IP address to the Netplan configuration?

To add another IP address to the Netplan configuration, you need to append it to the addresses key in the YAML configuration file. Each IP address should be separated by a hyphen and a space, like this: - 192.168.1.99/24.

How do I apply the Netplan configuration changes?

After saving the Netplan configuration file, you can apply the changes by running the commands sudo netplan generate and sudo netplan apply in the terminal. The generate command generates the configuration files for the backend, and the apply command applies the new configuration to the system.

Do I need to reboot the system after applying the Netplan configuration changes?

In some cases, a reboot may be required for the Netplan configuration changes to take effect. However, you can try restarting the systemd-networkd service by running the command sudo systemctl restart systemd-networkd before considering a reboot.

How can I troubleshoot any errors or issues with the Netplan configuration?

If you encounter any errors or issues with the Netplan configuration, you can check the syslog for error messages related to the network configuration. Use the command sudo tail -f /var/log/syslog to view the syslog and identify any potential problems.

Leave a Comment

Your email address will not be published. Required fields are marked *