Centos 6.5 dual network card dual IP dual gateway configuration

Due to the company's business needs, it is necessary to configure telecommunications on the server to connect the IP addresses of the two operators to realize data transmission from the two addresses, that is, both IP addresses can communicate with the external network.

At that time, I found that two IP addresses and gateways were configured on the two network cards of the server. After restarting the network service, the system would select the gateway of one of the network cards as the data transmission gateway by default, and the consequence of this was that one network card could not communicate with the outside world. , and then manually added the routing point to the network card that cannot communicate, the result is either to replace the default route of the system or the routing point does not take effect, so that the two network cards still cannot communicate with the external network at the same time. Create two routing tables to transmit the data of the two network cards respectively:

The specific operations are as follows:


Telecom network 192.168.1.2/24 gateway 192.168.1.1
Unicom network 172.16.1.2/24 gateway 172.16.1.1

Step 1:
Add the complete address information of the telecom network to the first network card, including IP address, mask, gateway
#vim /etc /sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.2
NETMASK=255.255.255.0
GATEWAY=192.168.1.1

The second network card only adds IP address, mask, no Add gateway
#vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.16.1.2
NETMASK=255.255.255.0

Step 2:
Create two for China Telecom and China Unicom Routing table
#vim /etc/iproute2/rt_tables
252 tel
252 cnc

Step 3: Add routing rules
#ip route flush table tel
#ip route add default via 192.168.1.1 dev eth0 src 192.168.1.2 table tel
#ip rule add from 192.168.1.2 table tel
Here is to set telecom as a gateway, and it can make telecom resource access only go out from eth0 network card

#ip route flush table cnc
#ip route add default via 172.16.1.1 dev eth1 src 172.16.1.2 table cnc
#ip rule add from 172.16.1.2 table cnc
Here is the gateway for setting up China Unicom, and it can realize that the resource access of China Unicom can only be accessed from eth1 Step 4: Configure the network

startup script file
#vim /etc/init.d/networking
ip route flush table tel
ip route add default via 192.168.1.1 dev eth0 src 192.168.1.2 table tel
ip rule add from 192.168.1.2 table tel
ip route flush table cnc
ip route add default via 172.16.1.1 dev eth1 src 172.16.1.2 table cnc
ip rule add from 172.16.1.2 table cnc
exit 0
Step 5: Exit and restart network #chmod u
+x /etc/init.d/networking 
#/etc/init.d/networking restart Add the startup script to the boot-up auto-start file to execute the startup script at startup #vim /etc/rc.local /etc/init.d/networking restart At this time, the addresses of China Telecom and China Unicom can be accessed normally.







Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324674347&siteId=291194637