Dual-gateway for linux dual-Nic, different IP segment settings

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.