Linux 版 (精华区)

发信人: clx (楚留香), 信区: Unix
标  题: PPP HOWTO 中译版(24)
发信站: 紫 丁 香 (Sat Jun 27 17:05:21 1998), 转信

PPP HOWTO 中译版 : 建立连结之後 - /etc/ppp/ip-up 指令稿
Previous: 使用 PPP 连结两个网路
Next: 使用 /etc/ppp/ip-down 


23. 建立连结之後 - /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 读取及执行. 

23.1. 特殊递送路径

如果你连结的是两个区域网路,你将得设立一个到 '外面的' 区域
网路的指定递送路径. 这可以很容易的使用 /etc/ppp/ip-up 指令稿
达成.唯一的困难发生在你的机器有多个 PPP 连结时.

这是因为 /etc/ppp/ip-up 这个指令稿是由每一个起动的 ppp 连线所
执行的,所以你得要小心地为每一个起动的连结执行正确的递送指
令!

23.2. 处理电子邮件伫列

当两个区域网路的连结建立之後,你可能想要确定放在伫列中的电
子邮件被清出 - 送到它的目的地. 这可以用适当的呼叫 sendmail
来达成. 

在 pppd 传递给指令稿的特定参数上使用 bash 的 `case' 叙述来
完成这个工作. 例如,这是我用来处理我们的广域网路连结及通往
我家乙太网路的(也是由相同的 PPP 伺服器处理)/etc/ppp/ip-up 指
令稿.

23.3. 一个 /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



23.4. 处理电子邮件

上一节提及如何处理外送的邮件 - 一旦连线建立之後简单地藉由
清出邮件伫列达成.

如果你执行连往广域网路的连结,你可以跟远端区域网路的网路管
理者协调请它们执行完全相同的动作. 例如,在我们的广域网路连
结中 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 连结建立时需要完成的任
何功能.


PPP HOWTO 中译版 : 建立连结之後 - /etc/ppp/ip-up 指令稿
Previous: 使用 PPP 连结两个网路
Next: 使用 /etc/ppp/ip-down 

--
※ 来源:.紫 丁 香 bbs.hit.edu.cn.[FROM: 202.118.244.16]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.215毫秒