coolguylentz

IPv6 charter

Jul 25th, 2013
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ##original https://gist.github.com/1016433
  4.  
  5. #Had issues with this and many scripts as they all assumed that my primary router had ipv6 support and that I wasn't hiding behind something.
  6. #This script sets your Linux (I use Ubuntu) box to function as a 6RD routing device.
  7. #I've left out radvd as I use HE TunnelBroker for my network's addressing.
  8.  
  9. #Get Charter's 6rd host
  10. HOST6RD=$(nslookup 6rd.charter.com | grep "Address"| awk '{ print $2 }'| tail --lines=1);
  11.  
  12. #Get our public IP.
  13. EXTERNIP=$(wget -q4 -O - http://ifconfig.me/ip);
  14.  
  15. #Get the interface that is our 'WAN'.
  16. #Should always return the interface ip that we talk on our local net with.
  17. #Shouldn't cause issues unless your external interface is public and on the same subnet as HOST6RD.
  18. WANIP=$(ip route get $HOST6RD | head --lines=1 | awk '{ print $7 }');
  19.  
  20. #What our prefix will be based on our external public IP address.
  21. V6PREFIX=$(printf ' 2602:100:%02x%02x:%02x%02x' $(echo $EXTERNIP | tr . ' '))
  22.  
  23. echo "External IP: $EXTERNIP";
  24. echo "'WAN' IP: $WANIP";
  25. echo "IPv6 prefix: $V6PREFIX::/32";
  26.  
  27. if [ -n "$EXTERNIP" ]
  28. then
  29. #Delete previous tunnel
  30. ip tunnel del tun6rd
  31. #Recreate tunnel using the 'WAN' ip.
  32. ip tunnel add tun6rd mode sit ttl 255 remote any local $WANIP
  33. ip link set tun6rd mtu 1280
  34. ip link set tun6rd up
  35. ip addr add $V6PREFIX::1/32 dev tun6rd
  36. ip -6 route add ::/0 via ::$HOST6RD dev tun6rd
  37. ##RADVD SETUP
  38. echo "interface br0 { \
  39. MinRtrAdvInterval 3; \
  40. MaxRtrAdvInterval 10; \
  41. AdvLinkMTU 1480; \
  42. AdvSendAdvert on; \
  43. prefix $V6PREFIX::/64 { \
  44. AdvOnLink on; \
  45. AdvAutonomous on; \
  46. AdvValidLifetime 86400; \
  47. AdvPreferredLifetime 86400; \
  48. }; \
  49. RDNSS 2607:f428:1::5353:1 { }; \
  50. RDNSS 2607:f428:2::5353:1 { }; \
  51. };" \
  52. > /tmp/radvd.conf
  53. radvd -C /tmp/radvd.conf start
  54. fi
Advertisement
Add Comment
Please, Sign In to add comment