-
-
Save djeraseit/68ee5bb9089656aac1c05d252cc4af47 to your computer and use it in GitHub Desktop.
tunnelbroker.net automatic tunnel IP update and tunnel setup (on Linux)
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/bash | |
# This script is published by Philipp Klaus <philipp.l.klaus@web.de> | |
# on <http://blog.philippklaus.de/2011/05/ipv6-6in4-tunnel-via-hurricane-electric-tunnelbroker-net-automatic-ip-update-on-mac-os-x/> | |
# It is originally by freese60 and modified by limemonkey. | |
# Found on <http://www.tunnelbroker.net/forums/index.php?topic=287.0> | |
# Further modified by pklaus, at <https://gist.github.com/pklaus/960672> | |
# Forked and mostly replaced by W-Floyd, <https://gist.github.com/W-Floyd/20a4c16ceb1e008cb995b7ff7dcc0a2a> | |
############################################################################### | |
TUNNELNAME='he-ipv6' | |
DEVNAME="$(ip route | grep default | tr -s ' ' | cut -d ' ' -f 5 | head -n 1)" | |
#DEVNAME='tun0' # If using a VPN to a static address, since I'm too lazy to get it working behind a NAT. | |
LOCAL_IPV4="$(ip addr show "${DEVNAME}" | grep 'inet ' | tr -s ' ' | cut -d ' ' -f 3 | sed 's#/.*##')" | |
echo -n "Getting external IP" | |
EXTERNAL_IPV4="$(curl -s 'https://canihazip.com/s')" | |
echo ": ${EXTERNAL_IPV4}" | |
# The username you use to login at tunnelbroker.net | |
HEUSER='you_user_name' | |
# This 'Update Key' can be found on the 'Advanced' tab of the tunnel details page. | |
HEKEY='your_update_key' | |
# The 'Tunnel ID' from the tab IPv6 tunnel on the tunnel details page. | |
HETUNNEL='your_tunnel_id' | |
# Tunnel settings | |
HESERVER4END='216.66.84.42' | |
HECLIENT6END='2001:470:1f12:c78::2/64' | |
############################################################################### | |
# Get root permission | |
############################################################################### | |
sudo true || exit 1 | |
############################################################################### | |
# Remove the interface if it exists | |
############################################################################### | |
if [ "$(grep "${TUNNELNAME}" <<< "$(ifconfig -l | tr ' ' '\n' )")" ]; then | |
echo "Removing previous tunnel." | |
sudo ip -6 route del ::/0 dev "${TUNNELNAME}" | |
sudo ip link set "${TUNNELNAME}" down | |
sudo ip tunnel del "${TUNNELNAME}" | |
echo "Done removing previous tunnel." | |
fi | |
############################################################################### | |
echo "Updating IPv4 tunnel endpoint setting with Hurricane Electric." | |
curl "https://${HEUSER}:${HEKEY}@ipv4.tunnelbroker.net/nic/update?hostname=${HETUNNEL}&myip=${EXTERNAL_IPV4}" 1&> /dev/null | |
echo "Setting up tunnel." | |
sudo ip tunnel add "${TUNNELNAME}" mode sit remote "${HESERVER4END}" local "${LOCAL_IPV4}" ttl 255 | |
sudo ip link set "${TUNNELNAME}" up | |
sudo ip addr add "${HECLIENT6END}" dev "${TUNNELNAME}" | |
sudo ip -6 route add ::/0 dev "${TUNNELNAME}" | |
echo "Done setting up tunnel." | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment