Немного переделано.
Пришлось лепить VPNHOSTGW, потому как сервак нев моей подсети :)[root@fc network-scripts]# cat ifcfg-pptp0
PEERDNS="yes"
DEVICE="pptp0"
ONBOOT="yes"
USERCTL="no"
PERSIST="yes"
DEBUG="yes"
DEFROUTE="yes"
PPPOPTIONS=""
MRU=""
MTU=""
IDLETIMEOUT=""
VPN_HOST="10.0.4.3"
VPNHOSTGW=""
VPN_USER="login"
VPN_PASS="password"
ROUTES=""
TYPE="pptp"
[root@fc network-scripts]# cat ifup-pptp
#!/bin/sh
# Based on Red Hat's ppp scripts
# MSG - yinyang@eburg.com
# 06/28/2000
# Changes:
# 06/28/2000 - modified scripts from original ssh vpn scripts.
PATH=/sbin:/usr/sbin:/bin:/usr/bin
if [ "$1" = watch ] ; then
shift
DEVICE=$1
shift
PID=`grep -v ppp /var/run/ppp-${DEVICE}.pid`
while ( test -e "/var/run/ppp-${DEVICE}.pid" && \
test -d "/proc/${PID}" ) ; do
sleep 5s
done
[ -e /var/run/${DEVICE}-up ] || exit 0
fi
# Get the configuration for this connection
cd /etc/sysconfig/network-scripts
. network-functions
CONFIG=$1
[ -f "$CONFIG" ] || CONFIG=ifcfg-$1
source_config
if [ "$2" = "boot" -a "${ONBOOT}" = "no" ]; then
exit
fi
[ -x /usr/sbin/pppd ] || {
echo "/usr/sbin/pppd does not exist or is not executable"
echo "ifup-pptp for $DEVICE exiting"
logger -p daemon.info -t ifup-vpn \
"/usr/sbin/pppd does not exist or is not executable for $DEVICE"
exit 1
}
opts="lock lcp-echo-interval 30 lcp-echo-failure 4 noipdefault noauth"
if [ -z "${VPNHOSTGW}" ] ; then
VPNHOSTGW=`route -n | grep '^0.0.0.0' | awk '{print $2}'`
fi
route add -host ${VPN_HOST} gw ${VPNHOSTGW}
if [ "${DEFROUTE}" = yes ] ; then
# 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 }'`
[ -n "${DEFRT}" ] && echo $DEFRT > /etc/default-route
route del default >/dev/null 2>&1
opts="$opts defaultroute"
fi
if [ "${PEERDNS}" != no ] ; then
opts="$opts usepeerdns"
fi
if [ -n "${MRU}" ] ; then
opts="$opts mru ${MRU}"
fi
if [ -n "${MTU}" ] ; then
opts="$opts mtu ${MTU}"
fi
if [ -n "${IDLETIMEOUT}" ] ; then
opts="$opts idle ${IDLETIMEOUT}"
fi
if [ -n "${IPADDR}${REMIP}" ] ; then
# if either IP address is set, the following will work.
opts="$opts ${IPADDR}:${REMIP}"
fi
if [ "${DEBUG}" = yes ] ; then
opts="$opts debug"
fi
if [ -z "${VPN_USER}" ] ; then
(logger -p daemon.info -t ifup-pptp \
"vpn: VPN_USER is not defined, authentication credentials required." &)&
exit 1
else
opts="$opts user ${VPN_USER}"
fi
if [ -z "${VPN_HOST}" ] ; then
(logger -p daemon.info -t ifup-pptp \
"vpn: VPN_HOST is not defined, to whom do I connect?" &)&
exit 1
else
opts="$opts remotename ${VPN_HOST}"
fi
(logger -p daemon.info -t ifup-pptp \
"vpn: pppd started for ${DEVICE} to ${VPN_HOST}" &)&
/usr/sbin/pptp "${VPN_HOST}" updetach $opts ${PPPOPTIONS} \
ipparam $DEVICE linkname $DEVICE
LINKUP=$?
if [ "${LINKUP}" -ne "0" ]; then
(logger -p daemon.info -t ifup-pptp \
"pptp: pppd failed to start" &)&
exit 1
fi
REALDEVICE=`grep ppp /var/run/ppp-${DEVICE}.pid`
for net in ${ROUTES}; do
unset NETWORK NETMASK
eval `echo $net | sed -e 's:\(.*\)/\(.*\):NETWORK=\1;NETMASK=\2:'`
route add -net ${NETWORK} netmask ${NETMASK} dev ${REALDEVICE}
done
if [ "${PERSIST}" = yes ] ; then
touch /var/run/${DEVICE}-up
"$0" watch "${DEVICE}" "$@" &
fi
[root@fc network-scripts]# cat ifdown-pptp
#!/bin/bash
# Based on Red Hat's ppp scripts
# MSG - yinyang@eburg.com
# 06/28/2000
PATH=/sbin:/usr/sbin:/bin:/usr/bin
cd /etc/sysconfig/network-scripts
. network-functions
CONFIG=$1
source_config
file=/var/run/ppp-$DEVICE.pid
if [ ! -f $file ]; then
# ppp isn't running, or we didn't start it
exit 0
fi
# remove the "$DEVICE-up" file so ifup-vpn knows to quit
if [ "${PERSIST}" = yes ] ; then
vpnfile=/var/run/${DEVICE}-up
[ -f "$vpnfile" ] && rm -f "$vpnfile"
fi
# pppd appears to put its pid and the real device name in this file
PID=`head -1 $file`
[ -n "$PID" ] || exit 1
kill -TERM $PID > /dev/null 2>&1
# Give pppd a chance to exit
sleep 1
[ ! -d /proc/$PID ] && exit 0
sleep 2
[ ! -d /proc/$PID ] && exit 0
# killing ppp-watch twice in a row causes it to send a SIGKILL to pppd pgrp
kill -TERM $PID > /dev/null 2>&1
# ip-down won't run in this case
/etc/sysconfig/network-scripts/ifdown-post $1
[ ! -d /proc/$PID ] && exit 0
exit 1