Last active
October 31, 2022 20:00
-
-
Save isofew/3cb7dbfc318b9beba4ba67fc847dc1a8 to your computer and use it in GitHub Desktop.
dynamic ipip6 tunnel setup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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