ETH0 GW 设置 无效分析

问题现象

产品有两个网口,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

总结建议:

双网口进行参数设置时,需深入了解双网口的参数设置要求。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值