/etc/cron.d/vpn - cron job file that checks if connection is alive (needs to be created)
Note 1: Be root.
Note 2: Make sure you read each file, and adjust things that need to be adjusted (like usernames, passwords and isp vpn addresses).
DO NOT(!) just copy-paste like a parrot, make sure you understand what you're doing! If you don't understand something - RTFM!
#!/bin/bash
# If this is a "stop" request
if [ "$1" == "stop" ]
then
# remove the run file
rm /var/run/vpn_run
# kill the link
killall pppd
# restart network
/etc/init.d/networking stop
/etc/init.d/networking start
exit 1
# If it's not a stop request
else
# make a run file
touch /var/run/vpn_run
# your vpn address
vpn="172.26.255.198"
# replace this vpn address with your isp's vpn pptp
# for address of your isp's pptp server, go here:
# http://cables.org.il/vpn/vpn.html
# Fix gateway
gateway=`/sbin/route | grep default | awk '{print $2}'`
/sbin/route add -net $vpn netmask 255.255.255.255 gw $gateway
/sbin/route del default
# Make the connection
/usr/sbin/pppd call provider
fi
#!/bin/bash
# check if we're supposed to run, if not - exit
[ -e /var/run/vpn_run ] || exit 1
check=`cat /proc/net/dev | grep ppp | wc -l | awk '{ print $1 }'`
if [ "$check" == "0" ]
then
echo "VPN is dead! Trying to reconnect..."
# Kill off all stale processes of pppd and pptp
killall -9 pppd
killall -9 pptp
# Make sure they're dead by killing them again
killall -9 pppd
killall -9 pptp
# Make sure we don't have any stale pids of pppd lying around
rm /var/run/ppp?.pid
# Wait 3 seconds
sleep 3
# Restart all networking in order to make sure we have current dhcp settings on our eth
/etc/init.d/networking stop
/etc/init.d/networking stop
/etc/init.d/networking start
# Wait 3 seconds
sleep 3
# Make the connection
/usr/bin/vpn
fi
#!/bin/bash
/usr/bin/vpn
If you're not running Debian GNU/Linux, this will probably not work for you.
On other Linux distributions, just add /usr/bin/vpn to your local startup script (iirc, gotta be something like /etc/init.d/rc.local on RedHat and friends)
# PAP Secrets File
# Syntax: username * password
# known isp suffixes (goes instead of "@CActcom")
# Actcom: @CActcom
# 012.net: no suffix needed
# Barak 013: no suffix needed
# AquaNet: @CAquanet
# InternetZahav: @ACZahav
# BezeqInt: unknown ???
# Netvision: no suffix needed
username@CActcom * password
# Username and pptp connection
# replace "username" with your username, "@CActcom" with your isp (if needed)
# and "172.26.255.198" with your isp's vpn server
user username@CActcom
pty "/usr/sbin/pptp 172.26.255.198 --nolaunchpppd"
# Lock the port
lock
# We don't need the tunnel server to authenticate itself
noauth
# Turn off transmission protocols we know won't be used
nobsdcomp
nodeflate
# Used to check if connection dies
lcp-echo-failure 10
lcp-echo-interval 20
# We don't need to specify default ip, we get one from server
noipdefault
# Don't show password in system log
hide-password
# Ask pppd to fetch dns ip addresses from isp
usepeerdns
NOTE: if you don't have the directory /etc/ppp/ip-up.d in your distribution (RedHat, or whatever): instead of creating this file, add the contents (without the first line) to your /etc/ppp/ip-up.local or similar local ip-up script.
#!/bin/bash
# Copy dns configuration
cp /etc/ppp/resolv.conf /etc/resolv.conf
|
/etc/ppp/ip-up.d/vpn_down
|
NOTE: if you don't have the directory /etc/ppp/ip-down.d in your distribution (RedHat, or whatever): instead of creating this file, add the contents (without the first line) to your /etc/ppp/ip-down.local or similar local ip-down script.
#!/bin/bash
# Attepmt to re-establish connection right away
/usr/bin/check_vpn
# Executes the internet connection check every minute
# If you want it to be executed every 5 minutes for example, change the first "*" to "*/5"
* * * * * (/usr/bin/check_vpn)
If you don't want your main syslog messages to be full of crontab calls for the check script and pppd LCP EchoReq/EchoRep messages,
edit your syslog config file (usually /etc/syslog.conf)
Modify the line of the main log (the one that starts with "*.*" and ends with "/var/log/syslog") to be something like:
*.*;cron,local2,auth,authpriv.none /var/log/syslog
Then add the following lines below, to redirect the annoying messages to where they belong:
cron.* /var/log/cron.log
local2.* /var/log/daemon.log
Make sure you use TABs and NOT spaces in the syslog config file! (apparently, it doesn't like spaces)
Now you probably need to restart your cron daemon: killall -HUP crontab
And your syslog daemon: killall -HUP syslogd
Don't forget to chmod a+x /usr/bin/vpn and chmod a+x /usr/bin/check_vpn
That's it. Now run /usr/bin/vpn and you're connected forever. Also, the connection should now be brought up automatically after a reboot.
Now you probably ask yourself, "What if I DO WANT to disconnect?"...
If you want to disconnect, run /usr/bin/vpn stop
This guide is inspired by "Cable Modem Mini-Howto for Israeli Linux Users" by Amit Margalit.
And here's a very detailed faithfull follower, Eyal Rozenberg's guide.
For comments, suggestions, corrections, hate-mail, etc. - feel free to email me.
See also: My Routing Guide
Hits on this page: 0
(C) L3ECH, 2003