嵌入式系统双网卡同网段疑难问题处理笔记

我们都知道,在windows系统中2块不同的网卡,可以设ip地址为同网段,也可以设置为不同的网段,这个功能在嵌入式系统中能否实现呢?(我也是因为一些特殊的原因,才想起验证个问题)。
首先我使用的飞凌嵌入式公司的6ull-S开发板,linux系统。

电脑网络配置

以太网适配器 以太网 2:

   连接特定的 DNS 后缀 . . . . . . . : 
   描述. . . . . . . . . . . . . . . : Realtek USB FE Family Controller
   物理地址. . . . . . . . . . . . . : 00-E0-4C-36-06-63
   DHCP 已启用 . . . . . . . . . . . : 否
   自动配置已启用. . . . . . . . . . : 是
   本地链接 IPv6 地址. . . . . . . . : fe80::71bf:bb21:8fcd:4c%8(首选) 
   IPv4 地址 . . . . . . . . . . . . : 192.168.0.9(首选) 
   子网掩码  . . . . . . . . . . . . : 255.255.255.0
   IPv4 地址 . . . . . . . . . . . . : 192.168.1.9(首选) 
   子网掩码  . . . . . . . . . . . . : 255.255.255.0
   IPv4 地址 . . . . . . . . . . . . : 192.168.2.9(首选) 
   子网掩码  . . . . . . . . . . . . : 255.255.255.0
   默认网关. . . . . . . . . . . . . : 192.168.0.1
   DHCPv6 IAID . . . . . . . . . . . : 167829580
   DHCPv6 客户端 DUID  . . . . . . . : 00-01-00-01-29-66-F4-50-B8-97-5A-F6-D3-24
   DNS 服务器  . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                       fec0:0:0:ffff::2%1
                                       fec0:0:0:ffff::3%1
   TCPIP 上的 NetBIOS  . . . . . . . : 已启用

可见,我在我的第二个网卡上配置了不同网段的多个ip,这样我们可以方便在不同网段之间切换。经验之谈,呵呵。

开发板网络配置及验证过程

首先验证网络1:

root@fetmx6ull-s:~# ifconfig eth0 192.168.0.100 up
root@fetmx6ull-s:~# ifconfig eth1 down
root@fetmx6ull-s:~# ifconfig 
eth0      Link encap:Ethernet  HWaddr AA:CC:DD:EE:FF:DD  
          inet addr:192.168.0.100  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::a8cc:ddff:feee:ffdd%1995876048/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:562 errors:0 dropped:0 overruns:0 frame:0
          TX packets:39 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:70488 (68.8 KiB)  TX bytes:7922 (7.7 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1%1995876048/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

root@fetmx6ull-s:~# ping 192.168.0.9
PING 192.168.0.9 (192.168.0.9): 56 data bytes
64 bytes from 192.168.0.9: seq=0 ttl=64 time=1.846 ms
64 bytes from 192.168.0.9: seq=1 ttl=64 time=1.219 ms
64 bytes from 192.168.0.9: seq=2 ttl=64 time=0.961 ms
64 bytes from 192.168.0.9: seq=3 ttl=64 time=1.018 ms
64 bytes from 192.168.0.9: seq=4 ttl=64 time=1.046 ms
^C
--- 192.168.0.9 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 0.961/1.218/1.846 ms

可以看到网络1正常。
下面验证eth2,

root@fetmx6ull-s:~# ifconfig eth1 192.168.0.200 up
root@fetmx6ull-s:~# ifconfig eth0 down
root@fetmx6ull-s:~# ifconfig
eth1      Link encap:Ethernet  HWaddr EE:BB:DD:EE:FF:DD  
          inet addr:192.168.0.200  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::ecbb:ddff:feee:ffdd%1995609808/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:309 errors:0 dropped:0 overruns:0 frame:0
          TX packets:54 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:34953 (34.1 KiB)  TX bytes:9709 (9.4 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1%1995609808/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
root@fetmx6ull-s:~# ping 192.168.0.9
PING 192.168.0.9 (192.168.0.9): 56 data bytes
64 bytes from 192.168.0.9: seq=0 ttl=64 time=2.010 ms
64 bytes from 192.168.0.9: seq=1 ttl=64 time=1.030 ms
64 bytes from 192.168.0.9: seq=2 ttl=64 time=0.945 ms

可见,网络2也是正常的。
注意:以上的验证都是单网络,下面我们网络都放开。
这个时候会发现,2个网络只能一个网络能ping通主机地址。
反过来验证,我们将网线插入eth1,分别ping上面设置的ip地址,100,200发现都能ping通。
将网线插入eth0,分别ping上面设置的ip地址,100,200发现都不能ping通。那这个有时什么原因,我们从电脑上输入以下指令

[C:\~]$ arp -a

接口: 192.168.205.1 --- 0x7
  Internet 地址         物理地址              类型
  192.168.205.255       ff-ff-ff-ff-ff-ff     静态        
  224.0.0.22            01-00-5e-00-00-16     静态        
  224.0.0.251           01-00-5e-00-00-fb     静态        
  224.0.0.252           01-00-5e-00-00-fc     静态        
  239.255.255.250       01-00-5e-7f-ff-fa     静态        

接口: 192.168.0.9 --- 0x8
  Internet 地址         物理地址              类型
  192.168.0.100         ee-bb-dd-ee-ff-dd     动态        
  192.168.0.200         ee-bb-dd-ee-ff-dd     动态        
  192.168.0.255         ff-ff-ff-ff-ff-ff     静态        

从这里看到,192.168.1.100 和192.168.0.200对应的物理地址都是 ee-bb-dd-ee-ff-dd ,是相同的,我们在看开发板的mac地址。

root@fetmx6ull-s:~# ifconfig 
eth0      Link encap:Ethernet  HWaddr AA:CC:DD:EE:FF:DD  
          inet addr:192.168.0.100  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::a8cc:ddff:feee:ffdd%1996031696/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:770 errors:0 dropped:0 overruns:0 frame:0
          TX packets:72 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:97890 (95.5 KiB)  TX bytes:13251 (12.9 KiB)

eth1      Link encap:Ethernet  HWaddr EE:BB:DD:EE:FF:DD  
          inet addr:192.168.0.200  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::ecbb:ddff:feee:ffdd%1996031696/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:489 errors:0 dropped:0 overruns:0 frame:0
          TX packets:72 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:59731 (58.3 KiB)  TX bytes:11221 (10.9 KiB)

发现这个地址是eth1的地址,这也是解释通了,不论ping100还是200,实际上网络数据都是从eth1出去的,eth0是不能联通的。这个现象的解释可以这样来理解,在linux系统中,所有皆为文件,linux系统的路由表也是一个文件,路由表中一般都是没有最后一个ip地址的。如

root@fetmx6ull-s:~# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.0     *               255.255.255.0   U     0      0        0 eth1
192.168.0.0     *               255.255.255.0   U     0      0        0 eth0

所以,在linux系统中路由表不论是0.100,还是0.200都是相同的,那么既然相同就相当于是一条记录,当系统扫描路由表的时候,就先入为主,将所有的数据都从你先设置的mac地址作为数据输入输出通道。这就解释的通了。

所以最后的结论,当使用linux或者嵌入式linux系统的时候,多个网口要设定到不同的网段,这样才是可靠的。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

six2me

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值