Environment Description:
Server A has dual NICs and installs the operating system RHEL6.3
----------------------------------------------------------
Nic display name IP address Gateway
----------------------------------------------------------
Eth0 192.168.153.4 192.168.153.1
Eth1 192.168.152.4 192.168.152.1
-----------------------------------------------------------
Nic configuration file:
12345678910111213141516 [root @ clovem ~] # Cat/etc/sysconfig/network-scripts/ifcfg-eth0DEVICE = eth0ONBOOT = yesBOOTPROTO = staticTYPE = EthernetIPADDR = 192.168.153.4NETMASK = 255.255.255.0GATEWAY = 192.168.153.1 [root @ clovem ~] # Cat/etc/sysconfig/network-scripts/ifcfg-eth1DEVICE = eth1ONBOOT = yesBOOTPROTO = staticTYPE = EthernetIPADDR = 192.168.152.4NETMASK = 255.255.255.0GATEWAY = 192.168.152.1
Restart NETWORK SERVICE
[Root @ clovem ~] # Service network restart
View its route information:
[Root @ clovem ~] # Route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.153.0*255.255.255.0 U 0 0 0 eth0
192.168.152.0*255.255.255.0 U 0 0 0 eth1
Link-local * 255.255.0.0 U 1015 0 0 eth0
Link-local * 255.255.0.0 U 1016 0 0 eth1
Default 192.168.152.1 255.255.255.0 UG 1017 0 0 eth1
We can find that the default gateway of the dual-nic is 192.168.152.1.
A test machine from another network segment 192.168.151.0/24: 192.168.150.252
Access to 192.168.153.4 and 192.168.152.4 can only be connected through 192.168.152.4, but 192.168.153.4 cannot. From the preceding routing table, we can see that the gateway parameter in the two Nic configuration files takes effect only for 192.168.152.1, and is set as the default gateway.
Solution:
1. Delete All GATEWAY parameters in the two Nic configuration files, that is
1234567891011121314 [root @ clovem ~] # Cat/etc/sysconfig/network-scripts/ifcfg-eth0DEVICE = eth0ONBOOT = yesBOOTPROTO = staticTYPE = EthernetIPADDR = 192.168.153.4NETMASK = 255.255.255.0 [root @ clovem ~] # Cat/etc/sysconfig/network-scripts/ifcfg-eth1DEVICE = eth1ONBOOT = yesBOOTPROTO = staticTYPE = EthernetIPADDR = 192.168.152.4NETMASK = 255.255.255.0
2. Restart the network
[Root @ clovem ~] # Service network restart
3. view the route table
[Root @ clovem ~] # Route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.153.0*255.255.255.0 U 0 0 0 eth0
192.168.152.0*255.255.255.0 U 0 0 0 eth1
Link-local * 255.255.0.0 U 1015 0 0 eth0
Link-local * 255.255.0.0 U 1016 0 0 eth1
No Default Gateway is set
4. Add a static route table
12345678 [root @ clovem ~] # Echo "153 net_153">/etc/iproute2/rt_tables [root @ clovem ~] # Echo "152 net_152">/etc/iproute2/rt_tables [root @ clovem ~] # Ip route flush table net_153 [root @ clovem ~] # Ip route add default via 192.168.153.1 dev eth0 src 192.168.153.4 table net_153 [root @ clovem ~] # Ip rule add from 192.168.153.4 table net_153 [root @ clovem ~] # Ip route flush table net_152 [root @ clovem ~] # Ip route add default via 192.168.152.1 dev eth0 src 192.168.153.4 table net_152 [root @ clovem ~] # Ip rule add from 192.168.152.4 table net_152
5. Access via external test machine again
123456789 [root @ storage252 ~] # Ifconfig eth0eth0 Link encap: Ethernet HWaddr 00: 50: 56: 82: 56: 55 inet addr: 192.168.150.252 Bcast: 192.168.150.255 Mask: 109addr: fe80: 250: 56ff: fe82: 5655/64 Scope: LinkUP broadcast running multicast mtu: 1500 Metric: 1RX packets: 25910143 errors: 0 dropped: 0 overruns: 0 frame: 0TX packets: 19888495 errors: 0 dropped: 0 overruns: 0 carrier: 0 collisions: 0 txqueuelen: 1000RX bytes: 26258149440 (24.4 GiB) TX bytes: 16323278977 (15.2 GiB)1234567891011121314 [root @ storage252 ~] # Ping-W1-c2 192.168.152.4PING 192.168.152.4 (192.168.152.4) 56 (84) bytes of data.64 bytes from 192.168.152.4: icmp_seq = 1 ttl = 63 time = 0.324 ms64 bytes from 192.168.152.4: icmp_seq = 2 ttl = 63 time = 0.349 ms --- 192.168.152.4pingstatistics --- 2 packets transmitted, 2 received, 0% packet loss, time1000msrtt min/avg/max/mdev = 0.324/0.336/0.349/0.022 MS [root @ storage252 ~] # Ping-W1-c2 192.168.153.4PING 192.168.153.4 (192.168.153.4) 56 (84) bytes of data.64 bytes from 192.168.153.4: icmp_seq = 1 ttl = 63 time = 0.342 ms64 bytes from 192.168.153.4: icmp_seq = 2 ttl = 63 time = 0.271 ms --- 192.168.153.4pingstatistics --- 2 packets transmitted, 2 received, 0% packet loss, time999msrtt min/avg/max/mdev = 0.271/0.306/0.342/0.039 MS
Finally, you must add a default gateway to allow the system to access hosts in other CIDR blocks.
[Root @ clovem ~] # Route add default gw 192.168.153.1
You can add the Static Routing command to the relevant configuration file as needed, and it will still take effect after restart.