Subscription-based service of managed cloud infrastructure

How to Configure Multiple Network Interfaces on CentOS 7

Joe Harris
May 2, 2021

To configure the server availability through different network interfaces and public IP addresses, it is not enough just to set up parameters for each network card. There can be only one default gateway, that is why all network packets will leave the server through it, even if they were originally received to a different address. This is a disadvantage of the used by default destination-based routing policy. In this tutorial, we will configure multiple network interfaces on CentOS 7 using source-based routing.

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

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

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 you need to put the IP address of the network interface, and instead of table200 — the tables added above, one for each interface:

from 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. dev eth0 table table200
default dev eth0 via 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

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.