/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 連結建立時需要完成的任何功能.