设为首页收藏本站
查看: 18998|回复: 0

[Linux] Linux下双网口同一网段问题

[复制链接]

25

主题

9

回帖

280

积分

中级会员

积分
280
Willian.Mo 发表于 2015-7-10 12:01:02 | 显示全部楼层 |阅读模式
本帖最后由 Willian.Mo 于 2015-8-10 11:42 编辑

Linux系统同上经常遇到双网口配置同一网段IP问题,在网上看到这篇文章写得不错,讲得也很详细。
原文出处:http://blog.163.com/jiangh_1982/blog/static/121950520123264274259/

=========================复制原文==========================

写在前面:经常遇到客户将板卡上的两个网络设备的IP地址设置为同一网段的情况,我的解释是,不能设置为同一网段,但是我不知道这个说法到底是根据什么,查了很多资料也没找到明确的说法,但是下面这个实验能够说明一些现象的原因。
初步做了一下实验:
双网口.jpg

服务器为RHEL5 双网卡,eth0为234,eth1为233,我本地客户机为172。
RHEL: ifconfig如下:
[mw_shl_code=bash,true][root@server1 ~]# ifconfig
eth0      Link encap:Ethernet HWaddr 00:0C:29:A5:D5:A3
          inet addr:60.232.83.233 Bcast:60.232.83.255 Mask:255.255.255.128
略。。。。。。。

eth1      Link encap:Ethernet HWaddr 00:0C:29:A5:D5:AD
          inet addr:60.232.83.234 Bcast:60.232.83.255 Mask:255.255.255.128
          略。。。。。。。。。
lo        Link encap:Local Loopback
          inet addr:127.0.0.1 Mask:255.0.0.0
          略。。。。。。。。。[/mw_shl_code]
在客户机XP上ping两个地址,都是通的。
[mw_shl_code=bash,true]C:\ >ping 60.232.83.233
Pinging 60.232.83.233 with 32 bytes of data:
Reply from 60.232.83.233: bytes=32 time=9ms TTL=64
Reply from 60.232.83.233: bytes=32 time<1ms TTL=64

C:\ >ping 60.232.83.234
Pinging 60.232.83.234 with 32 bytes of data:
Reply from 60.232.83.234: bytes=32 time<1ms TTL=64
Reply from 60.232.83.234: bytes=32 time<1ms TTL=64[/mw_shl_code]
此时用arp –a在本地查看
[mw_shl_code=bash,true]C:\ >arp -a
Interface: 60.232.83.172 --- 0x20005
Internet Address      Physical Address      Type
60.232.83.129         00-04-96-1a-ca-60     dynamic
60.232.83.233         00-0c-29-a5-d5-a3     dynamic
60.232.83.234         00-0c-29-a5-d5-a3     dynamic[/mw_shl_code]
发现两个网卡的MAC地址一样,也就是eth0的mac地址。
现在我们[root@server1 ~]# ifconfig eth1 down
来禁止eth1,结果ping 233和234的地址都是通的。
这里可以这样理解,arp –a看到本地解析到得两块网卡mac地址是一样的,局域网是通过2层寻址的不可能涉及到ip这样的3层协议,因此mac地址相同ping哪个都应该是通的,但是为什么本地会出现不同的IP相同的mac地址呢?在Linux上看到的明明是不同的MAC地址00:0C:29:A5:D5:A3,00:0C:29:A5:D5:AD
继续测试,现在把eth0禁止。
[mw_shl_code=bash,true][root@server1 ~]# ifconfig eth0 down
[root@server1 ~]# ifconfig
eth1      Link encap:Ethernet HWaddr 00:0C:29:A5:D5:AD
          inet addr:60.232.83.234 Bcast:60.232.83.255 Mask:255.255.255.128
          inet6 addr: fe80::20c:29ff:fea5:d5ad/64 Scope:Link
          略。。。。。
lo        Link encap:Local Loopback
          inet addr:127.0.0.1 Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          略。。。。
