问题现象
产品有两个网口,eth0跟 eth1 初始分别设为1网段跟2网段。如下:
现场将eth0 设为2网段,eth2 设为其他网段,eth0 路由查找失败,网络工作异常。(设备无法跨网关工作)
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 * 255.255.255.0 U 0 0 0 eth0
192.168.40.0 * 255.255.255.0 U 0 0 0 eth1
default 192.168.40.1 0.0.0.0 UG 0 0 0 eth1
问题分析
经测试发现, 只有eth0 设置2网段存在问题,其他网段都正常,如1网段route信息:
[root@M28x ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
192.168.40.0 * 255.255.255.0 U 0 0 0 eth1
default 192.168.40.1 0.0.0.0 UG 0 0 0 eth1
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
设备修改IP有两种方法:
1、vi /etc/init.d/S40network
ifconfig eth0 “192.168.1.136” netmask 255.255.255.0
ifconfig eth1 “192.168.2.136” netmask 255.255.255.0
ifconfig eth0 up
ifconfig eth1 up
设备未加载应用程序时, 出厂IP设置采用此方法。
2、vi /opt/nts/setnet.sh
#! /bin/sh
ifconfig eth0 192.168.2.202 netmask 255.255.255.0
route add default gw 192.168.2.1
ifconfig eth0 up
ifconfig eth1 192.168.40.212 netmask 255.255.255.0
route add default gw 192.168.40.1
ifconfig eth1 up
设备启动完成后,通过改方法设置IP。
这里先修改eth0 到2网段, 此时eth1还在2网段。eth0的gw设置无效。
为了使得eth0 设置2网段成功,需要步骤1把eth1的网段调整到其他网段。
ifconfig eth0 “192.168.1.136” netmask 255.255.255.0
ifconfig eth1 “192.168.20.136” netmask 255.255.255.0
ifconfig eth0 up
ifconfig eth1 up
reg=/root/net_phy_rw eth0 0 | awk '{print $9}'
if [ $reg = “0x2100” ]; then
/root/net_phy_rw eth0 0 0x800 >/dev/null
/root/net_phy_rw eth0 0 0x2100 >/dev/null
fi
reg=/root/net_phy_rw eth1 0 | awk '{print $9}'
if [ $reg = “0x2100” ]; then
/root/net_phy_rw eth1 0 0x800 >/dev/null
/root/net_phy_rw eth1 0 0x2100 >/dev/null
fi
#闃叉eth0鑷姩鏂紑
#ping 192.168.1.1 >/dev/null &
#闃叉eth1鑷姩鏂紑
#ping 192.168.20.1 >/dev/null &
修改保存后, route正常。
[root@M28x ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 * 255.255.255.0 U 0 0 0 eth0
192.168.40.0 * 255.255.255.0 U 0 0 0 eth1
default 192.168.40.1 0.0.0.0 UG 0 0 0 eth1
default 192.168.2.1 0.0.0.0 UG 0 0 0 eth0
尝试方法2
先修改eth1 再修改 eth0
恢复S40network参数设置,修改setnet.sh如下:
vi /opt/nts/setnet.sh
[root@M28x ~]# vi /opt/nts/setnet.sh
#! /bin/sh
ifconfig eth1 192.168.40.0 netmask 255.255.255.0
route add default gw 192.168.40.1
ifconfig eth1 up
ifconfig eth0 192.168.2.212 netmask 255.255.255.0
route add default gw 192.168.2.1
ifconfig eth0 up
~
重启,执行route:
[root@M28x ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 * 255.255.255.0 U 0 0 0 eth0
192.168.40.0 * 255.255.255.0 U 0 0 0 eth1
default 192.168.2.1 0.0.0.0 UG 0 0 0 eth0
default 192.168.40.1 0.0.0.0 UG 0 0 0 eth1
route 设置成功。
解决方法:
1、修改S40network,将eth1 改到2以外网段。
2、修改setnet.sh 先设置eth1,再设置eth0
总结建议:
双网口进行参数设置时,需深入了解双网口的参数设置要求。