/etc/ppp/ip-up 脚本文件一旦 PPP 连结建立後, pppd 会找寻 /etc/ppp/ip-up 脚本文件.
如果这个脚本文件存在并且可以执行的话,那么 PPP 服务程序就会执行这个脚本文件.
这允许你自动执行任何可能有必要的特殊递送路径指令及任何你想在每次 PPP 连结启动时执行的动作.
这不过就是一般普通的 shell 脚本文件,可以做任何脚本文件能做的事(也就是,任何你想做的事).
例如,你可能想要 sendmail 赶快处理在邮件队列中等待外送的讯息.
类似地,你可以在 ip-up 里插入一些指令取得(使用 POP)在你的 ISP 那边等著你的任何电子邮件.
不过在 /etc/ppp/ip-up 也有些限制:-
/etc/ppp/ip-up 是一个程序而非脚本文件.
这是说它可以被直接执行 - 也因此它在第一行开始必须具有标准的 file magic (#!/bin/bash) 并且能被 root 读取及执行.
如果你连结的是两个局烛网,你将得设立一个到 '外面的' 局烛网的指定递送路径.
这可以很容易的使用 /etc/ppp/ip-up 脚本文件达成.唯一的困难发生在你的机器有多个 PPP 连结时.
这是因为 /etc/ppp/ip-up 这个脚本文件是由每一个起动的 ppp 连线所执行的,所以你得要小心地为每一个起动的连结执行正确的递送指令!
当两个局烛网的连结建立之后,你可能想要确定放在队列中的电子邮件被清出 - 送到它的目的地.
这可以用适当的调用 sendmail 来达成.
在 pppd 传递给脚本文件的特定参数上使用 bash 的 `case' 叙述来完成这个工作.
例如,这是我用来处理我们的广域网络连结及通往我家以太网络的(也是由相同的 PPP 服务器处理)/etc/ppp/ip-up 脚本文件.
/etc/ppp/ip-up 脚本文件的例子
下面的例子提供不同的使用范例.
#!/bin/bash
#
# Script which handles the routing issues as necessary for pppd
# Only the link to Newman requires this handling.
#
# When the ppp link comes up, this script is called with the following
# parameters
# $1 the interface name used by pppd (e.g. ppp3)
# $2 the tty device name
# $3 the tty device speed
# $4 the local IP address for the interface
# $5 the remote IP address
# $6 the parameter specified by the 'ipparam' option to pppd
#
case "$5" in
# Handle the routing to the Newman Campus server
202.12.126.1)
/sbin/route add -net 202.12.126.0 gw 202.12.126.1
# and flush the mail queue to get their email there asap!
/usr/sbin/sendmail -q &
;;
139.130.177.2)
# Our Internet link
# When the link comes up, start the time server and synchronise to the world
# provided it is not already running
if [ ! -f /var/lock/subsys/xntpd ]; then
/etc/rc.d/init.d/xntpd.init start &
fi
# Start the news server (if not already running)
if [ ! -f /var/lock/subsys/news ]; then
/etc/rc.d/init.d/news start &
fi
;;
203.18.8.104)
# Get the email down to my home machine as soon as the link comes up
# No routing is required as my home Ethernet is handled by IP
# masquerade and proxyarp routing.
/usr/sbin/sendmail -q &
;;
*)
esac
exit 0
起动通往我们 Newman 校园的 ppp 连结以及这个脚本文件的结果,我们最后得到下面这个递送表格记录(这台机器也是我们通常用的 PPP 服务器并且处理我们的互联网连结). 我已经在这个输出里加入一些注解以解释每个项目是什么:
[root@kepler /root]# route -n Kernel routing table Destination Gateway Genmask Flags MSS Window Use Iface # the HOST route to our remote internet gateway 139.130.177.2 * 255.255.255.255 UH 1500 0 134 ppp4 # the HOST route to our Newman campus server 202.12.126.1 * 255.255.255.255 UH 1500 0 82 ppp5 # the HOST route to my home ethernet 203.18.8.104 * 255.255.255.255 UH 1500 0 74 ppp3 # two of our general dial up PPP lines 203.18.8.64 * 255.255.255.255 UH 552 0 0 ppp2 203.18.8.62 * 255.255.255.255 UH 552 0 1 ppp1 # the specific network route to the Newman campus LAN 202.12.126.0 202.12.126.1 255.255.255.0 UG 1500 0 0 ppp5 # the route to our local Ethernet (super-netting two adjacent C classes) 203.18.8.0 * 255.255.254.0 U 1500 0 1683 eth0 # the route to the loop back device 127.0.0.0 * 255.0.0.0 U 3584 0 483 lo # the default route to the Internet default 139.130.177.2 * UG 1500 0 3633 ppp4
上一节提及如何处理外送的邮件 - 一旦连线建立之后简单地藉由清出邮件队列达成.
如果你执行连往广域网络的连结,你可以跟远程局烛网的网络管理者协调请它们执行完全相同的动作.
例如,在我们的广域网络连结中 Newman 校园那一端的 /etc/ppp/ip-up 脚本文件看起来像:
#!/bin/bash
#
# Script which handles the routing issues as necessary for pppd
# Only the link to Hedland requires this handling.
#
# When the ppp link comes up, this script is called with the following
# parameters
# $1 the interface name used by pppd (e.g. ppp3)
# $2 the tty device name
# $3 the tty device speed
# $4 the local IP address for the interface
# $5 the remote IP address
# $6 the parameter specified by the 'ipparam' option to pppd
#
case "$5" in
203.18.8.4)
/usr/sbin/sendmail -q
;;
*)
esac
exit 0
然而如果你只能使用动态 IP 号码方式的 PPP 连线连往你的 ISP,你得从在你 ISP 机器上的帐号取得你的电子邮件.
这通常是使用 POP(Post Office Protocol)协议来达成的.可以使用 `popclient' 程序处理这个程序 - 而 ip-up 脚本文件也可以为你自动化这个程序.
简单地建立一个 /etc/ppp/ip-up 脚本文件,其中包含有起动 popclient 程序的适当指令.
在我执行 Red Hat Linux 的膝上型计算机上(任何旅行时我都带著它)是这样的
popclient -3 -c -u hartr -p <password> kepler.hedland.edu.au |formail -s procmail
你可以使用 slurp 或其它软件以相同的方式取得网络新闻,以及诸如此类的服务. 记得,ip-up 这个脚本文件只是个标准的 bash 脚本文件因此可以用来自动化当每次适当的 PPP 连结建立时需要完成的任何功能.