How to configure dual-IP gateway for dual-line dual-Nic in linux

Source: Internet
Author: User
A test machine is installed in the IDC. The system is ubuntu9.04X64 and the master machine is IBMX336. The user needs to be dual-line. Therefore, one Nic is used to configure the telecom address, and the other Nic is configured with the Unicom address. after the system is installed, the IP address is configured and the Unicom address and the telecom address can only have one pi... A test machine is installed in the IDC. The system is ubuntu9.04 X64 and the master machine is IBM X336. The user needs a dual-line connection. Therefore, one Nic is used to configure the telecom address, and the other Nic is configured with the Unicom address. after the system is installed, only one Unicom address and one telecom address can be pinged, if the China Unicom address does not match the gateway, you can only ping the China Telecom address. Otherwise, you can only ping the China Unicom address. if both China Unicom and China Telecom addresses are configured, the two cannot be connected.
Because it is not our company's network, we are not clear about the upper-layer implementation method. we only know that China Unicom and China Telecom lead to different VLANs, and China Telecom and China Unicom cannot pass through, however, other machines with the same intervention method can work normally out of the Internet, so as to eliminate network problems, in addition, the network can be accessed normally when the machine is 2003, and the NIC problem is also ruled out. This is the only problem with the operating system. After asking for help from google and other masters, we finally got it done. The procedure is as follows:
Ubuntu dual-Nic dual IP. different gateways. different subnets. how to ping two NICs at the same time,
The server environment is as follows :,
System: ubuntu9.04 X64 server
China Telecom IP (TEL): 114.80.0.4 netmask 255.255.128 gateway 114.80.0.3
China Unicom IP (CNC): 112.65.0.2 netmask 255.255.255.0 gateway 112.65.0.1
1. configure Nic information
# Vi/etc/network/interfaces
Auto lo
Iface lo inet loopback
# The primary network interface
Auto eth0
Iface eth0 inet static
Address 114.80.0.4
Netmask 255.255.255.255.128
Gateway 114.80.0.3
# Dns-* options are implemented by the resolvconf package, if installed
Dns-nameservers 202.96.209.20.
Auto eth1
Iface eth1 inet static
Address 112.65.0.2
Netmask 255.255.255.0
Save configuration information and restart the NIC
#/Etc/init. d/networking restart
2. added two route tables: China Telecom: tel Unicom: cnc
# Vi/etc/iproute2/rt_tables
252 tel
251 cnc
Save and launch
3. add routing rules
# Ip route flush table tel
# Ip route add default via 114.80.0.3 dev eth0 src 114.80.0.4 table tel
# Ip ruleadd from 114.80.0.4 table tel
In this example, the gateway of China Telecom is set up, and the telecom resources can be accessed only from the eth0 Nic.
# Ip route flush table cnc
# Ip route add default via 112.65.0.1 dev eth1 src 112.65.0.2 table cnc
# Ip rule add from 112.65.0.2 table cnc
The gateway of China Unicom is set up, and the access to Unicom resources is only available from the eth1 Nic.
4. configure the networking startup script file to add the following content before the end of exit 0
# Vi/etc/init. d/networking
Ip route flush table tel
Ip route add default via 114.80.0.3 dev eth0 src 114.80.0.4 table tel
Ip rule add from 114.80.0.4 table tel
Ip route flush table cnc
Ip route add default via 112.65.0.1 dev eth1 src 112.65.0.2 table cnc
Ip rule add from 112.65.0.2 table cnc
Exit 0
5. log out and restart the network.
#/Etc/init. d/networking restart
Then test the network conditions of the machine, and you will find that the addresses of both the Telecom and China Unicom can be accessed normally. This method also allows requests from the telecom IP address to be returned by the telecom route, and requests from the Netcom IP address to be returned by the Netcom route.
Supplement: Some experts on the Internet say that if the server is restarted or the network service is restarted, the above routing rules will become invalid. Therefore, you need to write the above command into the system startup script and network startup script.
For ubuntu/debian, the system startup script is/etc/rc. local.
For RedHat/centos, the system startup script is/etc/rc. d/rc. local.
For ubuntu/debian, the network startup script is/etc/init. d/networking.
For RedHat/centos, the network startup script is/etc/rc. d/init. d/network.
The system startup script has not been changed but has changed the network startup script. if you are interested, you can test it.


This article is from the lng1115 BLOG
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.