[pptp-server] linux pptp client: how to stop it?

Dave Morse svref at yahoo.com
Thu Jul 27 12:13:52 CDT 2000


Tom Eastep writes:
 > Thus spoke Dave Morse:
 > 
 > > I have the linux pptp client working.  Now how do I get it to shut down
 > > and free ppp0?  This is so that I can start it again, after a remote
 > > server reboot or something.
 > > 
 > 
 > Here's the script that I use:
 > [THUNK]
 > This is RedHat-centric but can be adapted to other setups.

Lucky for me, since RH is what the server happens to use.  I had to modify
the script a bit.  There were a few hacks in it, that maybe people can
clear up.

Here are the particular hacks:

1) it checks for the success of pptp by greping for "ppp0" in "ifconfig".
Unfortunately it takes some time for pptp to actually create ppp0 on my
configuration.  So I have to "sleep 5" in there.  Ideally I could query
the state, to see if the connection has been accepted, failed, or still
resolving.  

2) This variant script assumes ppp0 is the interface that gets created.
Can anyone think of a good way to query the created interface?  Better
yet, can anyone think of a way to force ppp0?  This makes firewall admin
cleaner.

3) This script calls route after a successful connect, to interface to the
whole subnet on the other side of the connection.

#!/bin/sh
#
#  /etc/rc.d/init.d/wet-vpn
#
# chkconfig: 5 12 85
# description: PPTP Link Control
#

PPTP=/usr/local/sbin/pptp
# Tunnel_name identifies the network we're dealing with.  Intended to
# match the filename of this script in /etc/rc.d/init.d/
TUNNEL_NAME=wet-vpn
# External internet interface of the vpn-ing machine
ADDRESS=209.85.130.149
# internal interface & mask that we're trying to get to.
SUBNET=192.168.1.0
SUBNET_MASK=255.255.255.0
USER=pisati
# I HOPE this is the interface we get. :(
# I've not found the flags to FORCE it to be this, but this is where
# we'll go a-file-freeing to turn things off.
INTERFACE=ppp0  

case "$1" in
	start)
		echo "Starting PPTP Connection to ${TUNNEL_NAME}..."
		$PPTP $ADDRESS user $USER
		echo "Sleeping for login to resolve"
		sleep 5
		if `ifconfig | grep -q $INTERFACE` ; then
			touch /var/lock/subsys/$TUNNEL_NAME
			echo "Setting up routing through $INTERFACE"
			route add -net $SUBNET netmask $SUBNET_MASK dev $INTERFACE
			else
			echo "Something went wrong  no $INTERFACE found in ifconfig output"
                fi
		;;
	stop)
		echo "Stopping $TUNNEL_NAME PPTP Connection..."
		if ( /usr/bin/killall $PPTP ); then
		    echo "Stopped pptp"
		else
		    rm -f /var/run/pptp/$ADDRESS
                fi

		if ( /usr/bin/killall pppd ); then
		    echo "Stopped pppd"
                fi
		rm -f /var/lock/subsys/$TUNNEL_NAME

		echo taking $INTERFACE down
		ifconfig $INTERFACE down
		
		sleep 5
		;;
	restart)
		echo "Restarting $TUNNEL_NAME PPTP Connection..."
		$0 stop
		$0 start
		;;
	status)
		ifconfig ppp0
		;;
	*)
		echo "Usage: $0 {start|stop|restart|status}"
		;;
esac



More information about the pptp-server mailing list