linux下pppoe脚本分析!
2016-02-20 12:01
736 查看
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脚本:
adsl-connect脚本:
adsl-stop脚本:
pppoe.conf文件:
若是指定接口eth0启动pppoe时,需要修改pppoe.conf文件为:
chap-secrets文件:
pap-secrets文件:
- 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"` # Check if still running kill -0 $PID > /dev/null 2>&1 if [ $? = 0 ] ; then [ "$DEBUG" = "1" ] && $ECHO "$ME: There already seems to be an ADSL connection up (PID $PID)" >& 2 exit 1 fi # Delete bogus PIDFILE rm -f "$PIDFILE" "$PIDFILE.pppd" "$PIDFILE.pppoe" "$PIDFILE.start" fi echo $$ > $PIDFILE.start #将adsl-start的进程号保存到$PIDFILE.start文件 # Start the connection in the background unless we're debugging if [ "$DEBUG" = "1" ] ; then $CONNECT "$@" exit 0 fi $CONNECT "$@" > /dev/null 2>&1 & #启动adsl-connect程序 CONNECT_PID=$! #保存adsl-connect程序的pid if [ "$CONNECT_TIMEOUT" = "" -o "$CONNECT_TIMEOUT" = 0 ] ; then exit 0 fi # Don't monitor connection if dial-on-demand if [ "$DEMAND" != "" -a "$DEMAND" != "no" ] ; then exit 0 fi # Monitor connection TIME=0 while [ true ] ; do /usr/sbin/adsl-status $CONFIG > /dev/null 2>&1 #监控时,通过adsl-status来检测 # Looks like the interface came up if [ $? = 0 ] ; then # Print newline if standard input is a TTY [ "$DEBUG" = "1" ] && tty -s && $ECHO " Connected!" cp -f /etc/ppp/resolv.conf /etc/ exit 0 #连接成功后,退出监控 fi if test -n "$FORCEPING" ; then [ "$DEBUG" = "1" ] && $ECHO -n "$FORCEPING" else [ "$DEBUG" = "1" ] && tty -s && $ECHO -n "$PING" fi sleep $CONNECT_POLL TIME=`expr $TIME + $CONNECT_POLL` if [ $TIME -gt $CONNECT_TIMEOUT ] ; then break #60s超时后退出监控。 fi done [ "$DEBUG" = "1" ] && $ECHO "TIMED OUT" >& 2 # Timed out! Kill the adsl-connect process and quit kill $CONNECT_PID > /dev/null 2>&1 #连接超时则将adsl-connect杀死 # Clean up PIDFILE(s) rm -f "$PIDFILE" "$PIDFILE.pppd" "$PIDFILE.pppoe" "$PIDFILE.start" #连接超时则删除所有pidfile文件 # add old default gw back #添加默认路由 if [ -s /etc/default-route ] ; then route add default gw `cat /etc/default-route` rm -f /etc/default-route fi exit 1
adsl-connect脚本:
#! /bin/bash # Generated automatically from adsl-connect.in by configure. #*********************************************************************** # # adsl-connect # # Shell script to connect to an ADSL provider using PPPoE # # Copyright (C) 2000 Roaring Penguin Software Inc. # # $Id: adsl-connect.in,v 1.17 2001/09/14 19:07:42 dfs Exp $ # # This file may be distributed under the terms of the GNU General # Public License. # # Usage: adsl-connect [config_file] # adsl-connect 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 localstatedir=/var # Paths to programs IP=/sbin/ip PPPD=/usr/sbin/pppd SETSID=/usr/bin/setsid PPPOE=/usr/sbin/pppoe BR2684CTL=/usr/sbin/br2684ctl LOGGER="/usr/bin/logger -t `basename $0`" NETWORKDIR=/etc/sysconfig/network-scripts LS=/bin/ls DEBUG=/var/log/pppoe.log 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 # Must be root if test "`/usr/bin/id -u`" != 0 ; then echo "$0: You must be root to run this script" >& 2 exit 1 fi if test "$SETSID" != "" -a ! -x "$SETSID"; then SETSID="" fi USER="" ETH="" # 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 test ! -f "$CONFIG" -o ! -r "$CONFIG" ; then echo "$0: Cannot read configuration file '$CONFIG'" >& 2 exit 1 fi . $CONFIG DEVNAME="$DEVICE" PPPOE_PIDFILE="$PIDFILE.pppoe" PPPD_PIDFILE="$PIDFILE" if [ "$CONFIG" != "/etc/ppp/pppoe.conf" ] ; then DEVNAME=`basename $CONFIG | sed 's/^ifcfg-//g'` #获取device名称,样式为:pppoe-port001.conf fi if [ -n "$BR2684DEV" ]; then [ -z "$ETH" ] && ETH="nas$BR2684DEV" modprobe br2684 > /dev/null 2>&1 fi # Check for command-line overriding of ETH and USER case "$#" in 2|3) ETH="$1" USER="$2" ;; esac # Check that config file is sane if test "$USER" = "" ; then echo "$0: Check '$CONFIG' -- no setting for USER" >& 2 exit 1 fi if test "`basename \"$LINUX_PLUGIN\"`" = "pppoatm.so" ; then if test "$VCI" = "" ; then echo "$0: Check '$CONFIG' -- no setting for VCI" >& 2 exit 1 fi if test "$VPI" = "" ; then echo "$0: Check '$CONFIG' -- no setting for VPI" >& 2 exit 1 fi else if test "$ETH" = "" ; then echo "$0: Check '$CONFIG' -- no setting for ETH" >& 2 exit 1 fi fi PPPD_PID=0 # Catch common error #若DEBUG=1,则不能使用adsl-connect,而是得用adsl-start if test "$DEBUG" = "1" ; then echo "*** If you want to use DEBUG, invoke adsl-start, not adsl-connect." exit 1 fi if test "$DEBUG" != "" ; then #DEBUG不等于1,也不等于空时,进入debug模式 if test "$LINUX_PLUGIN" != "" ; then echo "Cannot use DEBUG mode and LINUX_PLUGIN at the same time." echo "Kernel-mode PPPoE is experimental and unsupported." #若为LINUX_PLUGIN,退出 exit 1 fi echo "* The following section identifies your Ethernet interface" >> $DEBUG echo "* and user name. Some ISP's need 'username'; others" >> $DEBUG echo "* need 'username@isp.com'. Try both" >> $DEBUG echo "ETH=$ETH; USER=$USER" >> $DEBUG echo "---------------------------------------------" >> $DEBUG fi # MTU of Ethernet card attached to modem MUST be 1500. This apparently # fails on some *BSD's, so we'll only do it under Linux if test `uname -s` = Linux ; then #仅支持linux系统 $IP link set $ETH up mtu 1500 # For 2.4 kernels. Will fail on 2.2.x, but who cares? modprobe ppp_generic > /dev/null 2>&1 modprobe ppp_async > /dev/null 2>&1 modprobe ppp_synctty > /dev/null 2>&1 if test -n "$LINUX_PLUGIN" ; then modprobe pppox > /dev/null 2>&1 modprobe pppoe > /dev/null 2>&1 fi fi if test "$SYNCHRONOUS" = "yes" ; then #是否同步,默认脚本是no PPPOE_SYNC=-s PPPD_SYNC=sync # Increase the chances of it working on Linux... if test `uname -s` = Linux ; then modprobe n_hdlc > /dev/null 2>&1 fi else PPPOE_SYNC="" PPPD_SYNC="" fi if test -n "$ACNAME" ; then #默认脚本中不存在该字段 ACNAME="-C $ACNAME" fi if test -n "$SERVICENAME" ; then #默认脚本中不存在该字段 SERVICENAME="-S $SERVICENAME" fi if test "$CLAMPMSS" = "no" ; then CLAMPMSS="" else CLAMPMSS="-m $CLAMPMSS" fi # If DNSTYPE is SERVER, we must use "usepeerdns" option to pppd. if test "$DNSTYPE" = "SERVER" ; then PEERDNS=yes fi if test "$PEERDNS" = "yes" ; then #默认为yes PEERDNS="usepeerdns" else PEERDNS="" fi if [ -z "$DEVICE" ] ; then IPPARAM="" LINKNAME="" else IPPARAM="ipparam ${DEVNAME}" #ipparam pppoe-port002.conf。DEVICE值为ppp_port002 LINKNAME="linkname ${DEVICE}" #linkname ppp_port002 。DEVICE值为 fi [ -z "$MTU" ] && MTU="1492" [ -z "$MRU" ] && MRU="1492" # Backward config file compatibility if test "$DEMAND" = "" ; then DEMAND=no fi if test "$DEMAND" = "no" ; then #DEMAND默认为no DEMAND="" else [ -z "$IPADDR" ] && IPADDR=10.112.112.112 [ -z "$REMIP" ] && REMIP=10.112.112.113 DEMAND="demand persist idle $CONNECT_TIMEOUT $IPADDR:$REMIP ipcp-accept-remote ipcp-accept-local noipdefault ktune" # The plugin doesn't need (and may not _accept_) the 'connect' option if [ -z "$LINUX_PLUGIN" ]; then DEMAND="$DEMAND connect true" fi fi case "$FIREWALL" in STANDALONE) . /etc/ppp/firewall-standalone ;; MASQUERADE) . /etc/ppp/firewall-masq ;; esac # If we're using kernel-mode PPPoE on Linux... if test "`basename \"$LINUX_PLUGIN\"`" = "rp-pppoe.so" ; then PLUGIN_OPTS="plugin $LINUX_PLUGIN $ETH" modprobe pppoe > /dev/null 2>&1 fi # If we're using kernel-mode PPPoATM on Linux... if test "`basename \"$LINUX_PLUGIN\"`" = "pppoatm.so" ; then PLUGIN_OPTS="plugin $LINUX_PLUGIN" # Interface name MUST BE LAST!! PLUGIN_OPTS="$PLUGIN_OPTS $VPI.$VCI" modprobe pppoatm > /dev/null 2>&1 fi if test "$DEFROUTE" != "no" ; then DEFAULTROUTE="defaultroute" # pppd will no longer delete an existing default route # so we have to help it out a little here. DEFRT=`ip route list | awk '/^default / { print $3 }'` #获取并保存default路由 [ -n "${DEFRT}" ] && echo $DEFRT > /etc/default-route route del default >/dev/null 2>&1 #删除default路由 else DEFAULTROUTE="" fi # Standard PPP options we always use PPP_STD_OPTIONS="$IPPARAM $LINKNAME $PLUGIN_OPTS noipdefault noauth default-asyncmap $DEFAULTROUTE hide-password nodetach $PEERDNS mtu $MTU mru $MRU noaccomp noccp nobsdcomp nodeflate nopcomp novj novjccomp user $USER lcp-echo-interval $LCP_INTERVAL lcp-echo-failure $LCP_FAILURE $PPPD_EXTRA" #pppd命令显示信息 # PPPoE invocation # pppoe执行命令 PPPOE_CMD="$PPPOE -p $PPPOE_PIDFILE -I $ETH -T $PPPOE_TIMEOUT -U $PPPOE_SYNC $CLAMPMSS $ACNAME $SERVICENAME $PPPOE_EXTRA" #pppoe命令显示信息 if test "$DEBUG" != "" ; then if test "$DEMAND" != "" ; then echo "(Turning off DEMAND for debugging purposes)" DEMAND="" fi echo "* The following section shows the pppd command we will invoke" >> $DEBUG echo "pppd invocation" >> $DEBUG echo "$SETSID $PPPD pty '$PPPOE_CMD' $PPP_STD_OPTIONS $PPPD_SYNC debug" >> $DEBUG echo "---------------------------------------------" >> $DEBUG $SETSID $PPPD pty "$PPPOE_CMD -D $DEBUG-0" \ $PPP_STD_OPTIONS \ $PPPD_SYNC \ debug >> $DEBUG 2>&1 echo "---------------------------------------------" >> $DEBUG echo "* The following section is an extract from your log." >> $DEBUG echo "* Look for error messages from pppd, such as" >> $DEBUG echo "* a lack of kernel support for PPP, authentication failure" >> $DEBUG echo "* etc." >> $DEBUG if test -f "/var/log/messages" ; then echo "Extract from /var/log/messages" >> $DEBUG grep 'ppp' /var/log/messages | tail -150 >> $DEBUG elif test -f "/var/adm/messages"; then echo "Extract from /var/adm/messages" >> $DEBUG grep 'ppp' /var/adm/messages | tail -150 >> $DEBUG else echo "Can't find messages file (looked for /var/{log,adm}/messages" >> $DEBUG fi date >> $DEBUG echo "---------------------------------------------" >> $DEBUG echo "* The following section is a dump of the packets" >> $DEBUG echo "* sent and received by rp-pppoe. If you don't see" >> $DEBUG echo "* any output, it's an Ethernet driver problem. If you only" >> $DEBUG echo "* see three PADI packets and nothing else, check your cables" >> $DEBUG echo "* and modem. Make sure the modem lights flash when you try" >> $DEBUG echo "* to connect. Check that your Ethernet card is in" >> $DEBUG echo "* half-duplex, 10Mb/s mode. If all else fails," >> $DEBUG echo "* try using pppoe-sniff." >> $DEBUG echo "rp-pppoe debugging dump" >> $DEBUG cat $DEBUG-0 >> $DEBUG rm -f $DEBUG-0 for i in 1 2 3 4 5 6 7 8 9 10 ; do echo "" echo "" echo "" done echo "*** Finished debugging run. Please review the file" echo "*** '$DEBUG' and try to" echo "*** figure out what is going on." echo "***" echo "*** Unfortunately, we can NO LONGER accept debugging" echo "*** output for analysis. Please do not send this to" echo "*** Roaring Penguin; it is too time-consuming for" echo "*** us to deal with all the analyses we have been sent." exit 0 fi echo $$ > $PIDFILE #将当前脚本的adsl-connect进程号写入pidfile文件中 while [ true ] ; do if [ "${DEFROUTE}" != "no" ] ; then DEFRT=`ip route list | awk '/^default / { print $3 }'` [ -n "${DEFRT}" ] && echo $DEFRT > /etc/default-route route del default >/dev/null 2>&1 fi if test "$BR2684DEV" != ""; then $BR2684CTL -b -c $BR2684DEV -a $VPI.$VCI /sbin/ip link set $ETH up fi if test "$LINUX_PLUGIN" != "" ; then $SETSID $PPPD $PPP_STD_OPTIONS $DEMAND & echo "$!" > $PPPD_PIDFILE else $SETSID $PPPD pty "$PPPOE_CMD" \ $PPP_STD_OPTIONS \ $DEMAND \ $PPPD_SYNC & echo "$!" > $PPPD_PIDFILE #记录pppd的pid进程号,此时会覆盖336行写入的adsl-connect的pid,但也不会导致 fi wait if test "$BR2684DEV" != ""; then kill `cat /var/run/nas$BR2684DEV.pid` rm /var/run/nas$BR2684DEV.pid fi # Run /etc/ppp/adsl-lost if it exists test -x /etc/ppp/adsl-lost && /etc/ppp/adsl-lost # Re-establish the connection $LOGGER -p daemon.notice "ADSL connection lost; attempting re-connection." # Wait a bit in case a problem causes tons of log messages :-) sleep 5 done
adsl-stop脚本:
#! /bin/bash # Generated automatically from adsl-stop.in by configure. #*********************************************************************** # # adsl-stop # # Shell script to bring down an ADSL connection # # Copyright (C) 2000 Roaring Penguin Software Inc. # # $Id: adsl-stop.in,v 1.4 2001/04/02 13:59:14 dfs Exp $ # # This file may be distributed under the terms of the GNU General # Public License. # # Usage: adsl-stop [config_file] # If config_file is omitted, defaults to /etc/ppp/pppoe.conf # #*********************************************************************** export PATH=/sbin:/bin:/usr/sbin:/usr/bin LS=/bin/ls NETWORKDIR=/etc/sysconfig/network-scripts # Set to "C" locale so we can parse messages from commands LANG=C export LANG 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 } ME="`basename $0`" LOGGER="/usr/bin/logger -t $ME" CONFIG="$1" 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 1o fi . $CONFIG PPPOE_PIDFILE="$PIDFILE.pppoe" PPPD_PIDFILE="$PIDFILE" STARTPID="$PIDFILE.start" # Backward config file compatibility if test "$DEMAND" = "" ; then DEMAND=no fi # Ignore SIGTERM trap "" 15 # Check for pidfile if [ -r "$PIDFILE" ] ; then PID=`cat $PIDFILE` # Check if still running kill -0 $PID > /dev/null 2>&1 if [ $? != 0 ] ; then [ "$DEBUG" = "1" ] && echo "$ME: The adsl-connect script (PID $PID) appears to have died" >& 2 fi # Kill pppd, which should in turn kill pppoe if [ -r "$PPPD_PIDFILE" ] ; then PPPD_PID=`cat "$PPPD_PIDFILE"` $LOGGER -p daemon.notice "Killing pppd" [ "$DEBUG" = "1" ] && echo "Killing pppd ($PPPD_PID)" kill $PPPD_PID > /dev/null 2>&1 fi # Kill adsl-start PIDS=`cat $STARTPID` kill -0 $PIDS > /dev/null 2>&1 if [ $? = 0 ] ; then $LOGGER -p daemon.notice "Killing adsl-start" kill $PIDS > /dev/null 2>&1 fi # Kill adsl-connect $LOGGER -p daemon.notice "Killing adsl-connect" [ "$DEBUG" = "1" ] && echo "Killing adsl-connect ($PID)" kill $PID > /dev/null 2>&1 # Kill br2684ctl if necessary if [ -n "$BR2684DEV" -a -r /var/run/nas$BR2684DEV.pid ]; then PIDS=`cat /var/run/nas$BR2684DEV.pid` kill -0 $PIDS > /dev/null 2>&1 if [ $? = 0 ]; then $LOGGER -p daemon.notice "Killing br2684ctl for nas$BR2684DEV" kill $PIDS > /dev/null 2>&1 fi rm -f /var/run/nas$BR2684DEV.pid fi rm -f "$PIDFILE" "$PPPD_PIDFILE" "$PPPOE_PIDFILE" "$STARTPID" else [ "$DEBUG" = "1" ] && echo "$ME: No ADSL connection appears to be running" >&2 exit 1 fi # add old default gw back if [ -s /etc/default-route ] ; then route add default gw `cat /etc/default-route` rm -f /etc/default-route fi exit 0
pppoe.conf文件:
USERCTL=yes BOOTPROTO=dialup NAME=DSLppp_0 DEVICE=ppp_0 TYPE=xDSL ONBOOT=no PIDFILE=/var/run/pppoe-adsl.pid FIREWALL=MASQUERADE PING=. PPPOE_TIMEOUT=80 LCP_FAILURE=3 LCP_INTERVAL=20 CLAMPMSS=1412 CONNECT_POLL=6 CONNECT_TIMEOUT=60 DEFROUTE=yes SYNCHRONOUS=no ETH=port002 PROVIDER=DSLppp_0 USER=test PEERDNS=yes DEMAND=no
若是指定接口eth0启动pppoe时,需要修改pppoe.conf文件为:
USERCTL=yes BOOTPROTO=dialup NAME=DSLppp_eth0 DEVICE=ppp_eth0 TYPE=xDSL ONBOOT=no PIDFILE=/var/run/pppoe-adsl.pid FIREWALL=MASQUERADE PING=. PPPOE_TIMEOUT=80 LCP_FAILURE=3 LCP_INTERVAL=20 CLAMPMSS=1412 CONNECT_POLL=6 CONNECT_TIMEOUT=60 DEFROUTE=yes SYNCHRONOUS=no ETH=eth0 PROVIDER=DSLppp_eth0 USER=test PEERDNS=yes DEMAND=no
chap-secrets文件:
# Secrets for authentication using CHAP # client server secret IP addresses ####### redhat-config-network will overwrite this part!!! (begin) ########## ####### redhat-config-network will overwrite this part!!! (end) ############ test * test *
pap-secrets文件:
# Secrets for authentication using PAP # client server secret IP addresses ####### redhat-config-network will overwrite this part!!! (begin) ########## ####### redhat-config-network will overwrite this part!!! (end) ############ test * test *
相关文章推荐
- Linux终端远程连接配置
- 系统调用和库函数
- Linux系统编程——进程调度浅析
- linux中fork()函数详解(原创!!实例讲解) - jason的专栏 - 博客频道 - CSDN.NET
- centos5.6 中文乱码 问题
- 分享自fissure 《Linux编程 报错 找不到 term.h和curses.h》
- Linux/Unix time时间戳的处理转换函数
- 嵌入式ARM+Linux 多个不同版本的交叉编译器的切换方法
- linux增加系统监视器的快捷键
- 【小镇的技术之路】Linux中的execve函数
- CentOS配置网卡IP
- 个人常用linux命令归纳(1)
- virtclouds,一个分享虚拟化编程和Linux编程的平台
- Linux 文件系统:procfs, sysfs, debugfs 用法简介
- Linux下修复“fatal error: jsoncpp/json/json.h: No such file or directory” 分类: C++ | 标签: Linux,jsonjson
- 在centos下配置samba服务器
- centos 安装node4.3.0
- Linux 权限管理
- linux环境变量之PS1
- linux的echo命令详解