需求
- 物联网网关操作系统:Debian 8.3.0;
- 主板自带两个网口,IP分别为192.168.50.51(eth1)、192.168.50.52(eth0);网关为192.168.50.254;
- 要求:物联网两个网口与2台设备(192.168.50.129)可以同时通信。
问题
目前的情况为:
- 使用路由表如下:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.50.254 0.0.0.0 UG 0 0 0 eth1
192.168.50.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.50.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
eth1能Ping通192.168.50.129,eth0不能192.168.50.129; 192.168.50.129可以同时Ping通192.168.50.51(eth1)、192.168.50.52(eth0), 但拔掉eth1网线,则都无法Ping通
- 搜索网络资料 linux下双网卡能不能设置同一网段?[1],按照以下操作
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.eth0.arp_announce = 2
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.eth1.arp_announce = 2
net.ipv4.conf.eth1.arp_ignore = 1
作者:袁昊洋
链接:https://www.zhihu.com/question/41331151/answer/169574975
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
eth1能Ping通192.168.50.129,eth0不能192.168.50.129; 192.168.50.129可以能Ping通192.168.50.51(eth1),无法Ping通192.168.50.52(eth0)
- 查找多路由表相关资料
ip route add 192.168.50.0/24 dev eth0 src 192.168.50.51 table eth0table
ip route add 192.168.50.0/24 dev eth1 src 192.168.50.52 table eth1table
ip route add default dev eth0 via 192.168.50.254 table eth0table
ip route add default dev eth1 via 192.168.50.254 table eth1table
ip rule add from 192.168.50.51 table eth0table
ip rule add from 192.168.50.52 table eth1table
在执行此指令后
ip rule add from 192.168.50.51 table eth0table
系统报错误
RTNETLINK answers: Operation not supported
查找相关ip rule资料,4.8. Routing Tables[2],需要内核开启 CONFIG_IP_MULTIPLE_TABLES=y配置;查看内核配置文件
zcat /proc/config.gz
输出:
#
# Automatically generated file; DO NOT EDIT.
# Linux/arm64 4.19.59 Kernel Configuration
#
...
# CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET is not set
# CONFIG_DEBUG_WX is not set
# CONFIG_DEBUG_ALIGN_RODATA is not set
# CONFIG_ARM64_RELOC_TEST is not set
# CONFIG_CORESIGHT is not set
...
没有 CONFIG_IP_MULTIPLE_TABLES配置项,若要开启需要编译内核,工作量较大,不再尝试
解决办法
一个不是办法的办法
不将两个网口配置为同一网段,在设备与网关间加交换机,同时使网关与设备在同一网络,搞定!
相关资料
[1] https://www.zhihu.com/question/41331151
[2] http://linux-ip.net/html/routing-tables.html