Skip to content

Instantly share code, notes, and snippets.

@isofew
Last active October 31, 2022 20:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isofew/3cb7dbfc318b9beba4ba67fc847dc1a8 to your computer and use it in GitHub Desktop.
Save isofew/3cb7dbfc318b9beba4ba67fc847dc1a8 to your computer and use it in GitHub Desktop.
dynamic ipip6 tunnel setup script
#!/bin/sh
TAP=tap0 # the IPv6 interface which, in my case, is a tap device
TUN=tun0 # the tunnel interface you are about to create
# address @ tap
REMOTE= # your server's address goes here
LOCAL=`ifconfig $TAP | grep inet6 | grep -v fe80 | head -1 | awk '{print $3}'`
# address @ tun
TUN_REMOTE=10.7.0.1
TUN_LOCAL=10.7.0.2
if [ -z $LOCAL ]; then
exit 1 # no ipv6 address
fi
ping -c1 -w1 $TUN_REMOTE
if [ $? == 0 ]; then
exit 1 # already connected
fi
sleep 10
ssh $REMOTE "
ip -6 tunnel del $TUN
ip -6 tunnel add $TUN mode ipip6 remote $LOCAL local $REMOTE
ifconfig $TUN $TUN_REMOTE pointopoint $TUN_LOCAL
"
ip -6 tunnel del $TUN
ip -6 tunnel add $TUN mode ipip6 remote $REMOTE local $LOCAL
ifconfig $TUN $TUN_LOCAL pointopoint $TUN_REMOTE
ip route add 8.8.8.8 via $TUN_REMOTE
# and more routes...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment