Easy IPv6 connections with miredo

Posted by Steve on Mon 1 Dec 2008 at 19:36

Many services are starting to become available over IPv6, including this site, but the majority of home users cannot access them. If you'd like to see the IPv6 internet chances are it won't be difficult for you though.

One of the most common ways of gaining IPv6 access is via 6to4. This works beautifully if you have a static IP address. The setup is pretty simple too:

The setup described there is simple enough to automate, and you can add the following to /etc/init.d/ipv6 if you have a suitable system:

#!/bin/sh
#
#  Auto-configure IPv6 support for the current host via
# 6to4 tunnels
#
# Steve
# --
#




#
#  The local addresses
#
ipv4=$(ifconfig eth0  | grep "inet addr" | awk '{print $2}' | awk -F: '{print $2
}')

#
#  The IPv6 address we generate
#
ipv6="$(printf "2002:%02x%02x:%02x%02x::1" `echo $ipv4 | tr "." " "`)"


#
#  Make sure we get an argument we recognise
#
if [ -z "$1" ]; then
    echo "$0 [show|status|start|stop|test]"
    exit
fi

case "$1" in
    show)
        echo "IPv4: $ipv4"
        echo "IPv6: $ipv6"

        ;;
    start)
        echo "Starting .."
        /sbin/ip tunnel add tun6to4 mode sit ttl 30 remote any local $ipv4
        /sbin/ip link set dev tun6to4 up
        /sbin/ip -6 addr add $ipv6/16 dev tun6to4
        /sbin/ip -6 route add 2000::/3 via ::192.88.99.1 dev tun6to4 metric 1
        /sbin/ip -6 route add 2000::/3 via 2002:c058:6301::1 dev tun6to4 metric 1
        ;;
    stop)
        echo "Stopping .."
        /sbin/ip -6 route flush dev tun6to4
        /sbin/ip link set dev tun6to4 down
        /sbin/ip tunnel del tun6to4

        ;;
    test)
        echo "Testing .."
        ping6 -c 4 $ipv6

        ;;
    status)
        if ( ip link |grep tun6to4 2>/dev/null >/dev/null ) ; then
            echo "ipv6 seems to be up"
        else
            echo "ipv6 seems to be down"
        fi
        ;;
     *)
        echo "$0 [show|status|start|stop|test]"
        ;;
esac

But this solution, as well as requiring a static IP address is more complex than it needs to be. It should be possible to easily gain access to the IPv6 internet and thats what the miredo package offers.

miredo is a Unix daemon program which mostly implements the Teredo: Tunneling IPv6 over UDP through NAT Internet proposed standard (RFC 4380) - in short it turns your home connection into an IPv6 client.

To get started install the package:

gold:~# apt-get install miredo

Once you've done that wait a few seconds and you should find that you'll have a new tap device:

gold:~# /sbin/ifconfig 
br0       Link encap:Ethernet  HWaddr 00:1c:25:36:5f:f2
...
...

eth0      Link encap:Ethernet  HWaddr 00:1c:25:36:5f:f2
...
...

teredo    Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
...

Here you can see the tunnel end-point, and we can test it out easily enough:

skx@gold:~$  ping6 -c 3 www.debian-administration.org
PING www.debian-administration.org(2002:5910:a162::1) 56 data bytes
64 bytes from 2002:5910:a162::1: icmp_seq=1 ttl=56 time=169 ms
64 bytes from 2002:5910:a162::1: icmp_seq=2 ttl=56 time=167 ms
64 bytes from 2002:5910:a162::1: icmp_seq=3 ttl=56 time=167 ms

--- www.debian-administration.org ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2010ms
rtt min/avg/max/mdev = 167.446/168.201/169.509/1.042 ms

Now for fun you can point your web browser at http://ipv6.google.com or any other IPv6 enabled website.


This article can be found online at the Debian Administration website at the following bookmarkable URL (along with associated comments):

This article is copyright 2008 Steve - please ask for permission to republish or translate.