Skip to content

Instantly share code, notes, and snippets.

@dpino
Created April 29, 2016 22:19
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Create Network Namespace with IPv6 connectivity via Hurricane Electric tunnel (no NAT66 needed)
#!/usr/bin/env bash
set -x
if [[ $EUID -ne 0 ]]; then
echo "You must run this script as root."
exit 1
fi
# Fill up IPv6 addresses for the veth pair. Addresses must belong to the
# IPv6 block leased by Hurricane Electric. For instance: 2001:XXXX::101/64.
VETH1_IPV6= # IPv6 address for the host side.
VPEER1_IPV6= # IPv6 address for the network namespace side.
# Clean up.
ip netns del ns-ipv6 &>/dev/null
ip li del veth1 &> /dev/null
# Create network namespace.
ip netns add ns-ipv6
# Create veth pair.
ip li add name veth1 type veth peer name vpeer1
# Setup veth1 (host).
ip -6 addr add ${VETH1_IPV6} dev veth1
ip -6 route add ${VPEER1_IPV6}/128 dev veth1
ip li set dev veth1 up
# Setup vpeer1 (network namespace).
ip li set dev vpeer1 netns ns-ipv6
ip netns exec ns-ipv6 ip li set dev lo up
ip netns exec ns-ipv6 ip -6 addr add ${VPEER1_IPV6} dev vpeer1
ip netns exec ns-ipv6 ip -6 route add ${VETH1_IPV6}/128 dev vpeer1
ip netns exec ns-ipv6 ip li set vpeer1 up
# Direct external traffic to VETH1 through VPEER1 (default gw).
ip netns exec ns-ipv6 ip -6 route add default dev vpeer1 via ${VETH1_IPV6}
# IP Forwarding.
sysctl -w net.ipv6.conf.all.forwarding=1
# Get into ns-ipv6.
ip netns exec ns-ipv6 /bin/bash --rcfile <(echo "PS1=\"ns-ipv6> \"")
Copy link

ghost commented Oct 6, 2017

Is there a special requirement for this script to work?

I tried with NAT version (https://gist.github.com/dpino/76b0bf7f522bd0d2e442eca06ae9db76) and worked fine, but with this one, I only got timeout with $ ping -6

No connectivity at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment