linux pppd-GPRS和以太网同时在线,解决拨号默认网关

问题分析:

      linux 系统下pppd-GPRS和以太网同时在线,当以太网配置网关,将导致pppd拨号之后不能使用获取到默认网关,会使用以太网配置的网关,将导致pppd-gprs无法联网,提示信息如下:

not replacing existing default route via 192.168.1.1
解决方式:
       创建脚本/etc/ppp/ip-pre-up,内容如下:
#!/bin/sh
/sbin/route del default
设置脚本为可执行chmod a+x /etc/ppp/ip-pre-up。
重启终端,可实现双网在线。

-------------------------------------------------------------------------------------------------------

       上面的处理会存在一些问题,如果以太网配置了网关,GPRS会把以太网的默认网关删掉,将导致以太网无法联网,所以在上面的基础上需要再添加一些处理机制,具体处理情况如下

先贴出具体的处理方法:

1. 添加网关信息
route add default gw 192.168.1.1 eth0

2. 添加路由信息
route add -net 192.168.1.0/24 gw 192.168.1.1 eth0  #当终端和电脑直连的时候,因涉及到网关,无法ping通,这个时候需要将网关设置成192.168.1.100(这个是电脑的IP)

问题分析及处理方式:在实际使用时,以太网和GPRS是同时使用的,由于以太网联网速度比GPRS快,如果以太网配置了网关,在使用上面的第一点的方式设置默认网关,将出现如下的联网信息,

[root@szclou /]#route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.100   0.0.0.0         UG    0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
[root@szclou /]#route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.100   0.0.0.0         UG    0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

此时GPRS联网不删除以太网设置的默认网关,将导致GPRS联网失败(GPRS网关为基站分配,为0.0.0.0),无法联网;如果在GPRS在联网的过程中删除了以太网默认网关,这将导致以太网断网(它的默认网关被删除)。所以,现在的处理方式是,以太网存在网关时按照上面第2点添加路由信息(而不是添加默认网关),不过这里又会把添加路由信息里的网关设置为默认网关,所以在GPRS联网把默认路由网关删掉即可,而此时以太网也不会断网,因为它有自己的路由信息。

#以太网联网、GPRS未联网的情况

[root@szclou /]#route -ne
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.100   0.0.0.0         UG        0 0          0 eth0
10.0.0.1        0.0.0.0         255.255.255.255 UH        0 0          0 ppp0
192.168.1.0     192.168.1.100   255.255.255.0   UG        0 0          0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
[root@szclou /]#route -ne
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         0.0.0.0         0.0.0.0         U         0 0          0 ppp0
10.0.0.1        0.0.0.0         255.255.255.255 UH        0 0          0 ppp0
192.168.1.0     192.168.1.100   255.255.255.0   UG        0 0          0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0

#以太网联网、GPRS联网的情况(GPRS把以太网的默认网关删除了)

[root@szclou /]#route 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         *               0.0.0.0         U     0      0        0 ppp0
10.0.0.1        *               255.255.255.255 UH    0      0        0 ppp0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
[root@szclou /]#route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         0.0.0.0         0.0.0.0         U     0      0        0 ppp0
10.0.0.1        0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

#以太网联网、GPRS联网的情况(GPRS未把以太网的默认网关删除,ppp将输出如下信息“not replacing existing default route”)

[root@szclou /]#route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.100   0.0.0.0         UG    0      0        0 eth0
10.0.0.1        *               255.255.255.255 UH    0      0        0 ppp0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
[root@szclou /]#route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.100   0.0.0.0         UG    0      0        0 eth0
10.0.0.1        0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
#以太网联网(采样上面的第2点配置路由信息)、GPRS联网(不需要删除默认网关,因为按照第2点配置就不会有默认网关了)
[root@szclou /]#route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         *               0.0.0.0         U     0      0        0 ppp0
10.0.0.1        *               255.255.255.255 UH    0      0        0 ppp0
192.168.1.0     192.168.1.100   255.255.255.0   UG    0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
[root@szclou /]#route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         0.0.0.0         0.0.0.0         U     0      0        0 ppp0
10.0.0.1        0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
192.168.1.0     192.168.1.100   255.255.255.0   UG    0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值