Enable a computer with two NICs to have two gateways)

Source: Internet
Author: User

Enable a computer with two NICs to have two gateways)

First, we need to declare that it is impossible for a computer with two NICs to have two gateways, because the default gateway can only be one.

Install two NICs for the server, with different IP addresses and gateways (intranet and Internet) respectively. The Internet can be accessed through the Internet Nic, and the Intranet can be accessed through the Intranet Nic, it seems very easy to implement, but in fact it is very difficult, because the default gateway can only be one!

The solution is:

1. Set a network card (such as the Internet) to the default gateway;

2. manually add a static route so that the data of another network segment (Intranet) passes through the second network card. Use the route command. The command example is as follows, hoping to help some comrades with a little effort.

Reference command:

Example 1: Route add-P 10.0.0.0 mask 255.255.255.0 10.40.4.200 (enable 10.0.0.1 access to the network adapter 10.40.4.200, And the subnet mask behind the mask)

Example 2: Route add-P 10.0.0.0 mask route 0.0.0 10.40.4.200

Example 3: Route add-P 0.0.0.0 mask 0.0.0.0 10.40.4.200 (needless to say, let all the accesses go through 10.40.4.200)

Note:

1. With the-p Parameter added, the added route is a permanent route and will not be initialized because the computer restarts. 10.40.4.200 is the IP address of my computer Nic. Enter route to get more help.

2. If your computer already has two gateways (for example, SoftEther), you can use Route print to view the two 0.0.0.0 routes. You can delete the 0.0.0.0 routes and add them again.

Route Delete 0.0.0.0 "delete all 0.0.0.0 routes"

 

Note: When I look for information on the network, I often see someone asking similar questions. We can see that you are familiar with routing. The following information is provided for your reference:

1, the interpretation of the route command http://www.kpcn.org/news/Read.asp? Newsid= 8527
2, the learning Windows Network command route command small file http://www.kpcn.org/news/Read.asp? Newsid= 8528

 

========== The content of another article ==============

It is often said that a computer needs to access two networks at the same time (one is the Internet and the other is the enterprise intranet. Take this unit as an example: the address is fictitious ^_^
The machine has two NICs connected to the two switches.
Internet address: 218.22.123.123, subnet mask: 255.255.255.0, Gateway: 218.22.123.254
Intranet address: 10.128.123.123, subnet mask: 255.255.255.0, Gateway: 10.128.123.254
If you set the IP address and gateway of each network card according to the normal setting method, you will see it when you use Route print in cmd.
Network destination netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 218.22.123.254 218.22.123.123 20
0.0.0.0 0.0.0.0 10.128.123.254 10.128.123.123 1
That is, there are two gateways pointing to 0.0.0.0, so there will be a route conflict and both networks will not be accessible. To access two networks at the same time, you must use the route command.
Step 1: Route Delete 0.0.0.0 "delete all 0.0.0.0 routes"
Step 2: Route add 0.0.0.0 mask 0.0.0.0 218.22.123.254 "add 0.0.0.0 network route"
Step 3: Route add 10.0.0.0 mask route 0.0.0 10.128.123.254 "add 10.0.0.0 network route"
In this case, you can access the two networks at the same time. However, if you encounter a problem, the route added using the above command will be automatically lost after the system restarts. How can you save the existing route table?
In Win2000, you can use Route add-P to add a static route. After restart, the route will not be lost. Note that you need to remove the gateway that is connected to the NIC of the enterprise intranet in the TCP/IP settings before use.

 

==================Configure the route table for dual-Gateway network interfaces in Linux==================

Http://hi.baidu.com/xibeihuohu/blog/item/a54d27fd18b8bf1f08244d1a.html

Due to the interconnection between China Telecom and China Netcom, many people choose dual-line data centers. The so-called dual-line data center has two outlets, one for China Telecom and one for China Netcom. I recently tested a server in a dual-line data center. I plan to use it as the database server of the Forum. The server operating system is Linux. We plan to configure Dual IP addresses and dual domain names so that viewers can access the server through both the Telecom and China Netcom lines. I encountered a Problem When configuring the network. By default, Linux only has one gateway. I have been querying the network for a long time and found a solution. So I sorted it out. Thanks to the original author jac003ke.

Server Operating System RedHat Linux 9, set two route tables
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

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.