Subscription-based service of managed cloud infrastructure

How to Configure Multiple Network Interfaces on Ubuntu 20.04

Joe Harris
May 2, 2021

In situations where there are 2 or more network interfaces with public IP addresses on the Ubuntu 20.04 server, additional settings must be made to ensure the server is available at these additional addresses. This is because the default routing policy sends all network packets through 1 interface, which has a default route. In this case, it does not matter through which interface the packet got to the server. Therefore, even with the correct Netplan configuration, the server will not respond to additional IP addresses without additional settings. Let’s take a look at how to configure multiple network interfaces in Ubuntu 20.04.

Netplan automatic configuration

Linux Serverspace servers are designed to make life easier for users. They have the function of configuring network interfaces in automatic mode when they are added in the control panel or during server creation. But in order to ensure the operation of policy-based routing and as a result of the server’s availability on several network interfaces at once, we need to make changes to the Netplan settings. To prevent our settings from being overwritten during a reboot, we need to disable automatic network configuration. After you make sure that the required number of interfaces has been added to the server, create a file on it:

nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

And add a parameter to it:

network: {config: disabled}

Now subsequent changes in Netplan will not be automatically overwritten on reboot.

Configuring Policy-Based Routes

Policy-Based routing powered by tables. Each table has its own routes and policies. Let’s check the presence of the iproute2 package in the system. If not, install it.

apt install iproute2

Open the file with routing tables:

nano /etc/iproute2/rt_tables

And add at the end the number of tables corresponding to the amount of interfaces you are configuring:

800 800
801 801

Record format: priority (number) space table name (number).
Now open the Netplan file with network interface settings. It is located along the path /etc/netplan/ and has the .yaml extension. In my case, the path is as follows:

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

Each interface has a settings block in this file. At the end of this block, we will add settings for policies and routing rules for the interface. In this file, it is important to observe the number of spaces before each parameter and value, and not to use tabs instead of spaces. Focus on indentation in existing entries and add by analogy.

For each network interface, add routes and routing-policy blocks. The final record for 1 interface will look like this:

    version: 2
                macaddress: 54:43:32:21:10:09
            mtu: 1500
                search: []
            set-name: enp0s5
                - to:
                  table: 800
                - from:
                  table: 800
                  priority: 300

For other interfaces, the entries will be the same, starting with the interface name (enp0s5), but others should not have the gateway4 parameter, since there should be one default gateway. Routes and routing-policy settings:

  • to — destination address of the packet. For our purposes — any (
  • via — gateway address for this interface
  • table — name of the routing table. The same values must be specified in routes and routing-policy for one interface, but be different from interface to interface. We created these tables in the rt_tables file
  • from — the source address of the package. For the purposes of this manual, this is the IP address of the interface
  • priority — a required numeric value

After making the settings and saving the file, check the configuration for errors:

netplan generate

Output like this will indicate an error if present (in this case, a space is missing.):

/etc/netplan/50-cloud-init.yaml:23:12: Invalid YAML: inconsistent indentation:

If the config is compiled correctly, then the output will be absent. This means it’s time to apply the changes:

netplan apply

After applying the changes, the network interfaces configured in this way will become available from the outside at their public IP addresses.

Start Your Cloud Journey Migration made simplified. Take the first step right now.
We use cookies to provide our services and for analytics and marketing. To find out more about our use of cookies, please see our Privacy Policy. By continuing to browse our website, you agree to our use of cookies.