从网络命名空间Ping外部IPv6地址



我需要从网络命名空间访问外部IPv6地址。

在我的主机中,我设置了一个SIT隧道(IPv6-In-IPv4),它对IPv6数据包进行隧道传输,并通过默认接口(eth0)发送。SIT隧道依赖Hurricane Electric隧道经纪服务。我可以从主机ping外部IPv6地址。

$ ping6 ipv6.google.com
PING ipv6.google.com(lis01s13-in-x0e.1e100.net) 56 data bytes
64 bytes from lis01s13-in-x0e.1e100.net: icmp_seq=1 ttl=57 time=98.1 ms
64 bytes from lis01s13-in-x0e.1e100.net: icmp_seq=2 ttl=57 time=98.7 ms

以下是关于隧道的一些细节:

$ ip -6 route sh
2001:470:1f14:10be::/64 dev he-ipv6  proto kernel  metric 256
default dev he-ipv6  metric 1024

有趣的部分来了。由于超出这个问题范围的原因,我需要在网络名称空间内做同样的事情(ping ipv6.google.com)。

以下是我如何创建和设置我的网络名称空间:

ns1.sh

#!/bin/bash
set -x
if [[ $EUID -ne 0 ]]; then
   echo "You must run this script as root."
   exit 1
fi
# Create network namespace 'ns1'.
ip netns del ns1 &>/dev/null
ip netns add ns1
# Create veth pair.
ip li add name veth1 type veth peer name vpeer1
# Setup veth1 (host).
ip -6 addr add fc00::1/64 dev veth1
ip li set dev veth1 up
# Setup vpeer1 (network namespace).
ip li set dev vpeer1 netns ns1
ip netns exec ns1 ip li set dev lo up
ip netns exec ns1 ip -6 addr add fc00::2/64 dev vpeer1
ip netns exec ns1 ip li set vpeer1 up
# Make vpeer1 default gw.
ip netns exec ns1 ip -6 route add default dev vpeer1
# Get into ns1.
ip netns exec ns1 /bin/bash --rcfile <(echo "PS1="ns1> "")

然后,我从"ns1"运行ns1.sh并ping veth1(fc00::1)vpeer1(fc00::2)。

ns1> ping6 fc00::1
PING fc00::1(fc00::1) 56 data bytes
64 bytes from fc00::1: icmp_seq=1 ttl=64 time=0.075 ms
^C
ns1> ping6 fc00::2
PING fc00::2(fc00::2) 56 data bytes
64 bytes from fc00::2: icmp_seq=1 ttl=64 time=0.056 ms

但是,如果我尝试ping外部IPv6地址:

ns1> ping6 2a00:1450:4004:801::200e
PING 2a00:1450:4004:801::200e(2a00:1450:4004:801::200e) 56 data bytes
^C
--- 2a00:1450:4004:801::200e ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1008ms

所有数据包都丢失了。

我用tcpdump打开了veth1并检查了发生了什么。我看到邻居请求数据包正在到达接口。这些数据包试图解析IPv6目的地地址的MAC地址:

$ sudo tcpdump -qns 0 -e -i veth1
IPv6, length 86: fc00::2 > ff02::1:ff00:200e: ICMP6, neighbor solicitation,
   who has 2a00:1450:4004:801::200e, length 32
IPv6, length 86: fc00::2 > ff02::1:ff00:200e: ICMP6, neighbor solicitation,
   who has 2a00:1450:4004:801::200e, length 32

我真的不明白为什么会发生这种事。我也在主机中启用了IPv6转发,但没有效果:

$ sudo sysctl -w net.ipv6.conf.default.forwarding=1

感谢您阅读此问题。建议欢迎:)

编辑:

主机中的路由表:

2001:470:1f14:10be::/64 dev he-ipv6  proto kernel  metric 256 
fc00::/64 dev veth1  proto kernel  metric 256 
default dev he-ipv6  metric 1024

我在主机中添加了一个NDP代理,它解决了NDP请求。仍然无法从nsnet访问地址(对此进行调查):

sudo sysctl -w net.ipv6.conf.all.proxy_ndp=1
sudo ip -6 neigh add proxy 2a00:1450:4004:801::200e dev veth1

ULA不可路由

您已为网络命名空间指定了一个唯一本地地址(fc00::2):此IP地址在全球互联网中不可路由,只能在您的本地网络中路由。

当您的ISP收到来自此地址的ICMP数据包时,它会将其丢弃。即使此数据包成功到达ipv6.google.com,它也不可能将答案发送回您,因为此IP地址没有公布的路由。

路由表问题(NDP通知)

你收到NDP通知是因为这行:

ip netns exec ns1 ip -6 route add default dev vpeer1

它告诉内核(在netns中)所有IP地址都直接连接在CCD_ 2接口上。内核认为这个IP地址存在于以太网链路上:这就是它试图用NDP解析其MAC地址的原因。

相反,你想说它们可以通过给定的路由器访问(在你的情况下,路由器就是你的主机):

ip netns exec ns1 ip -6 route add default dev vpeer1 via $myipv6

解决方案

您可以:

  • 公共IPv6地址(您的公共IPv6前缀)与您的网络关联,并在主机上为地址设置NDP代理;

  • subnet您的IPv6前缀,并将子网路由到您的主机(如果可以的话);

  • 使用NAT(糟糕,丑陋,不要那样做)。

你应该能够使用这样的东西来实现第一个:

#!/bin/bash
set -x
myipv6=2001:470:1f14:10be::42
peeripv6=2001:470:1f14:10be::43
#Create the netns:
ip netns add ns1
# Create and configure the local veth:
ip link add name veth1 type veth peer name vpeer1
ip -6 address add $myipv6/128 dev veth1
ip -6 route add $peeripv6/128 dev veth1
ip li set dev veth1 up
# Setup vpeer1 in the netns:
ip link set dev vpeer1 netns ns1
ip netns exec ns1 ip link set dev lo up
ip netns exec ns1 ip -6 address add $peeripv6/128 dev vpeer1
ip netns exec ns1 ip -6 route add $myipv6/128 dev vpeer1
ip netns exec ns1 ip link set vpeer1 up    
ip netns exec ns1 ip -6 route add default dev vpeer1 via $peeripv6
# IP forwarding
sysctl -w net.ipv6.conf.default.forwarding=1
# NDP proxy for the netns
ip -6 neigh add proxy $myipv6 dev veth1

最新更新