Linux dual network card dual gateway settings for different IP segments

  

This question has been bothering me. I can see that this post can be set, and there is still no problem. Hereby posted it, keep it for later

Two IPs that are not in one segment are considered as a telecommunications network connection to set up. Centos no problem

1. vi /etc/iproute2/rt_tables, increase the routing table between Netcom and Telecom

251 tel Telecom routing table

252 cnc network access by table < Br>

2. Bind two addresses to the NIC for both Telecom and Netcom

ip addr add 192.168.0.2/24 dev eth0

ip addr add 10.0.0.2 /24 dev eth1

3. Set the routing table for Telecom and Netcom respectively

Telecom routing table:

#Ensure local subnet

ip route Add 192.168.0..0/24 via 192.168.0.2 dev eth0 table tel

#internal loopback network

ip route add 127.0.0.0/8 dev lo table tel

#192.168.0.1 is the default gateway address for telecommunication networks

ip route add default via 192.168.0.1 dev eth0 table tel

Netcom line routing table:

#make local Subnet

ip route add 10.0.0.0/24 via 10.0.0.2 dev eth1 table cnc

#内回环网络

ip route add 127.0.0.0/8 dev lo Table cnc

#10.0.0.1 is the default gateway of Netcom

ip route add default via 10.0.0.1 dev eth1 table cnc

4. Telecom and Netcom each have their own routing table. The strategy is to let the response packet of 192.168.0.2 go to the routing table route of the telecom, and the response packet of 10.0.0.2 to go to the routing table routing of Netcom

ip rule add from 192.168.0.1 table tel

ip rule add from 10.0.0.1 table cnc

Finally, consider the special case of the network management needs to add IP to the route in order to be able to pass, simplify

ip rule del from 192.168.0.0/24 table tel

ip rule del from 10.0.0.0/24 table cnc



Copyright © Windows knowledge All Rights Reserved