Dual-network card dual-IP dual-Gateway under Ubuntu9.04

Source: Internet
Author: User
Ubuntu dual-nic Dual IP address. different gateways. different subnets. how to ping two NICs at the same time, the server environment is as follows:, system: Ubuntu9.04X64server telecommunications IP (TEL): 114.80.0.4netmask?201710000128gateway114.80.0.3 Unicom IP (CNC): 112.65.0.2netmask25

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: Ubuntu 9.04X64 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 online experts say that if the server is restarted or the network service is restarted, the above routing rules will become invalid. Therefore, you needCommandWrite 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. PS: Sometimes/etc/init. d/networking restart is useless, stop first and then start

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.