SHOW:
|
|
- or go back to the newest paste.
| 1 | #!/bin/bash | |
| 2 | server_ip="10.0.5.1" | |
| 3 | client_ip="10.0.5.50" | |
| 4 | max_errors=3 | |
| 5 | time_ping=3 | |
| 6 | time_sleep=10 | |
| 7 | time_sleep_routes=5 | |
| 8 | inited=false | |
| 9 | ||
| 10 | #now remove default route and only one to the vpn server | |
| 11 | ip route del default | |
| 12 | - | ip route add 176.10.115.90 via 172.24.127.17 |
| 12 | + | ip route add xxx.xxx.xxx.xxx via 172.24.127.17 |
| 13 | ||
| 14 | ||
| 15 | restart_tunnel() | |
| 16 | {
| |
| 17 | shutdown_tunnel | |
| 18 | ||
| 19 | #invoke-rc.d ipsec restart | |
| 20 | /etc/init.d/ipsec restart | |
| 21 | sleep 3 | |
| 22 | #invoke-rc.d xl2tpd restart | |
| 23 | /etc/init.d/xl2tpd restart | |
| 24 | sleep 3 | |
| 25 | ipsec auto --up L2TP-PSK | |
| 26 | echo "c vpn-sf14" > /var/run/xl2tpd/l2tp-control | |
| 27 | ||
| 28 | # now we have to wait a few secs to exchange the default-routes | |
| 29 | sleep 5 | |
| 30 | ip route add default via 10.0.5.1 | |
| 31 | } | |
| 32 | ||
| 33 | shutdown_tunnel() | |
| 34 | {
| |
| 35 | /etc/init.d/ipsec stop | |
| 36 | /etc/init.d/xl2tpd stop | |
| 37 | echo "Tunnel was shut down" | |
| 38 | } | |
| 39 | ||
| 40 | ||
| 41 | fail_count=0 | |
| 42 | packet_count=0 | |
| 43 | while : | |
| 44 | do | |
| 45 | packet_count=`ping $server_ip -c 1 -w $time_ping | grep -E -o '[0-9]+ received' | cut -f1 -d' '` | |
| 46 | ||
| 47 | if [ "$packet_count" != "1" ] ; then | |
| 48 | fail_count=$((fail_count+1)) | |
| 49 | fi | |
| 50 | ||
| 51 | if [ $fail_count -eq $max_errors ] ; then | |
| 52 | echo "Fail-count reached, restarting tunnel" | |
| 53 | fail_count=0 | |
| 54 | restart_tunnel | |
| 55 | fi | |
| 56 | ||
| 57 | echo $fail_count | |
| 58 | sleep $time_sleep | |
| 59 | done |