Instantly share code, notes, and snippets.

What would you like to do?
Charter 6rd Script
#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 | grep "Address"| awk '{ print $2 }'| tail --lines=1);
#Get our public IP.
EXTERNIP=$(wget -q4 -O -;
#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" ]
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment