public
Created

  • Download Gist
gistfile1.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
#!/bin/bash
 
# This script is modified from the one found here: https://wiki.archlinux.org/index.php/IPv6_-_Tunnel_Broker_Setup
# Noticably this script now runs like this:
# $0 <start|stop> <device name>
#
# So if you want IPv6 traffic to be routed through wlan0, you would do:
# $0 start wlan0
 
if [ "$EUID" -ne 0 ]; then
echo "You must run this as root"
exit 1
fi
 
# Edit these
if_name=he6in4
server_ipv4='' # HE Server Endpoint IP
client_ipv6='' # Your HE-assigned client IP
 
# Don't edit below this line
client_ipv4=''
link_mtu=1480
tunnel_ttl=255
 
if [ -n "$2" ]; then
client_ipv4=$(ifconfig eth0 | grep netmask | awk '{print $2}')
fi
 
if [ -z "$client_ipv4" ]; then
echo "Usage: $0 <start|stop> <device name>"
exit 1
fi
 
echo "Tunneling data from IPv6 to $2 (IP: $client_ipv4)"
 
daemon_name=6in4-tunnel
 
# . /etc/rc.conf
# . /etc/rc.d/functions
 
case "$1" in
start)
# stat_busy "Starting $daemon_name daemon"
 
ifconfig $if_name &>/dev/null
if [ $? -eq 0 ]; then
stat_busy "Interface $if_name already exists"
stat_fail
exit 1
fi
 
ip tunnel add $if_name mode sit remote $server_ipv4 local $client_ipv4 ttl $tunnel_ttl
ip link set $if_name up mtu $link_mtu
ip addr add $client_ipv6 dev $if_name
ip route add ::/0 dev $if_name
# Here is how you would add additional ips....which should be on the eth0 interface
# ip addr add 2001:XXXX:XXXX:beef:beef:beef:beef:1/64 dev eth0
# ip addr add 2001:XXXX:XXXX:beef:beef:beef:beef:2/64 dev eth0
# ip addr add 2001:XXXX:XXXX:beef:beef:beef:beef:3/64 dev eth0
 
add_daemon $daemon_name
stat_done
;;
 
stop)
stat_busy "Stopping $daemon_name daemon"
 
ifconfig $if_name &>/dev/null
if [ $? -ne 0 ]; then
stat_busy "Interface $if_name does not exist"
stat_fail
exit 1
fi
 
ip link set $if_name down
ip tunnel del $if_name
 
rm_daemon $daemon_name
stat_done
;;
 
*)
echo "usage: $0 {start|stop}"
esac
exit 0

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.