Shell VPN
Этот скрипт позволяет с помощью pptp реализовать доступ к интернету
из внутренней локальной сети.
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:.
export PATH
#
# network settings
#
USER= ваш_логин
NETWORK=192.168.55.120
NETMASK=255.255.255.0
VPNSERVER=192.168.0.253
GATEWAY=192.168.55.253
DEVICE=eth0
# vpn stuff
#
PPPD=/usr/sbin/pppd
PPTP=/usr/sbin/pptp
if [ ! -x $PPPD ]; then
echo "$0: $PPPD not found"
exit 1
fi
if [ ! -x $PPTP ]; then
echo "$0: $PPTP not found"
exit 1
fi
#
# here we go
#
case "$1" in
start)
if [ ! -d /var/run/pptp ]; then
mkdir /var/run/pptp
fi
if [ -f /var/run/pptp/remote ]; then
if ping -vc1 'cat /var/run/pptp/remote'; then
exit 1
fi
killall -HUP pptp
killall -TERM pppd
sleep 2
fi
rm -rf /var/run/pptp/* >/dev/null
route del default
route add -net $NETWORK netmask $NETMASK gw $GATEWAY dev $DEVICE
echo -n "===> Starting vpn: "
($PPTP $VPNSERVER defaultroute noauth user $USER && \
echo -n "done") || echo -n "failed"
echo
;;
stop)
echo -n "===> Stopping vpn: "
killall -HUP pptp
killall -TERM pppd
sleep 2
rm /var/run/pptp/* >/dev/null
route del -net $NETWORK netmask $NETMASK gw $GATEWAY dev $DEVICE
route add default gw $GATEWAY dev $DEVICE
echo "done"
;;
restart)
$0 stop
sleep 2
$0 start
;;
*)
echo "*** Usage: vpn {start|stop|restart}"
exit 1
;;
esac
exit 0
|
|