Skip to content

Instantly share code, notes, and snippets.

@z4yx
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z4yx/0a5362ef7bdec744442a to your computer and use it in GitHub Desktop.
Save z4yx/0a5362ef7bdec744442a to your computer and use it in GitHub Desktop.
Tsinghua IPv6 Tunnel
#!/bin/sh
echo "Content-type: text/plain"
echo ""
ifconfig eth0.2
#!/bin/bash
export PATH="$PATH:/sbin"
isatap_gateway=166.111.21.1
sit_dev=sit2
v6_prefix=2402:f000:1:1501:200:5efe
#v6_router=2402:f000:1:1501:200:5efe:166.111.21.1
v6_router=2402:f000:1:1501::1
local_ip=$(ifconfig eth0|grep -Po '(?<=inet addr:)(\d+\.?){4}')
global_ip=$(curl --silent ip.cn|grep -Po '(\d+\.?){4}')
echo "local address: $local_ip"
echo "global address: $global_ip"
if [ "x$global_ip" == x ];then
echo "empty global address"
exit 1
fi
ip tunnel del $sit_dev
ip tunnel add $sit_dev mode sit remote $isatap_gateway local $local_ip
ifconfig $sit_dev up
ifconfig $sit_dev add $v6_prefix:$global_ip/64
ip route add ::/0 via $v6_router metric 1
#!/bin/bash
if [ x$1 == x ];then
ifce=en0
else
ifce=$1
fi
if [ x$2 == x ];then
sit_num=1
else
sit_num=2
fi
if [ $sit_num == 2 ];then
ip6=2402:f000:1:1501:200:5efe
ip6_router=2402:f000:1:1501:200:5efe:166.111.21.1
ip4_router=166.111.21.1
else
ip6=2001:da8:200:900e:0:5efe
ip6_router=2001:da8:200:900e::1
ip4_router=59.66.4.50
fi
#global_ip=59.66.131.40
#local_ip=$(ifconfig|grep -A 8 'en0'|grep 'inet ' |head -n 1|awk '{ print $2}')
#global_ip=$(ifconfig en0|egrep 'inet (101|59)'|awk '{print $2}')
#local_ip=$global_ip
echo "Tunnel IP: $ip4_router"
echo "Getting global IP"
#global_ip=$(curl --silent ifconfig.me)
global_ip=$(curl --silent ip.cn|grep -E -o '(\d+\.?){4}')
local_ip=$(ifconfig|grep -A 8 $ifce|grep 'inet ' |head -n 1|awk '{ print $2}')
echo "Interface: $ifce"
echo "Global IP address: $global_ip"
echo "Local IP address: $local_ip"
sudo ifconfig gif0 destroy
sudo ifconfig gif0 create
sudo ifconfig gif0 tunnel $local_ip $ip4_router
sudo ifconfig gif0 inet6 $ip6:$global_ip prefixlen 64
sudo route delete -inet6 default
sudo route add -inet6 default $ip6_router
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment