ip4addr=`ip -4 addr \
| egrep inet \
| egrep -v 'inet 127[.]' \
| egrep -v 'inet 10[.]' \
| egrep -v 'inet 172[.]1[6-9][.]' \
| egrep -v 'inet 172[.]2[0-9][.]' \
| egrep -v 'inet 172[.]3[0-1][.]' \
| egrep -v 'inet 192[.]168[.]' \
| tr / ' ' \
| awk '{print $2}'`


IPV4_ADDRESS_REFORMATTED="`echo $ip4addr | tr '.' ' '`"
ip6net=`printf "2002:%02x%02x:%02x%02x::" $IPV4_ADDRESS_REFORMATTED`

echo $ip4addr
echo $ip6net

# 212.238.62.70
# 212.238.57.212
# 2002:D4EE:3E46
#ip6net=2002:D4EE:39D4::
ip6addr=${ip6net}1

# Name of tunnel interface to configure
tunnel=tun6in4

# Kill tunnel if possibly alive (DISABLED)
if false && ip tunnel | egrep --silent "^${tunnel}:"; then
ip tunnel del ${tunnel}
fi

# Flush tunnel from routing table if present
if ip -6 route | egrep --silent " dev ${tunnel} " ; then
ip -6 route flush dev ${tunnel}
ip -6 addr flush dev ${tunnel}
fi

# configure and start the tunnel
ip tunnel add ${tunnel} mode sit ttl 128 remote any local ${ip4addr}
ip -6 addr add ${ip6addr}/16 dev ${tunnel}
ip -6 route add ::/96 dev ${tunnel}
ip -6 route add 2000::/3 via ::192.88.99.1 dev ${tunnel}
ip link set dev ${tunnel} up


## Route and advertise IPv6 addresses on LAN 

