31.07.2025

How to Configure Multiple Network Interfaces and Source-Based Routing on CentOS 7

To ensure server availability across multiple network interfaces and public IP addresses, simply configuring each network card is not enough. Since the system allows only one default gateway, all outgoing packets will route through that single gateway, regardless of the interface they arrived on. This limitation stems from the default destination-based routing policy. In this tutorial, we will demonstrate how to configure multiple network interfaces on CentOS 7 with source-based routing, enabling outbound traffic to be routed based on its source address for improved reliability and network performance.

Configuring network interfaces

If you use a server in Serverspace, then the parameters of network interfaces are configured automatically when you add them or create a server. Otherwise, it is necessary to bring the parameters to the form below. The above example can be copied by substituting your values for the interface name (eth0), gateway (GATEWAY), MAC address (HWADDR), IP address (IPADDR) and in some cases the subnet mask (NETMASK):

nano /etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO=none
DEFROUTE=yes
DEVICE=eth0
GATEWAY=33.44.55.1
HWADDR=aa:11:bb:22:cc:33
IPADDR=33.44.55.66
MTU=1500
NETMASK=255.255.255.0
ONBOOT=yes
STARTMODE=auto
TYPE=Ethernet

The GATEWAY is set up only for one network interface, since there should only be one in the system. Configuring the second interface:

nano /etc/sysconfig/network-scripts/ifcfg-eth1
BOOTPROTO=none
DEVICE=eth1
HWADDR=bb:cc:dd:ee:ff:gg
IPADDR=66.77.88.99
MTU=1500
NETMASK=255.255.255.0
ONBOOT=yes
STARTMODE=auto
TYPE=Ethernet

Similarly, you can configure the number of interfaces that are connected to the system.

Setting up source based routing

Just in case, it is worth checking if the iproute package is installed and install if not:

yum install iproute

Now open the following file:

nano /etc/iproute2/rt_tables

Add the following lines to the end:

200 table200
201 table201

The record must be in the format number space table name. Both values can be arbitrary. The only condition is their uniqueness relative to the values of other records in the file. The number of lines must correspond to the number of network interfaces for which we are configuring accessibility.

Now let's create files with routing tables parameters. You need to create a separate such file for each interface, replacing eth0 in the file name with the actual name of the network connection.

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

Below is the contents of the file, where instead of 33.44.55.66 you need to put the IP address of the network interface, and instead of table200 - the tables added above, one for each interface:

from 33.44.55.66 lookup table200

And the corresponding files with routing rules. Created in the same way as routing table parameter files.

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

It is necessary to substitute the actual values of the subnet address, gateway, interface name and the table value corresponding to the value from the previous file.

33.44.55.0/24 dev eth0 table table200
default dev eth0 via 33.44.55.1 table table200

Such file pairs are created for each network interface in the system with the corresponding values.

Restart the network service for the changes to take effect:

systemctl restart network

Conclusion

Configuring multiple network interfaces on CentOS 7 with source-based routing ensures that outbound traffic is routed through the correct interface based on its source IP address. This setup overcomes the limitation of having only one default gateway in traditional destination-based routing, thereby improving server availability and network reliability across different public IP addresses. Following this guide allows system administrators to efficiently manage complex network configurations and optimize traffic flow in multi-interface environments.

FAQ