編輯 /etc/rc.conf
加入以下內容,讓ADSL撥接後也能當NAT
gateway_enable="YES"
ppp_enable="YES"
ppp_mode="ddial"
ppp_profile="hinet"
ppp_nat="YES"
ppp_enable="YES"
ppp_mode="ddial"
ppp_profile="hinet"
ppp_nat="YES"
編輯 /etc/ppp/ppp.conf
hinet:
set device PPPoE:bge0:
set mru 1492
set mtu 1492
set speed sync
enable lqr
set lqrperiod 5
set cd 5
set dial
set login
set timeout 0
set authname 87654321@ip.hinet.net <--你的帳號
set authkey 2axuliar <--你的密碼
#set ifaddr 10.200.0.254/0 255.255.0.0 0.0.0.0
add default HISADDR
enable dns
set device PPPoE:bge0:
set mru 1492
set mtu 1492
set speed sync
enable lqr
set lqrperiod 5
set cd 5
set dial
set login
set timeout 0
set authname 87654321@ip.hinet.net <--你的帳號
set authkey 2axuliar <--你的密碼
#set ifaddr 10.200.0.254/0 255.255.0.0 0.0.0.0
add default HISADDR
enable dns
這個撥接我取名叫「hinet」,注意除了第一行 hinet: 外,其餘行前都得要有一個空白,否則會出錯:
Warning: Bad label in /etc/ppp/ppp.conf (line xx) - missing colon
操作指令
撥接
'hinet' 是我設定的撥接名稱
# ppp -nat -ddial hinet
或
# /etc/rc.d/ppp start
中斷連線
tun0是因為撥接產生的介面,可下ifconfig來查看
# kill `cat /var/run/tun0.pid`
或是
# /etc/rc.d/ppp stop
斷線及重連
後來發現 ppp 真的滿容易自動斷線,所以參考別人的資料自己寫了一個SHELL定時檢查,
# vi /root/check_ppp.sh
#!/bin/sh
# 請務必先裝 fping
checkonline2=`/usr/local/sbin/fping 168.95.1.1`
if [ "$checkonline2" = "168.95.1.1 is alive" ] ; then
echo "$checkonline2"
echo "The ADSL is connected"
exit
else
echo "$checkonline2"
echo "The ADSL is disconnected"
curr_day=`/bin/date +%Y%m%d_%H%M%S`
# 寫入記錄檔
echo "$curr_day PPP Reconnection" >> /var/log/ppp.reconn.log
/etc/rc.d/ppp stop
sleep 5 #等5秒
/etc/rc.d/ppp start
fi
# 請務必先裝 fping
checkonline2=`/usr/local/sbin/fping 168.95.1.1`
if [ "$checkonline2" = "168.95.1.1 is alive" ] ; then
echo "$checkonline2"
echo "The ADSL is connected"
exit
else
echo "$checkonline2"
echo "The ADSL is disconnected"
curr_day=`/bin/date +%Y%m%d_%H%M%S`
# 寫入記錄檔
echo "$curr_day PPP Reconnection" >> /var/log/ppp.reconn.log
/etc/rc.d/ppp stop
sleep 5 #等5秒
/etc/rc.d/ppp start
fi
修改為可執行
# chmod 711 /root/check_ppp.sh
先測試
# /root/check_ppp.sh
168.95.1.1 is alive
The ADSL is connected
這個SHELL得先裝 fping
# /usr/ports/net/fping
# make install clean
# make install clean
接著使用排程每五分鐘測試一次
*/5 * * * * /root/check_ppp.sh
參考資料
[1] http://redhat.ecenter.idv.tw/bbs/showthread.php?postid=190438
編修 2009-10-07 01:48:52