Skip to content

Instantly share code, notes, and snippets.

@kerus1024
Created December 5, 2020 08:24
Show Gist options
  • Save kerus1024/76cd7956a9c983431c720857c2bfe848 to your computer and use it in GitHub Desktop.
Save kerus1024/76cd7956a9c983431c720857c2bfe848 to your computer and use it in GitHub Desktop.
Linux IPv6 in IPv4 Tunnel (Tunnelbroker)
#!/bin/bash
INTERFACE="hev6_tunnel"
SERVERv4_ADDRESS="216.218.226.238"
CLIENTv4_ADDRESS="198.51.100.69"
# Server Tunnel Address for route; Do not enter a prefix here
SERVERv6_TUNADDRESS="2001:470:6969::1"
# Client Tunnel Address; you must have to define a prefix
CLIENTv6_TUNADDRESS="2001:470:6969::2/64"
# Additional v6 Address
ROUTED_FOR_INTERFACE="eth1"
# you must have to define a prefix
ROUTED_IPv6=""
# You need additional settings for firewall
# example: allow IP Protocol 41 (IPv6 Encapsulation) Traffic
# allow traffic from tunnel interface/server ip traffic.
# *All firewall rules for IPv6 should be in place.
ip link set $INTERFACE down
ip tunnel del $INTERFACE
ip route del ::/0 dev $INTERFACE
if [ "$1" = "down" ]; then
echo "The interface $INTERFACE is just down."
exit
fi
modprobe ipv6
ip tunnel add $INTERFACE mode sit remote $SERVERv4_ADDRESS local $CLIENTv4_ADDRESS ttl 255
ip link set $INTERFACE up
ip -6 address add $CLIENTv6_TUNADDRESS dev $INTERFACE
ip -6 route add ::/0 via $SERVERv6_TUNADDRESS dev $INTERFACE
if [ ! -z "$ROUTED_IPv6" ]; then
ip -6 address add $ROUTED_IPv6 dev $ROUTED_FOR_INTERFACE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment