#! /bin/sh # # local-ipv6-networking - sets up IPv6 networking using a 6to4 tunnel # # Copyright 2004 by Nathaniel W. Turner # This program is published under GNU GPL version 2. # See: http://www.gnu.org/licenses/gpl # # Depends: iproute, perl # # This script sets up a 6to4 tunnel for IPv6 networking from any IPv4 machine. # The IPv6 prefix is determined at runtime, making this script suitable for # workstations that get their IPv4 address from DHCP. # It can be installed in /usr/local/sbin and called from # /etc/network/interfaces or installed in /etc/init.d and used as a sysv # initscript. # # Example usage with /etc/network/interfaces (recommended): # # iface eth0 inet dhcp # up /usr/local/sbin/local-ipv6-networking up eth0 # down /usr/local/sbin/local-ipv6-networking down eth0 # PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin NAME=local-ipv6-networking DESC="IPv6 networking (6to4 tunnel)" DEFAULT_IPV4_IF=eth0 # Gracefully exit if the iproute package has been removed. test -x /bin/ip || exit 0 set -e # Uncomment the following line for debugging: #set -x # determines the ipv4 interface if [ -n "$2" ]; then my_ipv4_if=$2 else my_ipv4_if=$DEFAULT_IPV4_IF fi # gets our primary IPv4 address my_ipv4_addr=`ip -4 addr show dev $my_ipv4_if primary \ | perl -ne 'print $1 if /^\ *inet (\d+(?:\.\d+){3})/'` # builds an IPv6 prefix from our IPv4 address # (from http://tldp.org/HOWTO/Linux+IPv6-HOWTO/ section 9.4.1) my_ipv6_prefix=`printf "2002:%02x%02x:%02x%02x" \ \`echo $my_ipv4_addr | tr "." " "\`` function ipv6_up { # ensures the ipv6 kernel module is loaded modprobe ipv6 # sets up 6to4 tunnel # (from http://tldp.org/HOWTO/Linux+IPv6-HOWTO/ section 9.4.1.1) ip tunnel add tun6to4 mode sit ttl 64 remote any local $my_ipv4_addr ip link set dev tun6to4 up ip -6 addr add ${my_ipv6_prefix}::1/16 dev tun6to4 ip -6 route add 2000::/3 via ::192.88.99.1 dev tun6to4 metric 1 ip -6 addr add ${my_ipv6_prefix}::1/128 dev $my_ipv4_if # add any extra setup configuration here: #ip -6 route add ${my_ipv6_prefix}:f00d::/64 dev eth1 proto static } function ipv6_down { # add any extra take-down configuration here: #ip -6 route del ${my_ipv6_prefix}:f00d::/64 dev eth1 proto static # brings down 6to4 tunnel # (from http://tldp.org/HOWTO/Linux+IPv6-HOWTO/ section 9.4.2.1) ip -6 addr del ${my_ipv6_prefix}::1/128 dev $my_ipv4_if ip -6 route flush dev tun6to4 ip -6 addr del ${my_ipv6_prefix}::1/16 dev tun6to4 ip link set dev tun6to4 down ip tunnel del tun6to4 } case "$1" in up) ipv6_up ;; down) ipv6_down ;; start) echo -n "Starting $DESC: $NAME" ipv6_up echo "." ;; stop) echo -n "Stopping $DESC: $NAME " ipv6_down echo "." ;; restart|force-reload) echo -n "Restarting $DESC: $NAME" ipv6_down sleep 1 ipv6_up echo "." ;; *) N=/etc/init.d/$NAME # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2 echo "Usage: $N {start|stop|restart|force-reload} [ipv4-iface]" >&2 exit 1 ;; esac exit 0