Article title: linux dual-network card dual gateway, different IP segment settings. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
This problem has always plagued me. I can set it when I see this post. Post it here and check it later
You can set two IP addresses that are not in the same segment as one China Telecom and one China Netcom. No problems with centos
1. vi/etc/iproute2/rt_tables, adding two route tables: China Netcom and China Telecom
251 tel China Telecom route table
252 cnc Netcom route table
2. bind two addresses to the network card for two lines: China Telecom and China Netcom.
Ip addr add 192.168.0.2/24 dev eth0
Ip addr add 10.0.0.2/24 dev eth1
3. set the route tables of China Telecom and China Netcom respectively
China Telecom route table:
# Make sure to find the 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 of the telecom network
Ip route add default via 192.168.0.1 dev eth0 table tel
China Netcom route table:
# Make sure to find the local subnet
Ip route add 10.0.0.0/24 via 10.0.0.2 dev eth1 table cnc
# Internal loopback network
Ip route add 127.0.0.0/8 dev lo table cnc
#10.0.0.1 is the default gateway of China Netcom.
Ip route add default via 10.0.0.1 dev eth1 table cnc
4. China Telecom and China Netcom have their own route tables and have their own policies set up to route the response data packets of 192.168.0.2 to the China Telecom route table. the response data packets of 10.0.0.2 are routed to the China Netcom route table.
Ip rule add from 192.168.0.1 table tel
Ip rule add from 10.0.0.1 table cnc
Finally, in special cases, the network administrator needs to add IP addresses to the route in batches to simplify the process.
Ip rule del from 192.168.0.0/24 table tel
Ip rule del from 10.0.0.0/24 table cnc