pppoe服务相关的命令包括:
- adsl-start。该脚本主要功能是pppoe服务启动脚本。
- adsl-stop。该脚本主要功能是pppoe服务停止脚本,并恢复默认路由。
- adsl-connect。该脚本主要功能是和pppoe协议执行脚本。
- adsl-status。该脚本主要功能是查看pppoe状态。
pppoe服务相关的文件包括:
- chap-secrets。chap认证的用户名和密码。
- pap-secrets。pap认证的用户名和密码。
- pppoe.conf。端口配置信息。
另外,pppoe不会自动配置默认路由,所以需要修改脚本。
最简单的修改方法就是pppoe启动前,先保存原来的默认路由,pppoe停止后,回复原来的默认路由。
或者,pppoe启动时,根据端口名称来配置默认路由,pppoe停止后,再取消启动时配置的默认路由。
默认情况下,使用/etc/ppp/pppoe.conf配置文件:
开启pppoe服务的命令:adsl-start 。
关闭pppoe服务的命令:adsl-stop。
若使用其他配置文件,例如/etc/ppp/pppoe-eth0.conf ,则
adsl-start /etc/ppp/pppoe-eth0.conf
adsl-stop /etc/ppp/pppoe-eth0.conf
下面分析用到的脚本。
adsl-start脚本:
#! /bin/bash
# Generated automatically from adsl-start.in by configure.
#***********************************************************************
#
# adsl-start
#
# Shell script to bring up an ADSL connection
#
# Copyright (C) 2000 Roaring Penguin Software Inc.
#
# $Id: adsl-start.in,v 1.7 2001/06/25 15:00:47 dfs Exp $
#
# This file may be distributed under the terms of the GNU General
# Public License.
#
# Usage: adsl-start [config_file]
# adsl-start interface user [config_file]
# Second form overrides USER and ETH from config file.
# If config_file is omitted, defaults to /etc/ppp/pppoe.conf
#
#***********************************************************************
# From AUTOCONF
prefix=/usr
exec_prefix=/usr
# Paths to programs
CONNECT=/usr/sbin/adsl-connect
ECHO=/bin/echo
IP=/sbin/ip
LS=/bin/ls
NETWORKDIR=/etc/sysconfig/network-scripts
get_device() {
if [ ! -d $NETWORKDIR ] ; then
$ECHO "** $NETWORKDIR not found"
$ECHO "** Quitting"
exit 1
fi
cd $NETWORKDIR
interfaces=$($LS ifcfg-ppp* 2>/dev/null | egrep -v '(~|\.bak)$' | \
egrep -v '(rpmsave|rpmorig|rpmnew)' | sed 's/^ifcfg-//g')
for i in $interfaces ; do
test -f ifcfg-$i && . ifcfg-$i 2>/dev/null
if [ "$TYPE" = "xDSL" ] ; then
CONFIG=$NETWORKDIR/ifcfg-$i
break
fi
done
}
# Set to "C" locale so we can parse messages from commands
LANG=C
export LANG
# Defaults
USER=""
ETH=""
ME=`basename $0`
# Must be root
if [ "`/usr/bin/id -u`" != 0 ] ; then
[ "$DEBUG" = "1" ] && $ECHO "$ME: You must be root to run this script" >& 2
exit 1
fi
# Debugging
if [ "$DEBUG" = "1" ] ; then
$ECHO "*** Running in debug mode... please be patient..."
DEBUG=`mktemp -d /tmp/pppoe-debug-XXXXXXXX`
if [ $? -ne 0 ] ; then
$ECHO "Could not create directory $DEBUG... exiting"
exit 1
fi
export DEBUG
DEBUG=$DEBUG/pppoe-debug.txt
# Initial debug output
$ECHO "---------------------------------------------" > $DEBUG
$ECHO "* The following section contains information about your system" >> $DEBUG
date >> $DEBUG
$ECHO "Output of uname -a" >> $DEBUG
uname -a >> $DEBUG
$ECHO "---------------------------------------------" >> $DEBUG
$ECHO "* The following section contains information about your network" >> $DEBUG
$ECHO "* interfaces. The one you chose for PPPoE should contain the words:" >> $DEBUG
$ECHO "* 'UP' and 'RUNNING'. If it does not, you probably have an Ethernet" >> $DEBUG
$ECHO "* driver problem." >> $DEBUG
$ECHO "Output of ip addr show" >> $DEBUG
$IP addr show >> $DEBUG
$ECHO "---------------------------------------------" >> $DEBUG
if [ "`uname -s`" = "Linux" ] ; then
$ECHO "* The following section contains information about kernel modules" >> $DEBUG
$ECHO "* If the module for your Ethernet card is 'tulip', you might" >> $DEBUG
$ECHO "* want to look for an updated version at http://www.scyld.com" >> $DEBUG
$ECHO "Output of lsmod" >> $DEBUG
lsmod >> $DEBUG
$ECHO "---------------------------------------------" >> $DEBUG
fi
$ECHO "* The following section lists your routing table." >> $DEBUG
$ECHO "* If you have an entry which starts with '0.0.0.0', you probably" >> $DEBUG
$ECHO "* have defined a default route and gateway, and pppd will" >> $DEBUG
$ECHO "* not create a default route using your ISP. Try getting" >> $DEBUG
$ECHO "* rid of this route." >> $DEBUG
$ECHO "Output of netstat -n -r" >> $DEBUG
netstat -n -r >> $DEBUG
$ECHO "---------------------------------------------" >> $DEBUG
$ECHO "Contents of /etc/resolv.conf" >> $DEBUG
$ECHO "* The following section lists DNS setup." >> $DEBUG
$ECHO "* If you can browse by IP address, but not name, suspect" >> $DEBUG
$ECHO "* a DNS problem." >> $DEBUG
cat /etc/resolv.conf >> $DEBUG
$ECHO "---------------------------------------------" >> $DEBUG
$ECHO "* The following section lists /etc/ppp/options." >> $DEBUG
$ECHO "* You should have NOTHING in that file." >> $DEBUG
$ECHO "Contents of /etc/ppp/options" >> $DEBUG
cat /etc/ppp/options >> $DEBUG 2>/dev/null
$ECHO "---------------------------------------------" >> $DEBUG
DEBUG="1"
fi
# Sort out command-line arguments
case "$#" in
1)
CONFIG="$1"
;;
3)
CONFIG="$3"
;;
esac
if [ -z "$CONFIG" ] ; then
get_device
[ -z "$CONFIG" ] && CONFIG=/etc/ppp/pppoe.conf
fi
if [ ! -f "$CONFIG" -o ! -r "$CONFIG" ] ; then
[ "$DEBUG" = "1" ] && $ECHO "$ME: Cannot read configuration file '$CONFIG'" >& 2
exit 1
fi
. $CONFIG
# Check for command-line overriding of ETH and USER
case "$#" in
2|3)
ETH="$1"
USER="$2"
;;
esac
# Check for pidfile
if [ -r "$PIDFILE" ] ; then
PID=`cat "$PIDFILE"`