14.07.2023

How to Configure Multiple Network Interfaces on Ubuntu 20.04

Why multiple networks may be needed?

Multiple networks may be needed in various scenarios due to several reasons:

In summary, multiple networks are beneficial in scenarios involving distributed computing, specialization, ensemble learning, transfer learning, complex model architectures, scalability, resource constraints, and domains with heterogeneous data. They enable improved performance, flexibility, robustness, and efficiency in various machine learning and artificial intelligence applications.

Multiple IPs to the multiple adapters

Using the "one IP one interface" network configuration in the network to organize a local and Internet connection on the router has several reasons:

Don't remember to update system package for properly work OS:

apt update && upgrade -y

Next, we need to check available interfaces on our machine as superuser, for that login as root user or use command sudo:

ip link show

We have several options to change configuration file: make new config file in folder and work with them or use one default config for all interfaces. For us example let's choose second way. Open the configuration plan , I will config static address for one of them.

ls /etc/netplan

You will see name of your configuration file, for the next step take in mind it. Attention! In your case you choose your name for file as we knew them before!

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

Then you will see the file with default configuration, change settings for the displayed below:

network:
     version: 2
     ethernets:
         enp0s5:
             addresses:
             - 109.207.173.205/24
             mtu: 1500
             nameservers:
                 addresses:
                 - 8.8.8.8
                 -1.1.1.1
                 -8.8.4.4
                 search: []
             routes:
             -   to: default
             via: 109.207.173.1
          enp0s6:
              addresses:
              - 10.10.10.1/24
              mtu: 1500
              nameservers:
                  addresses:
                  - 8.8.8.8
                  -1.1.1.1
                  - 8.8.4.4
                  search: []
              routes:
              -   to: 10.10.10.0/24
              via: 10.10.10.1

Change 10.10.10.1, 10.10.10.0/24, 109.207.173.205/24 for your's IP. Let's have a look for changes via command below:

netplan generate && netplan apply && ip a

Secondary IPs to the one interface

Why are we in need of this?

Secondary IP addresses can be used in different situations and for different purposes. Here are some of them:

Secondary IP addresses have a wide range of applications and can be useful in various situations where additional flexibility or isolation in the network is required.

Even if your server has one network adapter you can configure additional IPs onto. Just one exception: if you add more then one IP to the same interface, you can't use DHCP. To add IP alias just "insert" secondary address to current interface config near the exist address:

Then apply and check changes:

netplan generate && netplan apply && ip a

Conclusion

After this article reading you are knew how to configure multiple network interfaces on Ubuntu 20.04.