How to Configure Multiple Network Interfaces and IP Addresses on Ubuntu 20.04
Multiple networks are often required in a variety of situations for several reasons:
- Distributed Computing: In large-scale systems, multiple networks distribute the computational load across different nodes or machines. This enhances performance and fault tolerance by enabling parallel task execution.
- Specialization: Different networks can be designed to specialize in distinct tasks or domains. For instance, in deep learning, separate networks can be dedicated to image recognition, speech synthesis, and text generation, each optimized for a specific task.
- Handling Heterogeneous Data: When data includes various types (such as images, text, and audio), distinct networks can be used to process each data type effectively before combining the results for the final decision.
In summary, multiple networks help in distributed computing, specialization, ensemble learning, transfer learning, scalability, and managing heterogeneous data. They improve performance, flexibility, and efficiency in machine learning and AI applications.
Multiple IPs to Multiple Adapters
The "one IP, one interface" network configuration is commonly used to organize local and internet connections on routers for several key reasons:
- Function Separation: Using separate IP addresses for each interface helps clearly distinguish the roles of the local network and internet access. Each interface can be connected to specific segments of the local network with individual routing and filtering rules.
- Traffic Management: Assigning separate IPs to each interface makes it easier to manage traffic. Different routing, filtering, and prioritization policies can be applied to each interface independently, optimizing bandwidth usage and ensuring quality of service.
- Problem Isolation: The "one IP, one interface" setup aids in isolating issues. If a problem arises on one interface or IP address, the other interfaces remain functional, which simplifies troubleshooting without impacting other network segments.
Update System Packages:
To ensure everything works properly, update your system packages:
apt update && upgrade -y

Next, check the available network interfaces on your system by logging in as the root user or using sudo:
ip link show
You can either create new configuration files for each interface or use a single default configuration file. For this example, we'll proceed with the second option and configure a static address for one of the interfaces.
Find Network Configuration File:
ls /etc/netplan
You should see the configuration file name. Make sure to note it for the next step.
Edit Network Configuration:
Open the configuration file with the nano editor:
sudo nano /etc/netplan/50-init-cloud.conf
You will see a default configuration. Replace it with the following settings:
network:
version: 2
ethernets:
enp0s5:
addresses:
- 109.207.173.205/24
- 192.168.0.10/24 # Secondary IP
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:
9;- to: 10.10.10.0/24
9;9;via: 10.10.10.1
Apply Changes:
Run the following commands to apply the changes and check your IP configurations:
netplan generate && netplan apply && ip a
Secondary IPs to One Interface
Why Do We Need Secondary IPs?
Secondary IP addresses can be useful for several scenarios:
- Service Separation: When a single physical device provides multiple network services, secondary IPs can bind each service to a different IP. For example, a server can host both a web server and a mail server, each using a separate IP address.
- Additional Connectivity: Secondary IPs allow for additional connectivity paths to the network. Multiple interfaces on a router or switch can each have a secondary IP to communicate with different network segments.
- Service Isolation: You can assign distinct IPs to different services on the same device to enforce stricter access controls between services. For instance, a web server and a database can each have separate IPs.
- Testing and Debugging: Secondary IPs provide a method to test new network configurations without interrupting primary services.
Even with just one network adapter, you can assign secondary IPs to it. However, note that if you add more than one IP to an interface, DHCP will not work.
Assign Secondary IP:
To assign a secondary IP to the same interface, modify the configuration as follows:
enp0s5:
addresses:
- 109.207.173.205/24
- 192.168.0.10/24 # Secondary IP
Apply and Check Changes:
After modifying the configuration, apply the changes and check your IPs with:
netplan generate && netplan apply && ip a
FAQ
Q: Why do I need multiple networks on a single server?
- Multiple networks allow for better traffic management, service isolation, and improved fault tolerance. Each network can be dedicated to specific services or tasks, optimizing the overall system performance.
Q: Can I configure secondary IPs on a single interface?
- Yes, you can configure secondary IPs on a single network interface. Just add them to the configuration file under the same interface, ensuring the interface doesn't rely on DHCP.
Q: What if my server has multiple interfaces?
- If your server has multiple interfaces, you can configure each one with a unique IP address. This allows better network segmentation and traffic management.
Q: How do I isolate network services using secondary IPs?
- Assign different IPs to different services on the same server. For example, assign one IP for a web server and another for a database, making it easier to control traffic and security.
Conclusion
In this guide, you learned how to configure multiple network interfaces on Ubuntu 20.04. You can assign static IPs, set up multiple interfaces with different configurations, and even apply secondary IPs to a single interface for service separation or additional connectivity. Mastering these concepts allows for better network management and improved performance in diverse use cases.


