I would like to create host-only IPv6 networks on two hosts and then route
between them. On each host, there will be a dummy interface, at
ipv6_prefix::9
. I would like to be able to ping that interface from the
other host.
Is there a well-developed best practice for this? It seems reasonable that one could do it with 6in4 tunnels.
Below, I'll work through the setup I tried recently in EC2, using 6in4 to
tunnel. The two hosts are 10.239.143.35
and 10.238.249.113
. First, let's
set up the dummy interfaces. We'll use these Bash functions:
function dummy {
local name="$1" ipv6="$2"
ip link add "$name" type dummy
ip -6 addr add "$ipv6" dev "$name"
ip link set "$name" up
}
function calc6to4 {
printf '2002:%02x%02x:%02x%02x::\n' $(tr '.' ' ' <<<"$@")
}
function eth0ipv4 {
ip addr list dev eth0 | egrep -o 'inet [^/]+' | head -n1 | cut -d' ' -f2
}
(You can just paste these straight in to your shell session.)
On the first host, we run:
:; ipv4="$(eth0ipv4)"
:; ipv6="$(calc6to4 "$ipv4")"
:; echo "ipv4 = $ipv4" "ipv6 = $ipv6"
ipv4 = 10.239.143.35 ipv6 = 2002:0aef:8f23::
:; dummy dummy9 "$ipv6"9
:; ip addr show dev dummy9
69: dummy9: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/ether e2:69:75:10:04:2c brd ff:ff:ff:ff:ff:ff
inet6 2002:aef:8f23::9/128 scope global
valid_lft forever preferred_lft forever
inet6 fe80::e069:75ff:fe10:42c/64 scope link
valid_lft forever preferred_lft forever
Pinging seems to work okay:
:; ping6 -q -c1 "$ipv6"9
PING 2002:0aef:8f23::9(2002:aef:8f23::9) 56 data bytes
--- 2002:0aef:8f23::9 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.040/0.040/0.040/0.000 ms
Now it's on to the second host:
:; ipv4="$(eth0ipv4)"
:; ipv6="$(calc6to4 "$ipv4")"
:; echo "ipv4 = $ipv4" "ipv6 = $ipv6"
ipv4 = 10.238.249.113 ipv6 = 2002:0aee:f971::
:; dummy dummy9 "$ipv6"9
Ping check checks out:
:; ping6 -q -c1 "$ipv6"9
PING 2002:0aee:f971::9(2002:aee:f971::9) 56 data bytes
--- 2002:0aee:f971::9 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.037/0.037/0.037/0.000 ms
Now it's time for the exciting bit: connecting the hosts with 6in4 tunnels. We use the following Bash function on both hosts:
function tunnel {
local name="$1" self_ipv4="$2" ipv4="$3" ipv6="$4"
ip tunnel add "$name" mode sit ttl 64 remote "$ipv4" local "$self_ipv4"
ip -6 addr add "$ipv6"1 dev "$name"
ip -6 route add "$ipv6"/64 dev "$name" metric 1
ip link set "$name" up
}
On the first host:
################################### IPv4 and IPv6 from host 2 ##
:; tunnel tun6in4 10.239.143.35 10.238.249.113 2002:0aee:f971::
On the second:
################################### IPv4 and IPv6 from host 1 ##
:; tunnel tun6in4 10.238.249.113 10.239.143.35 2002:0aef:8f23::
When we try to find a route from the first host to 2002:aee:f971::9
, bound
to the dummy device on the second, we get a hit:
:; ip -6 route get 2002:aee:f971::9
2002:aee:f971::9 from :: dev tun6in4 src 2002:aee:f971::1 metric 0
cache
But pings don't work:
:; ping6 -q -c1 2002:aee:f971::9
PING 2002:aee:f971::9(2002:aee:f971::9) 56 data bytes
--- 2002:aee:f971::9 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
Maybe I need to add an address to eth0
?