How to Configure Multiple Network Interfaces on CentOS 8
If there are 2 or more network interfaces with public IP addresses in the system, it is not enough to make correct network settings for them to ensure their availability from the Internet. The downside of the default routing is that all network packets will leave the host through the default gateway. And at the same time, it does not matter which of the interfaces they came to initially. In this tutorial, we will configure the availability of multiple network interfaces from the outside in CentOS 8 using source-based routing.
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.
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)
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.
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
Let’s check if the iproute package is present. If not, install it.
dnf install iproute
Add new tables to configure routing policies.
Add records to the end of the file:
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:
Insert the following line into it with the current IP address instead of 184.108.40.206 and the name of the table created in the previous step instead of 400:
from 220.127.116.11 lookup 400
Replace 18.104.22.168/24 with the address of your subnet, enp0s5 with the name of the interface, 400 with the name of the corresponding table, and 22.214.171.124 with the gateway for routing traffic and insert it into the open file:
126.96.36.199/24 dev enp0s5 table 400
default dev enp0s5 via 188.8.131.52 table 400
After creating such files for each network interface, restart the network service and our goal is achieved.
systemctl restart network