Serverspace Black Friday
JH
Joe Harris
May 2, 2021
Updated June 7, 2023

How to Configure Multiple Network Interfaces on CentOS 7

CentOS Linux Networks

Using another OS?

Select the desired version or distribution.

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
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

Vote:
5 out of 5
Аverage rating : 5
Rated by: 2
33145 North Miami, FL 2520 Coral Way apt 2-135
+1 302 425-97-76
700 300
ITGLOBAL.COM CORP
700 300
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.