СHRISTMAS
WHEEL OF FORTUNE

Tap the button and win a guaranteed prize right now!

By registering, you are signing up to receiving e-mails.
JH
Joe Harris
May 2 2021
Updated June 7 2023

How to Configure Multiple Network Interfaces on CentOS 8

CentOS Linux Networks

Using another OS?

Select the desired version or distribution.

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.

nano /etc/sysconfig/network-scripts/ifcfg-enp0s5

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)
BOOTPROTO=none
DEFROUTE=yes
DEVICE=enp0s5
GATEWAY=54.43.32.1
HWADDR=56:67:78:89:01:ab
IPADDR=54.43.32.11
MTU=1500
NETMASK=255.255.255.0
ONBOOT=yes
STARTMODE=auto
TYPE=Ethernet

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.

Disable NetworkManager

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.

nano /etc/iproute2/rt_tables

Add records to the end of the file:

400 400
401 401

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:

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

Insert the following line into it with the current IP address instead of 54.43.32.11 and the name of the table created in the previous step instead of 400:

from 54.43.32.11 lookup 400

Second file:

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

Replace 54.43.32.0/24 with the address of your subnet, enp0s5 with the name of the interface, 400 with the name of the corresponding table, and 54.43.32.1 with the gateway for routing traffic and insert it into the open file:

54.43.32.0/24 dev enp0s5 table 400
default dev enp0s5 via 54.43.32.1 table 400

After creating such files for each network interface, restart the network service and our goal is achieved.

systemctl restart network

Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
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.