IPv6 over IPv4 on Linux using 6to4

Attention: open in a new window. PDFPrintE-mail


# set the interface name

# calculate the IPv6 address
ipv4=`/sbin/ifconfig $if | grep "inet addr" | sed -e 's/^. *inet addr://' | sed 
-e 's/ .*$//'`
ipv4s=`echo $ipv4 | tr "." " "`

ipv6=`printf "2002:%02x%02x:%02x%02x::1" $ipv4s `

case "$1" in
/sbin/ip tunnel add tun6to4 mode sit ttl 128 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 :: dev tun6to4 metric 1
# configure firewall
/sbin/ip6tables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/ip6tables -A INPUT -j DROP
/sbin/ip -6 route flush dev tun6to4
/sbin/ip link set dev tun6to4 down
/sbin/ip tunnel del tun6to4
# clear firewall
/sbin/ip6tables -F INPUT
    echo "usage: ipv6 {start|stop}"
    exit 1

exit 0

This will create a new interface ‘tun6to4’ which will be used for IPv6.