6to4

From LQWiki
Jump to navigation Jump to search

6to4 is a name for an IPv6-over-IPv4 tunneling mechanism. What makes this method special is that it doesn't require manually configuring a ipv6-over-ipv4 tunnel. Instead these tunnels are dynamically built between 6to4 hosts and traffic going to native ipv6 addresses go to an automatically selected nearby 6to4 relay router (by use of an anycast address). This makes this method easy and quick to setup.

All 6to4 hosts have a special ipv6 addresses, which have the '2002::/16' prefix. The following 32 bits of the address is the hosts ipv4 address, The rest of the address can be used freely, giving the user a whole /48 network to use, based on 1 ipv4 address. 6to4 relay routers are advertised on the anycast ipv4 prefix of 192.88.99.0/24, the address used for the nearest relay router is 192.88.99.1, or in 6to4 address as 2002:c058:6301::

Configuration

Needed are:

  • IPv4 address
  • IPv6 support for the kernel (the kernel module for this is called 'ipv6')
  • IPv6 tools (ip or ifconfig/route with ipv6 support)
  • some IPv6 capable applications to test it out (e.g. ping6,nc6,etc)

Calculate 6to4 host address

The address can be calculated by translating the decimal numbers of the ipv4 address to hex, adding the 2002: prefix, and picking something for the remaining bits (doesn't matter what you choose). For example:

Ipv4 address in decimal notation: 192.168.1.2

Now translate each decimal to hex

Translated to hex it becomes: C0 A8 01 02

Add prefix and write it in common ipv6 notation:

6to4 ipv6 address becomes: 2002:c0a8:0102:: (the last 16 bits can be anything, in this case it's 0000:0000, which can be written as :: )

Another way to calculate it with help of the printf command:

$ printf "2002:%02x%02x:%02x%02x::\n"  ` echo <YOUR_IPV4_ADDR> | tr "." " " `

Configuring network

This section will give the manual way of configuring it by using the 'ip' command (normally comes in a package called iproute). It can also be done with the 'ifconfig' and 'route' commands or by using some distribution specific network configuration mechanism.

Bring up the sit0 device (the sit device is a generic tunnel device):

# ip link set sit0 up 

Add 6to4 address to device:

# ip addr add <YOUR 6TO4 ADDR> dev sit0

Add a route to the 6to4 relay routers:

# ip route add 2000::/3 via ::192.88.99.1

And that's it, you now should be able to use ping6 or some other ipv6-capable application to test it out.