-1

我在一个 Arch Linux 机器上,通过 3G USB 记忆棒 (ttyUSB0) 使用工作 ETH0(固定 IP)和 PPP 连接。重启后,ETH0 工作正常。建立 PPP 连接也可以正常工作。但是在使用 'poff' 取消 PPP 连接后,我没有再次获得默认路由。我知道如何手动设置默认路由,但是由于 linux 机器将在各种网络中注册,我必须找到一个在使用 PPP 连接后自动获取默认路由的过程。

ETH0 在 /etc/conf.d/net-conf-eth0 中配置:

address   = 10.0.1.30
netmask   = 24
broadcast = 10.0.1.255
gateway   = 10.0.1.1

PPP是使用设置的

pacman -S ppp

...以及以下配置文件:

/etc/ppp/ip-pre-up

#!/bin/sh
/usr/bin/route del default

/etc/ppp/options-mobile

ttyUSB0
921600
lock
crtscts
modem
passive
novj
defaultroute
noipdefault
usepeerdns
noauth
hide-password
persist
holdoff 10
maxfail 0
debug

PPP连接的路由表:

# route
Kernel IP routing table
Destination     Gateway        Genmask         Flags Metric Ref    Use Iface
default         router.intern  0.0.0.0         UG    0      0        0 eth0
default         router.intern  0.0.0.0         UG    1024   0        0 eth0
10.0.1.0       *               255.255.255.0   U     0      0        0 eth0
router.intern  *               255.255.255.255 UH    1024   0        0 eth0

PPP连接成功的路由表:

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.1.0        *               255.255.255.0   U     0      0        0 eth0
router.intern   *               255.255.255.255 UH    1024   0        0 eth0

我错过了什么?

4

1 回答 1

0

回答我自己的问题: /etc/ppp/ip-down 是线索。(我试图在 /etc/ppp/ip-down.d/ 中放置一个脚本,但有时它不会被执行。ip-down 太早从 pppd 获取 SIGTERM。)所以我修改了 /etc/ppp/ip -向下:

!/bin/sh
#
# This script is run by pppd after the connection has ended.
#

ETH_Gateway=$(/usr/bin/cat /etc/conf.d/net-conf-eth0 | /usr/bin/grep 'gateway' | /usr/bin/grep -oE '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+')
/usr/bin/route del default
/usr/bin/ip route add default via $ETH_Gateway

# Execute all scripts in /etc/ppp/ip-down.d/
for ipdown in /etc/ppp/ip-down.d/*.sh; do
  if [ -x $ipdown ]; then
    # Parameters: interface-name tty-device speed local-IP-address remote-IP-address ipparam
    $ipdown "$@"
  fi
done
于 2015-06-02T00:00:58.097 回答