label: CentOS, dual network interfaces, ip command, Dual NIC, dual NIC routing, dual public IP
Scenario: A server is in the LAN, and provides services through the port mapping of the router. The server is equipped with dual network cards, which belong to different intranet segments. Each network segment has a public IP address mapped to the server.
Symptom: The public IP address corresponding to the default NIC in the two NICs of the server can access the server normally, and the other IP cannot be accessed.
Solution: You need to configure the two public IP addresses to access the server. Assume that the two network segments are: 192.168.0 and 192.168.1, and the IP addresses of the server on the two network segments are: 192.168.0.9 and 192.168.1.9, and the network card names are: enp2s0 and enp3s0. The routing configuration is as follows:
echo "101 Net1" >> /etc/iproute2/rt_tables
echo "102 Net2" >> /etc/iproute2/rt_tables
ip route add default via 192.168.0.1 dev enp2s0 table Net1
ip route add default via 192.168.1.1 dev enp3s0 table Net2
ip rule add from 192.168.0.9 table Net1
ip rule add from 192.168.1.9 table Net2