prasys

Untitled

Jan 20th, 2012
137
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # IPv6 Tunnel setup of an tunnelbroker.net tunnel on Linux using the `ip` tool from the iproute suite (iproute2)
  4. # Website of iproute2: <http://www.linux-foundation.org/en/Net:Iproute2>
  5. # Package on Ubuntu: <http://packages.ubuntu.com/iproute> and on Arch Linux <http://www.archlinux.org/packages/?&q=iproute2>
  6. #
  7. # Run like this:
  8. # ./tunnelbroker-net.linux.sh
  9. #
  10. # 2011 by Philipp Klaus
  11. # Published on <http://blog.philippklaus.de/2011/05/ipv6-6in4-tunnel-via-hurricane-electric-tunnelbroker-net-tunnel-setup-on-ubuntu-11-04/>
  12. # Modified by Pradeesh Parameswaran (prasys) to add a few stuff
  13. # Uncomment this line to debug the script:
  14. #set -x
  15.  
  16. # CONFIGURATION BEGINS HERE
  17. #ALL OF THESE INFORMATION CAN BE OBTAINED FROM http://tunnelbroker.net/tunnel_detail.php?
  18. LOCALIPV41=`wget -qO- http://v4.ipv6-test.com/api/myip.php` # do not touch this unless you plan to use another site or comment this if you are on static ip
  19. LOCALIPV4="" # your local IP address ,(i.e behind router/public IP address)
  20. HEIPV4SERVER="" # tunnel's server IP Address
  21. HEIPV6CLIENT="" # Client Address generally ends with 2
  22. TUNNELNAME="he-ipv6" # feel free to name it
  23. ROUTE64="" # your Route64 ID
  24. HEUSER='' # hash from the website, "UserID" (under the main page)
  25. HEPASS='' # hash: echo -n MyPass|md5 (or use an online md5 hash tool)
  26. HETUNNEL= # from the website, "Global Tunnel ID" - it can be obtained from the URL of your tunnel
  27. ETH="" # your ethernet/wlan adapter (i.e en0 , en1 , etc)
  28. IPADR="" # your Routed64 Address + 1 (i.e 2001:45:19:e35::1) just add 1 after the two ::
  29.  
  30. # CONFIG ENDS HERE
  31.  
  32. echo "Please enter your user account password. It is needed to set up the IPv6 tunnel."
  33. sudo echo "Gained superuser permissions"
  34. if [ $? == 1 ]; then echo "Sorry! You need to provide your password in order to set up the tunnel."; exit 1; fi
  35.  
  36.  
  37.  
  38. # If you have the UFW firewall running on your system, make sure, passing proto 41 is allowed
  39. # found on <https://bugs.launchpad.net/ufw/+bug/502655/comments/8>
  40. #sudo ufw allow proto ipv6 from $HEIPV4SERVER
  41. cat << "EOF"
  42. Please make sure, that `IPV6=yes` is set in `/etc/default/ufw`. After changing this,
  43. you have to run `sudo ufw disable && sudo ufw enable` in order to get it to work.
  44. EOF
  45.  
  46. # It pretty much removes any tunnel and recreates them back , this is to avoid some issues and stuff
  47. sudo ip tunnel del $TUNNELNAME
  48. sudo ip route delete ::/0 dev $TUNNELNAME
  49. sudo ip addr del $HEIPV6CLIENT dev $TUNNELNAME
  50. sudo ip link set $TUNNELNAME down
  51. sudo ip tunnel del $TUNNELNAME
  52.  
  53.  
  54. #This part "updates" your IP Address , ideal for those who are using dynmanic IP
  55. #Comment the part below if you are on static IP
  56. curl -k -s "https://ipv4.tunnelbroker.net/ipv4_end.php?ip=$LOCALIPV41&pass=$HEPASS&apikey=$HEUSER&tid=$HETUNNEL"
  57.  
  58. # Now setup the tunnel, start the link, add the IPv6 address to the tunnel and set up routing.
  59.  
  60. sudo ip tunnel add $TUNNELNAME mode sit remote $HEIPV4SERVER local $LOCALIPV4 ttl 255
  61. sudo ip link set $TUNNELNAME up
  62. sudo ip addr add $HEIPV6CLIENT dev $TUNNELNAME
  63. sudo ip route add ::/0 dev $TUNNELNAME
  64. sudo ip -6 addr add $IPADR dev $ETH
  65. ip -f inet6 addr # &#8592; show the current IPv6 addresses on you machine
  66.  
  67. cat << EOF
  68. You set up the tunnel. To remove the tunnel again, run these commands:
  69.  
  70. sudo ip route delete ::/0 dev $TUNNELNAME
  71. sudo ip addr del $HEIPV6CLIENT dev $TUNNELNAME
  72. sudo ip link set $TUNNELNAME down
  73. sudo ip tunnel del $TUNNELNAME
  74. EOF
RAW Paste Data