v4-to-v6 tunnel under KVM/dedi/OpenVZ
===
There are a few different method, for each different container. I think I've found the best methods for each, with tunnelbroker.net 6to4 tunnel && debian/Ubuntu

- Note! For IRC usage, due to the large amount of abuse in accordance with tunnelbroker tunnels on IRC networks, tunnelbroker.net has disabled IRC traffic on their tunnels by default. This means you need ot signup for their certification test, (free), complete all test and get `Sage` certification. Once you get that, you can go into your system-specific tunnel, go to configuration, and enabled IRC usage on that tunnel. Easy as that!


OpenVZ
===

With OpenVZ, setting up a tunnel is quite a bit harder. This is because a lot of things are limited with the OVZ setup, to create dynamicy within kernel bounds.

 - Create a tunnel at tunnelbroker.net
 > Hurricane Electric allows creation of up to 5 free IPv6 tunnels @ tunnelbroker.net.
 - Create one for your VPS.
 - Enable TUN/TAP on your VPS.
 > It should normally be possible to do this through your control panel (e.g., SolusVM).
 > If not, a support ticket with your provider should get it done fairly quickly.
 > Be advised that toggling this option forces a reboot. So plan accordingly.
 - tb-tun (tb-userspace)
 > tb-tun is a userspace program that utilizes TUN/TAP to build a tunnelbroker tunnel on linux.
 > Since we can’t do it any other way on a OpenVZ VPS.

```sh
sudo apt-get install iproute gcc
cd /root
wget http://tb-tun.googlecode.com/files/tb-tun_r18.tar.gz
tar -xf tb-tun_r18.tar.gz
gcc tb_userspace.c -l pthread -o tb_userspace
```


 - Create a new init script: `nano /etc/init.d/ipv6tb` and put in the following contents (after replacing the correct IP addresses, of course)
 > Remember, for the tunnel, your VPS IP is the client and the Hurricane Electric IP is the server.


```sh
#! /bin/sh
 
### BEGIN INIT INFO
# Provides:          ipv6
# Required-Start:    $local_fs $all
# Required-Stop:     $local_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the ipv6 tunnel 
# Description:       ipv6 tunnel start-stop-daemon
### END INIT INFO
 
# /etc/init.d/ipv6tb
 
touch /var/lock/ipv6tb
 
case "$1" in
  start)
    echo "Starting ipv6tb "
      setsid /root/tb_userspace tb [Server IPv4 Address] [Client IPv4 Address] sit > /dev/null 2>&1 &
      sleep 3s #ugly, but doesn't seem to work at startup otherwise
      ifconfig tb up
      ifconfig tb inet6 add [Client IPv6 Address]/64
      ifconfig tb inet6 add [Routed /64]::1/64 #Add as many of these as you need from your routed /64 allocation
      ifconfig tb mtu 1480
      route -A inet6 add ::/0 dev tb
      route -A inet6 del ::/0 dev venet0
    ;;
  stop)
    echo "Stopping ipv6tb"
      ifconfig tb down
      route -A inet6 del ::/0 dev tb
      killall tb_userspace
    ;;
  *)
    echo "Usage: /etc/init.d/ipv6tb {start|stop}"
    exit 1
    ;;
esac
 
exit 0
```
 - Make it executable, and add it to startup: `chmod 0755 /etc/init.d/ipv6tb` then `update-rc.d ipv6tb defaults`

- Execute it right away: `/etc/init.d/ipv6tb start` OR simply reboot.
- Test to confirm that IPv6 connectivity is working: `ping6 -c 5 google.com`

KVM (Or of the liking)
===
Credits for this simple script go to ChauffeR

```php
<?php
    $v6 = "2001:470:1f12:500"; // Server IPv6 (without prefix)
    $server_ipv4 = "216.66.84.42"; // Server IPv4 (obviously)
    $bind = "2001:470:c957"; // Routed /64 or /48 (without prefix)
    
    shell_exec("ip tun del sit1");
    shell_exec("ifconfig sit0 up;ifconfig sit0 inet6 tunnel ::".$server_ipv4.";ifconfig sit1 up");
    for($i=5; $i<505; $i++){
            shell_exec("ifconfig sit1 inet6 add ".$bind."::".$i."/64");
            sleep(0.2);
    }
    shell_exec("ifconfig sit1 inet6 add ".$v6."::/64");
    shell_exec("route -A inet6 add ::/0 dev sit1");
?>
```

This will bind 500 or so of the first chunk of your IPv6. This can be put into a crontab at startup.
Note, that this will also need php5-cli (`sudo apt-get install php5 php5-cli`)
