Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- server_ip="10.0.5.1"
- client_ip="10.0.5.50"
- max_errors=3
- time_ping=3
- time_sleep=10
- time_sleep_routes=5
- inited=false
- #now remove default route and only one to the vpn server
- ip route del default
- ip route add xxx.xxx.xxx.xxx via 172.24.127.17
- restart_tunnel()
- {
- shutdown_tunnel
- #invoke-rc.d ipsec restart
- /etc/init.d/ipsec restart
- sleep 3
- #invoke-rc.d xl2tpd restart
- /etc/init.d/xl2tpd restart
- sleep 3
- ipsec auto --up L2TP-PSK
- echo "c vpn-sf14" > /var/run/xl2tpd/l2tp-control
- # now we have to wait a few secs to exchange the default-routes
- sleep 5
- ip route add default via 10.0.5.1
- }
- shutdown_tunnel()
- {
- /etc/init.d/ipsec stop
- /etc/init.d/xl2tpd stop
- echo "Tunnel was shut down"
- }
- fail_count=0
- packet_count=0
- while :
- do
- packet_count=`ping $server_ip -c 1 -w $time_ping | grep -E -o '[0-9]+ received' | cut -f1 -d' '`
- if [ "$packet_count" != "1" ] ; then
- fail_count=$((fail_count+1))
- fi
- if [ $fail_count -eq $max_errors ] ; then
- echo "Fail-count reached, restarting tunnel"
- fail_count=0
- restart_tunnel
- fi
- echo $fail_count
- sleep $time_sleep
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement