Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to configure an ipv6 6rd tunnel
#!/bin/sh
## You must have a real routable IPv4 address for IPv6 rapid deployment (6rd)
## tunnels.
## Also make sure you have at least linux kernel 2.6.33 and you have enabled 6rd
## CONFIG_IPV6_SIT_6RD=y
PREFIX="2a02:2b64" # 6rd ipv6 prefix
GATEWAY=`dig +short 6rd.on.net.mk` # 6rd gateway host
modprobe sit
## Try to autodetect the local ipv4 address
MYIPV4=`ip -o route get 8.8.8.8 | sed 's/.* src \([0-9.]*\) .*/\1/'`
## Generate an IPv6-RD address
MYIPV4_nodots=`echo ${MYIPV4} | tr . ' '`
IPV6=`printf "${PREFIX}:%02x%02x:%02x%02x::1" ${MYIPV4_nodots}`
## Setup the tunnel, it will create an interface named '6rd'
ip tunnel add 6rd mode sit local ${MYIPV4} ttl 64
ip tunnel 6rd dev 6rd 6rd-prefix ${PREFIX}::/32
ip addr add ${IPV6}/32 dev 6rd
ip link set 6rd up
ip route add ::/0 via ::${GATEWAY} dev 6rd
## IPv6-rd allows you to have IPv6 network in your LAN too. Uncomment the
## following 3 lines on your Linux router and set the correct LAN interface.
## You might also want to run the 'radvd' sevice to enable IPv6 auto-configuration
## on the LAN.
# sysctl -w net.ipv6.conf.all.forwarding=1
# LANIF=eth0
# ip addr add ${IPV6}/64 dev ${LANIF}
@gdamjan

This comment has been minimized.

Copy link
Owner Author

gdamjan commented Aug 12, 2011

Setting a 6rd gateway is the same, except that you give it an address of $PREFIX::1/32 (don't need to generate the IPv6-RD address) and you don't add a default gw to the 6rd interface. The gateway host should have it's own IPv6 connectivity and it should have that $PREFIX::/32 network routed to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.