How to configure dual network card routing on CentOS?
To set up CentOS dual network card routing, you need to follow the steps outlined below:
- Make sure that your CentOS system has two network cards installed, and that they are connected to separate networks.
- Open the terminal and use the following command to view all network interfaces in the system:
ifconfig -a
- Identify the names of your two network cards based on the output results, which are typically eth0 and eth1.
- Edit the network interface configuration file using the following command to open the editor:
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
- Set the IP address, subnet mask, and gateway information for the eth0 network card, with an example configuration as follows:
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
- Save and exit the editor, then repeat the above steps to configure the eth1 network card.
- Enable IP forwarding by entering the following command in the terminal:
sudo sysctl -w net.ipv4.ip_forward=1
- Edit the router configuration file and open the editor with the following command:
sudo vi /etc/sysconfig/network-scripts/route-eth0
- Add route information, configuration examples are as follows:
192.168.2.0/24 via 192.168.1.1
- Save and exit the editor, then repeat the above steps to configure the eth1 network card.
- Finally, restart the network service to apply the configuration.
sudo systemctl restart network
After completing the steps above, your CentOS system will be configured with dual network card routing. You can test the connectivity of the two network cards using the ping command to ensure everything is working properly.