News
Spin into 2026: join the Christmas Wheel of Fortune
JH
Joe Harris
May 2 2021
Updated January 18 2026

How to Configure Multiple Network Interfaces on CentOS 8 Using Source-Based Routing

CentOS Linux Networks

Using another OS?

Select the desired version or distribution.

When a CentOS 8 system has two or more network interfaces with public IP addresses, standard routing configuration is often insufficient. By default, all outgoing traffic is sent through a single default gateway, regardless of which interface received the incoming request.

In this tutorial, we configure source-based (policy-based) routing on CentOS 8 to ensure that traffic originating from each public IP address is routed back through the correct network interface.

Network interface parameters

Cloud servers in Serverspace have the function of automatically configuring network interfaces when they are added or a server is created. Therefore, if you use them, proceed to the next step. Otherwise, first you need to set the correct parameters of the network interfaces.

Open the network interface settings file. Their names can be viewed using the ip a command, or set new ones if they are not configured.

nano /etc/sysconfig/network-scripts/ifcfg-enp0s5

You can copy the configuration below and replace the following values with your own:

  • interface name (enp0s5)
  • gateway (GATEWAY)
  • MAC address (HWADDR)
  • IP address (IPADDR)
  • subnet mask (NETMASK)
BOOTPROTO=none
DEFROUTE=yes
DEVICE=enp0s5
GATEWAY=54.43.32.1
HWADDR=56:67:78:89:01:ab
IPADDR=54.43.32.11
MTU=1500
NETMASK=255.255.255.0
ONBOOT=yes
STARTMODE=auto
TYPE=Ethernet

Configure all network interfaces in the same way. GATEWAY for the second, third, etc. interfaces are not specified, since this is the default gateway and there should only be one.

Disable NetworkManager

We will configure policy-based routing using network-scripts, so we will disable NetworkManager and related services:

systemctl mask NetworkManager.service
systemctl stop NetworkManager.service
systemctl mask NetworkManager-wait-online.service
systemctl mask NetworkManager-dispatcher.service

Install the network-scripts package.

dnf install network-scripts

Let's start the network service:

systemctl enable network
systemctl start network

Source based routing setup

Source-based routing in Linux is implemented using multiple routing tables and rules managed by iproute2.
Let's check if the iproute package is present. If not, install it.

dnf install iproute

Add new tables to configure routing policies.

nano /etc/iproute2/rt_tables

Add records to the end of the file:

400 400
401 401

Each row is a new table. Record format - priority space table name. These values must be unique relative to other entries in the file. The priority is numeric, and the table name can contain letters. Add as many new tables as there are interfaces you are setting up.

The following files will contain the routing settings. For each interface, you need to create a pair of files: rule-eth-name, route-eth-name, where eth-name should be replaced with the name of the interface. Example for enp0s5 interface:

nano /etc/sysconfig/network-scripts/rule-enp0s5

Insert the following line into it with the current IP address instead of 54.43.32.11 and the name of the table created in the previous step instead of 400:

from 54.43.32.11 lookup 400

Second file:

nano /etc/sysconfig/network-scripts/route-enp0s5

Replace 54.43.32.0/24 with the address of your subnet, enp0s5 with the name of the interface, 400 with the name of the corresponding table, and 54.43.32.1 with the gateway for routing traffic and insert it into the open file:

54.43.32.0/24 dev enp0s5 table 400
default dev enp0s5 via 54.43.32.1 table 400

After creating such files for each network interface, restart the network service and our goal is achieved.

systemctl restart network

Conclusion

Configuring source-based routing on CentOS 8 allows multi-homed servers to correctly handle inbound and outbound traffic across multiple network interfaces. By using separate routing tables for each public IP address, you avoid the limitations of default routing and ensure reliable external connectivity. This approach is essential for servers with multiple public interfaces in cloud and data center environments.

FAQ

  • Q1: Why is configuring multiple network interfaces not enough to ensure availability from the Internet?
    A1: Because by default, all outgoing traffic uses a single default gateway regardless of the incoming interface. Without source-based routing, replies might leave through the wrong interface, causing connectivity issues.
  • Q2: Can I set multiple default gateways for each network interface?
    A2: No, the system allows only one default gateway. Source-based routing solves this by creating separate routing tables per interface.
  • Q3: What is source-based routing and why is it important?
    A3: Source-based routing directs outgoing packets based on their source IP address or interface. It ensures that replies to incoming traffic go out through the same interface they arrived on, which is critical for multi-homed servers with several public IPs.
  • Q4: Do I need to disable NetworkManager to configure source-based routing on CentOS 8?
    A4: Yes, this tutorial uses network-scripts for configuration, so disabling NetworkManager is necessary to avoid conflicts.
  • Q5: Will this setup work for servers with more than two network interfaces?
    A5: Absolutely. You just need to create corresponding routing tables and configuration files for each interface.
Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
33145 North Miami, FL 2520 Coral Way apt 2-135
+1 302 425-97-76
700 300
ITGLOBAL.COM CORP
700 300

You might also like...

We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.