How to Configure Multiple Network Interfaces on CentOS 7
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):
The GATEWAY is set up only for one network interface, since there should only be one in the system. Configuring the second interface:
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:
Add the following lines to the end:
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.
Below is the contents of the file, where instead of 220.127.116.11 you need to put the IP address of the network interface, and instead of table200 — the tables added above, one for each interface:
from 18.104.22.168 lookup table200
And the corresponding files with routing rules. Created in the same way as routing table parameter files.
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.
22.214.171.124/24 dev eth0 table table200
default dev eth0 via 126.96.36.199 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