Linux IPv6 基于策略的路由失败

Linux IPv6 基于策略的路由失败

我有一台 VPN 服务器,用作我的 IPv6 互联网连接。设置如下:

我已分配了一个 /48 地址池,我想将其划分为 VPN 客户端的子网。为了便于论述,我们将其称为池2001:DB8:CAFE::/48

我将该网络分为以下部分: 2001:DB8:CAFE::/64分配给 VPN 服务器和每个客户端之间的实际 VPN 链接。

    “2001:DB8:CAFE:100:/56” 被分配给客户端 1 后面的网络
    “2001:DB8:CAFE:200:/56” 被分配给客户端 2 后面的网络

这给出了以下布局:

+--------------+ 2001:470:xxxx:xxx::/64 +---------------+ /-> 客户端 1 网络(2001:DB8:CAFE:100::/56)
| + <-- Tunnelbroker 链接 -> + | /
| 互联网 | | 我的 VPN 服务器 + <-*---> VPN 链接 - 网络拓扑 (2001:DB8:CAFE::/64)
| + <- 原生 IPv6 链接 ---> + | \
+--------------+ 2a01:xxxx:xxxx:xxxx::/48 +---------------+ \-> 客户端 2 网络(2001:DB8:CAFE:200::/56)

我希望所有来自的流量2001:DB8:CAFE::/48都通过我的Tunnelbroker链路路由 -仅有的那个链接

这让我想到了以下脚本:

# Reset IPv6 routing table.
ip -6 rule flush

# Reset Tunnelbroker routing table (table name: "he-ipv6").
ip -6 route flush table he-ipv6

# Add routeable VPN subnets to Tunnelbroker routing table
ip -6 rule add from 2001:DB8:CAFE::/48 table he-ipv6

# Any traffic that originates from VPN has to be forwarded via Tunnelbroker routing table 
# using the tunnelbroker link (link name: he-ipv6).
ip -6 route add default via 2001:470:xxxx:xxx::1 dev he-ipv6 table he-ipv6

# Add default IPv6 rules again - since they gets deleted by the initial rule flush command.
ip -6 rule add priority 32766 from all table main

但是:当我运行 -command 时ip -6 route add default ...出现以下错误:

RTNETLINK answers: No route to host

问题是2001:470:xxxx:xxx::1在我运行脚本之前可以 ping 通,但之后就不能了。

我错过了什么?

答案1

命令顺序事宜

该命令不起作用的原因ip -6 route add default via 2001:470:xxxx:xxx::1 dev he-ipv6 table he-ipv6是路线是在main表中定义的。

但由于初始刷新命令删除了主表,因此必须再次添加它你执行ip route default命令。

因此正确的脚本是:

# Reset IPv6 routing table.
ip -6 rule flush

# Add default IPv6 rules again - since they gets deleted by the initial rule flush command.
ip -6 rule add priority 32766 from all table main

# Reset Tunnelbroker routing table (table name: "he-ipv6").
ip -6 route flush table he-ipv6

# Add routeable VPN subnets to Tunnelbroker routing table
ip -6 rule add from 2001:DB8:CAFE::/48 table he-ipv6

# Remember to add a rule that if no machine does not respond to a 
# packet address in my /48, then we should return unreachable. 
# Else the package will be forwarded by default out through the 
# Hurricane Electric connection.

#(From the Internet)
ip -6 route add unreachable 2001:DB8:CAFE::/48

#(From my /48 subnet)
ip -6 route add unreachable 2001:DB8:CAFE::/48 table he-ipv6

# Any traffic that originates from VPN has to be forwarded via Tunnelbroker routing table 
# using the tunnelbroker link (link name: he-ipv6).
ip -6 route add default via 2001:470:xxxx:xxx::1 dev he-ipv6 table he-ipv6

我将在这里保留问题和答案,因为我可能不是唯一一个尝试基于源进行 IPv6 路由的人。

我发现的有关这个主题的最新信息是 2010 年的。

相关内容