[/mw_shl_code]
本地先arp –d清除一下缓存。然后再ping两块网卡的IP地址,依然可以ping通两个地址。
Arp –a后发现:
[mw_shl_code=bash,true]C:\>arp -a
Interface: 60.232.83.172 --- 0x20005
Internet Address      Physical Address      Type
60.232.83.129         00-04-96-1a-ca-60     dynamic
60.232.83.233         00-0c-29-a5-d5-ad     dynamic
60.232.83.234         00-0c-29-a5-d5-ad     dynamic[/mw_shl_code]
Mac地址成为另一块也就是eth1的mac地址。
然后开启eth0,然后再ping测试一下。结果如下:
[mw_shl_code=bash,true]C:\>arp -a
Interface: 60.232.83.172 --- 0x20005
Internet Address      Physical Address      Type
60.232.83.129         00-04-96-1a-ca-60     dynamic
60.232.83.233         00-0c-29-a5-d5-a3     dynamic
60.232.83.234         00-0c-29-a5-d5-ad     dynamic[/mw_shl_code]
这才是一张正常的地址表。
这时候再关闭eth0,结果就ping不通了,因为这时候缓存里的233的mac地址已经关闭。
Arp –d之后就可以ping通了,此时eth0依然处于关闭状态,只是清楚了一下缓存表,这样再起ping233地址,可以ping通了,得出的结果是234的mac地址。
[mw_shl_code=bash,true]C:\>arp -a
Interface: 60.232.83.172 --- 0x20005
Internet Address      Physical Address      Type
60.232.83.129         00-04-96-1a-ca-60     dynamic
60.232.83.233         00-0c-29-a5-d5-ad     dynamic
60.232.83.234         00-0c-29-a5-d5-ad     dynamic[/mw_shl_code]
此时开启eth0,现在本地缓存中的两个IP依然对应的还是234的mac地址。Arp –d清除一下,这次先ping 234再ping 233,结果两个都是233的既eth0的mac地址。
实验做到这里脑子有点乱,把这台Linux服务器换成Windows Server 2003,就没有这问题出现。
[mw_shl_code=bash,true]C:\Documents and Settings\Administrator>ipconfig /all
Windows IP Configuration
   Host Name . . . . . . . . . . . . : newxyz-yz5l2clv
   Primary Dns Suffix . . . . . . . :
   Node Type . . . . . . . . . . . . : Unknown
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
Ethernet adapter 本地连接 3:
   Connection-specific DNS Suffix . :
   Description . . . . . . . . . . . : VMware Accelerated AMD PCNet Adapter #2
   Physical Address. . . . . . . . . : 00-0C-29-68-03-AF
   DHCP Enabled. . . . . . . . . . . : No
   IP Address. . . . . . . . . . . . : 60.232.83.251
   Subnet Mask . . . . . . . . . . . : 255.255.255.128
   Default Gateway . . . . . . . . . :
Ethernet adapter 本地连接 2:
   Connection-specific DNS Suffix . :
   Description . . . . . . . . . . . : VMware Accelerated AMD PCNet Adapter
   Physical Address. . . . . . . . . : 00-0C-29-68-03-A5
   DHCP Enabled. . . . . . . . . . . : No
   IP Address. . . . . . . . . . . . : 60.232.83.250
   Subnet Mask . . . . . . . . . . . : 255.255.255.128
   Default Gateway . . . . . . . . . :
本地ping两块网卡之后显示如下:
C:\Documents and Settings\Administrator>arp -a

Interface: 60.232.83.198 --- 0x10005
Internet Address      Physical Address      Type
60.232.83.129         00-04-96-1a-ca-60     dynamic
60.232.83.250         00-0c-29-68-03-a5     dynamic
60.232.83.251         00-0c-29-68-03-af     dynamic[/mw_shl_code]
关闭任何一个网卡都是无法ping的。
所以在Linux下网卡可能采用一些机制,比如说,首先,问题属于双网卡同一网段linux系统网卡自动路由的问题。
2、如果系统有两个独立网卡,并且这两个网卡的IP属于同一个子网,那么后面这个网卡的IP将自动路由到前面一个网卡上。
也就是说数据将自动路由到前面的那个网卡上。在不加任何设置的情况下,如果前面的网卡断线或者故障了(拔掉网线或者网卡指坏了),必须用命令down调后 面的网卡然后再up,这时后面的网卡才能启用。此时两个IP又同时路由到后面的网卡上,也就是说后面的网卡又具有两个IP地址。
当然两块网卡设置成同一网段是不合理的。
我的技术实在有限,这些都是实验后的猜测,就当抛砖引玉,希望有人能给解释一下。谢谢
改天实验一下bond~~~~
====================
结论:
这种现象正常。我们将其理解为在Linux系统下双网卡设置同样网段没有正确更新路由表的能力。因此会造成上述情况出现。
所以最好的方法是避免这样操作。

====================






回复

使用道具 举报

您需要登录后才可以回帖 登录

本版积分规则

Archiver|手机版|小黑屋|米尔科技论坛   

GMT+8, 2024-4-20 15:15 , Processed in 0.679060 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表