Following is the script I use to initialize my IPv6 tunnel on GNU/Linux:
#!/bin/sh
# Name: up-he.sh
# Description: Initializes the IPv6 tunnel from HE.
# Author: Ashish Shukla <gmail.com!wahjava>
# OS: GNU/Linux
# NOTE: This script requires superuser privileges.
# Default outgoing interface
INTERFACE=ppp0
# IPv6 tunnel interface name
HE=he-ipv6-tunnel
IP_OF_INTERFACE=`/sbin/ifconfig ${INTERFACE} |awk '/^[[:space:]]+inet[[:space:]]/ { print $2 }' |sed -e s/addr://`
# Enter your IPv6 /64 endpoint here.
IP6_TUNNEL_ENDPOINT=2001:470::/64
# Enter your IPv4 tunnel endpoint here.
REMOTE_ENDPOINT=127.0.0.2
/sbin/ip tunnel add $HE mode sit remote ${REMOTE_ENDPOINT} local ${IP_OF_INTERFACE} ttl 255
/sbin/ip link set $HE up
/sbin/ip addr add ${IP6_TUNNEL_ENDPOINT} dev $HE
/sbin/ip route add ::/0 dev $HE
# Add a explicit route in case if you've multiple outgoing interfaces ;)
/sbin/ip route add ${REMOTE_ENDPOINT} dev $INTERFACE
# Comment the following line, if you want /64 IPv6 endpoint address to be the used as the default source address
/sbin/ip addr del ${IP6_TUNNEL_ENDPOINT} dev $HE
And, following is its FreeBSD counterpart:
#!/bin/sh
# Name: up-he.sh
# Description: Initializes the IPv6 tunnel from HE.
# Author: Ashish Shukla <gmail.com!wahjava>
# OS: FreeBSD
# NOTE: This script requires superuser privileges.
# The IPv6 tunnel interface you want to be created, make sure its name starts with 'gif'
TUNNEL_IF=gif0
# The outgoing interface
INTERFACE=ng0
LOCAL_ENDPOINT=`/sbin/ifconfig ${INTERFACE} |awk '/^[[:space:]]*inet[[:space:]]/ { print $2 }'`
# Please enter your remote IPv4 endpoint here.
REMOTE_ENDPOINT=127.0.0.1
# Please enter your local IPv6 /64 endpoint here
LOCAL6_ENDPOINT=2001:470:xxxx::1
# Please enter your remote IPv6 /64 endpoint here
REMOTE6_ENDPOINT=2001:470:xxxx::2
# ${REMOTE6_ENDPOINT} prefixlen 64
sudo ifconfig ${TUNNEL_IF} create
echo created.
sudo ifconfig ${TUNNEL_IF} tunnel ${LOCAL_ENDPOINT} ${REMOTE_ENDPOINT}
echo tunnelled.
sudo ifconfig ${TUNNEL_IF} inet6 ${LOCAL6_ENDPOINT}/64
echo setup.
sudo route -n add -inet6 default ${REMOTE6_ENDPOINT}
echo routed.
sudo ifconfig ${TUNNEL_IF} up
echo up.
# Comment the following line, if you want /64 IPv6 endpoint address to be used as default source address
sudo ifconfig ${TUNNEL_IF} inet6 ${LOCAL6_ENDPOINT} -alias
Following is the script I use to update my IPv4 endpoint, stored in the IPv6 tunnel database of HE, from GNU/Linux:
#!/bin/sh
# Name: setup-he.sh
# Description: Updates IPv4 endpoint in IPv6 tunnel databse of HE
# Author; Ashish Shukla <gmail.com!wahjava>
# OS: GNU/Linux
# NOTE: This script doesn't require superuser privileges.
IFACE=ppp0
ENDPOINT=`/sbin/ifconfig ${IFACE} | sed -e s/addr://g |awk '/^[[:space:]]*inet[[:space:]]/ { print $2 }'`
SCRIPT_NAME=`basename $0`
TMPFILE=`mktemp -q -t ${SCRIPT_NAME}.XXXXXX`
# Please set appropriate paths to md5sum and wget here
WGET=/usr/bin/wget
MD5=/usr/bin/md5sum
# Enter your tunnel user id here
USER=XXXXX
# Enter your tunnel password here
PASSWORD=XXXXXXX
# Enter your Global Tunnel ID in HE's database
TUNNEL_ID=00000
MD5_PASSWORD=`printf ${PASSWORD} |md5sum |awk '{ print $1 }'`
${WGET} -O /dev/null --keep-session-cookies "--post-data=f_user=${USER}&f_pass=${MD5_PASSWORD}&clearpass=" --save-cookies=${TMPFILE} http://ipv4.tunnelbroker.net/login.php 2>/dev/null || exit 1
${WGET} -O /dev/null --load-cookies=${TMPFILE} "--post-data=ipv4b=${ENDPOINT}&tunnel_id=${TUNNEL_ID}&update=Submit" http://ipv4.tunnelbroker.net/ipv4_update.php 2>/dev/null || exit 2
rm ${TMPFILE}
exit 0
And following is its FreeBSD counterpart:
#!/bin/sh
# Name: setup-he.sh
# Description: Updates IPv4 endpoint in IPv6 tunnel databse of HE
# Author; Ashish Shukla <gmail.com!wahjava>
# OS: FreeBSD
# NOTE: This script doesn't require superuser privileges.
# Default outgoing interface
IFACE=ng0
ENDPOINT=`/sbin/ifconfig ${IFACE} |awk '/^[[:space:]]*inet[[:space:]]/ { print $2 }'`
SCRIPT_NAME=`basename $0`
TMPFILE=`mktemp -q -t ${SCRIPT_NAME}`
# Please set appropriate paths to md5 and wget here
WGET=/usr/local/bin/wget
MD5=/sbin/md5
# Enter your tunnel user id here
USER=XXXXXX
# Enter your tunnel password here
PASSWORD=XXXXXXX
# Enter your Global Tunnel ID in HE's database
TUNNEL_ID=00000
MD5_PASSWORD=`${MD5} -q -s ${PASSWORD}`
${WGET} -O /dev/null --keep-session-cookies "--post-data=f_user=${USER}&f_pass=${MD5_PASSWORD}&clearpass=" --save-cookies=${TMPFILE} http://ipv4.tunnelbroker.net/login.php 2>/dev/null
${WGET} -O /dev/null --load-cookies=${TMPFILE} "--post-data=ipv4b=${ENDPOINT}&tunnel_id=${TUNNEL_ID}&update=Submit" http://ipv4.tunnelbroker.net/ipv4_update.php 2>/dev/null
rm ${TMPFILE}
The tunnel endpoint updating scripts are inspired from a script written by someone (sorry the name I’ve forgotten, but the regexp is f.*) on #ipv6@irc.freenode.net.
UPDATE: The scripts are recently updated on Mon Sep 1 10:46:40 IST 2008.
