RHEL中双网卡IP不能同时被访问的解决方法

本文介绍在RHEL6.5环境下,如何正确配置具备双网卡的服务器,解决因默认网关冲突导致的部分网络连接不可达的问题。通过删除网关参数、添加静态路由表,实现双网卡同时正常工作。

环境简述:
服务器A具备双网卡,安装操作系统RHEL6.5
----------------------------------------------------------
网卡显示名称      IP地址                网关  
----------------------------------------------------------
eth0              192.168.153.4    192.168.153.1
eth1              192.168.152.4    192.168.152.1
-----------------------------------------------------------
网卡配置文件:
[root@clovem ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0 
ONBOOT=yes
BOOTPROTO=static 
TYPE=Ethernet 
IPADDR=192.168.153.4 
NETMASK=255.255.255.0 
GATEWAY=192.168.153.1 
[root@clovem ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1 
DEVICE=eth1 
ONBOOT=yes
BOOTPROTO=static 
TYPE=Ethernet 
IPADDR=192.168.152.4 
NETMASK=255.255.255.0 
GATEWAY=192.168.152.1

重启网络服务
[root@clovem ~]# service network restart 
查看其路由信息:
[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
可以发现双网卡的默认网关为192.168.152.1 
从其他网段192.168.151.0/24的某台测试机:192.168.150.252
访问192.168.153.4以及192.168.152.4 ,只能通过192.168.152.4进行网络连接,而192.168.153.4却不可以,从上面的路由表中可以看出两个网卡配置文件中的网关参数只有192.168.152.1生效,并被设置为默认网关。
解决方法:
1.将两个网卡配置文件中的GATEWAY参数全部删除,即
[root@clovem ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0 
ONBOOT=yes
BOOTPROTO=static 
TYPE=Ethernet 
IPADDR=192.168.153.4 
NETMASK=255.255.255.0 
[root@clovem ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1 
DEVICE=eth1 
ONBOOT=yes
BOOTPROTO=static 
TYPE=Ethernet 
IPADDR=192.168.152.4 
NETMASK=255.255.255.0

2. 重启网络
[root@clovem ~]# service network restart
3.查看路由表
[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
发现默认网关没有被设置
4. 添加静态路由表
[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. 此时再次通过外部测试机访问均可
[root@storage252 ~]# ifconfig  eth0 
eth0      Link encap:Ethernet  HWaddr 00:50:56:82:56:55 
          inet addr:192.168.150.252  Bcast:192.168.150.255  Mask:255.255.255.0 
          inet6 addr: fe80::250:56ff:fe82:5655/64 Scope:Link 
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1 
          RX packets:25910143 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:19888495 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:26258149440 (24.4 GiB)  TX bytes:16323278977 (15.2 GiB)

1234567891011121314 [root@storage252 ~]# ping -W1 -c2 192.168.152.4 
PING 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 ms 
64 bytes from 192.168.152.4: icmp_seq=2 ttl=63 time=0.349 ms 
--- 192.168.152.4 ping statistics --- 
2 packets transmitted, 2 received, 0% packet loss, time 1000ms 
rtt min/avg/max/mdev = 0.324/0.336/0.349/0.022 ms 
[root@storage252 ~]# ping -W1 -c2 192.168.153.4 
PING 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 ms 
64 bytes from 192.168.153.4: icmp_seq=2 ttl=63 time=0.271 ms 
--- 192.168.153.4 ping statistics --- 
2 packets transmitted, 2 received, 0% packet loss, time 999ms 
rtt min/avg/max/mdev = 0.271/0.306/0.342/0.039 ms

可以根据需要将静态路由命令添加至相关配置文件,重启之后仍然生效。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值