Skip to content

Instantly share code, notes, and snippets.

@tstromberg
Created January 28, 2021 20:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tstromberg/498bbe1bc8df756b3d75dc0ba30f8f2a to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Sonic & he.net tunnel configuration script, appropriate for usage in
# dhcp-exit-hooks. Tested on FreeBSD 12.2-STABLE
set -x -u -e
if [ "$1" = "he" ]; then
server_v4="72.52.104.74"
server_v6="2001:470:803d::1"
client_v6="2001:470:803d::2"
prefixlen=128
int_gateway="2001:470:803d:1024::1"
lab_gateway="2001:470:803d:cafe::1"
elif [ "$1" = "sonic" ]; then
server_v4="208.201.234.221"
server_v6="2001:05a8:0000:0001:0000:0000:0000:28aa"
client_v6="2001:05a8:0000:0001:0000:0000:0000:28ab"
prefixlen=127
int_gateway="2001:5a8:4:320::1"
lab_gateway="2001:5a8:4:321::1"
else
echo "please specify 'he' or 'sonic'"
fi
# DHCP makes me sad
client_v4=$(ifconfig em2| grep inet | awk '{print $2 }')
# Configure internal gateway IP's
ifconfig igb0 inet6 "${int_gateway}" prefixlen 64
ifconfig em0 inet6 "${lab_gateway}" prefixlen 64
ifconfig gif0 destroy
ifconfig gif0 create
ifconfig gif0 tunnel "${client_v4}" "${server_v4}"
# This seems crazy - is it necessary?
if [ "${prefixlen}" = 128 ]; then
ifconfig gif0 inet6 "${client_v6}" "${server_v6}" prefixlen "${prefixlen}"
else
ifconfig gif0 inet6 "${client_v6}/${prefixlen}"
fi
route -n add -inet6 default "${server_v6}"
ifconfig gif0 up
echo "${int_gateway} and ${lab_gateway} should be routable"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment