Created
August 1, 2012 23:59
-
-
Save snoj/3231686 to your computer and use it in GitHub Desktop.
Charter 6rd Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
##original https://gist.github.com/1016433 | |
#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. | |
#This script sets your Linux (I use Ubuntu) box to function as a 6RD routing device. | |
#I've left out radvd as I use HE TunnelBroker for my network's addressing. | |
#Get Charter's 6rd host | |
HOST6RD=$(nslookup 6rd.charter.com | grep "Address"| awk '{ print $2 }'| tail --lines=1); | |
#Get our public IP. | |
EXTERNIP=$(wget -q4 -O - http://ifconfig.me/ip); | |
#Get the interface that is our 'WAN'. | |
#Should always return the interface ip that we talk on our local net with. | |
#Shouldn't cause issues unless your external interface is public and on the same subnet as HOST6RD. | |
WANIP=$(ip route get $HOST6RD | head --lines=1 | awk '{ print $7 }'); | |
#What our prefix will be based on our external public IP address. | |
V6PREFIX=$(printf ' 2602:100:%02x%02x:%02x%02x' $(echo $EXTERNIP | tr . ' ')) | |
echo "External IP: $EXTERNIP"; | |
echo "'WAN' IP: $WANIP"; | |
echo "IPv6 prefix: $V6PREFIX::/32"; | |
if [ -n "$EXTERNIP" ] | |
then | |
#Delete previous tunnel | |
ip tunnel del tun6rd | |
#Recreate tunnel using the 'WAN' ip. | |
ip tunnel add tun6rd mode sit ttl 255 remote any local $WANIP | |
ip link set tun6rd mtu 1280 | |
ip link set tun6rd up | |
ip addr add $V6PREFIX::1/32 dev tun6rd | |
ip -6 route add ::/0 via ::$HOST6RD dev tun6rd | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment