#!/bin/bash # sets the IPv6 routes correctly # from the 6to4 tunnel # the 6to4 tunnel interface SITDEV="sit0" # LAN interface LANDEV="eth0" # our private subnet suffix (without the first 48 bits) PRIV="1111::/64" # 6to4 addresses start with 2002: and give us a complete /48 subnet # For LANDEV we use a /64 PRIV subnet out of this one. # Our current tunnel 6to4 IP (2002:xxxx:yyyy::1/16) # where xxxx:yyyy is our IPv4 IP IP6=$(ip addr show dev ${SITDEV} scope global to 2002::/8 | awk '$1=="inet6" { print $2; }') if [ -z "${IP6}" ]; then # no IP exit; fi # the /48 subnet (2002:xxxx:yyyy:) NET48="${IP6:0:15}" # our route prefix (2002:xxxx:yyyy:PRIV) PREFIX="${NET48}${PRIV}" # Current route (2002:xxxx:yyyy:SUBNET::/64) CUR_ROUTE=$(ip -6 route list dev ${LANDEV} | awk '$1~/^2002:/ { print $1; }' ) if [ "${CUR_ROUTE:0:15}" = "${NET48}" ]; then # the route is uptodate exit; elif [ ! -z "${CUR_ROUTE}" ]; then # route is outdated ip -6 route del "${CUR_ROUTE}" fi ip -6 route add "${PREFIX}" dev "${LANDEV}"