Fork me on GitHub
Mar 26 2009

A script to make sure that my IPv6 Tunnel is always on

1,334 views

I’m using an IPv6 tunnel using http://go6.net/, and when the internet connection goes down and up after a while, the tunnel just doesn’t refresh it self.
I run it on crontab for every 5 minutes for now :)
My Machine is Gentoo 2008, I guess you need to do some changes for it to work on your distro.
Hope that any one will benefit from it

  1. #!/bin/bash
  2. function restartGW {
  3.         /etc/init.d/gw6c restart
  4.         date >> /var/log/checkipv
  5. }
  6. stat="`/etc/init.d/gw6c status | tr -d ‘ ‘ | cut -d’:’ -f2`"
  7. if [ $stat == ’stopped’ ]
  8. then
  9.         restartGW
  10. elif [ $stat == ’started’ ]
  11. then
  12.         IPV4connected="`echo $(nc -zv www.google.com 80 2>&1) | cut -d’)’ -f2 | tr -d ‘ ‘`"
  13.         if [ $IPV4connected == "open" ]
  14.         then
  15.                 # check ipv6 connectivity
  16.                 IPV6connected="`echo $(nc -6zv ipv6.google.com 80 2>&1) | cut -d’)’ -f2 | tr -d ‘ ‘`"
  17.                 if [ $IPV6connected == "open" ]
  18.                 then
  19.                         exit 0;
  20.                 else
  21.                         restartGW
  22.                 fi
  23.         fi
  24. fi
  25. exit 0

Update:
This script is available at github on http://github.com/alaaibrahim/ala-scripts/.