Skip to content

Instantly share code, notes, and snippets.

@rjstone
Last active October 17, 2016 07:51
Show Gist options
  • Save rjstone/b3e42f708050c5bebefb447f09e4a808 to your computer and use it in GitHub Desktop.
Save rjstone/b3e42f708050c5bebefb447f09e4a808 to your computer and use it in GitHub Desktop.
Hurricane Electric Tunnelbroker IPv6 6in4 configuration script for DD-WRT. See https://is.gd/Aijzpc for more info.
#!/bin/sh
# HE IPv6 6in4 config script. See https://is.gd/Aijzpc for more info.
# If needed, add -x after /bin/sh above for more debug output.
# Save this as your "Custom Script".
# Put this in your Startup Script to use this script:
# mkdir -p /tmp/etc/config
# ln -sf /tmp/custom.sh /tmp/etc/config/ipv6-tunnel.wanup
####### Configuration ########
# "Server IPv4 Address"
TUNNEL_SERVER="216.66.22.2"
# "Client IPv6 Address"
MY_TUNNEL_ADDR="2001:xxxx:xxxx:xxxx::2"
# "Routed /64"
MY_ROUTED_ADDR="2001:xxxx:xxxx:xxxx::1"
# Whatever name you want for your tunnel interface
TUNNELIF="he-ipv6"
##############################
# For debugging redirect stderr > stdout for rest of script and log
logfile=/tmp/custom.log
echo "See $logfile for errors."
exec 1>> $logfile 2>&1
# For some reason wanup scripts get run multiple times.
lockfile=/tmp/custom.lock
if ! (set -o noclobber ; echo > $lockfile) ; then
echo "Script already running. Exiting."
exit 1
fi
trap "rm -f $lockfile" 0 2 3 15
echo "Custom.sh started:" `date`
# Set to your wan interface, normally vlan2 or ppp0 (for PPPoE) if this command doesn't work
WANIF=`get_wanface`
last_wanip_file=/tmp/custom.last_wanip
touch $last_wanip_file
LAST_WANIP=`cat $last_wanip_file`
# Wait for interface to come up and get address
WANIP=""
while [ -z $WANIP ]; do
WANIP=$(ifconfig $WANIF | sed -n '/inet /{s/.*inet.*addr\://;s/ .*//;p}')
sleep 1
done
if [ "$WANIP" == "$LAST_WANIP" ]; then
echo "WANIP $WANIP didn't change. Exiting. ('rm $last_wanip_file' to force)"
exit
fi
echo $WANIP > $last_wanip_file
ip tunnel del $TUNNELIF 2>>/dev/null
ip tunnel add $TUNNELIF mode sit remote $TUNNEL_SERVER local $WANIP ttl 255
ip link set $TUNNELIF up
sleep 1
ip addr add $MY_TUNNEL_ADDR/64 dev $TUNNELIF
ip route add ::/0 dev $TUNNELIF
ip -6 addr add $MY_ROUTED_ADDR/64 dev br0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment