仅对远程对等方使用 IPv6 临时地址

nei*_*owj 7 networking linux ipv6 privacy-extensions

我认为这个问题涉及RFC-3484定义的可配置默认地址选择算法与RFC-4941定义的临时地址之间的交互,尽管该解决方案可能需要某些第三种功能。我的环境是带有 iproute2 实用程序(版本 ss111117)的 Linux(Ubuntu 12.04 上的内核版本 3.2.0)。

如何将我的计算机配置为使用常规的非隐私增强地址连接到相同前缀下的其他节点,但使用临时地址连接到该前缀之外的节点?

例如,假设我的计算机是fuzzy,我的文件服务器是bunny。IPv6 Internet 上的某个地方有一个我想访问的网站nosey.example.com。以下是分配的地址fuzzy

neirbowj@fuzzy:~$ ip -6 addr show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000
    inet6 2001:db8:d00d:babe:6d3b:96d0:f584:beb3/64 scope global temporary dynamic 
       valid_lft 599342sec preferred_lft 80342sec
    inet6 2001:db8:d00d:babe:22fc:11ff:fe53:b2e7/64 scope global dynamic 
       valid_lft 2591986sec preferred_lft 604786sec
    inet6 fe80::22fc:11ff:fe53:b2e7/64 scope link 
       valid_lft forever preferred_lft forever
Run Code Online (Sandbox Code Playgroud)

bunny 具有相同前缀的静态配置地址。

neirbowj@fuzzy:~$ grep bunny /etc/hosts
2001:db8:d00d:babe::1    bunny
Run Code Online (Sandbox Code Playgroud)

nosey.example.com 不在这个前缀上。

neirbowj@fuzzy:~$ host -t aaaa nosey.example.com
nosey.example.com has IPv6 address 2001:db8:b00b:1e5::1
Run Code Online (Sandbox Code Playgroud)

地址标签fuzzy设置为默认值。

neirbowj@fuzzy:~$ ip addrlabel
prefix ::1/128 label 0 
prefix ::/96 label 3 
prefix ::ffff:0.0.0.0/96 label 4 
prefix 2001::/32 label 6 
prefix 2001:10::/28 label 7 
prefix 2002::/16 label 2 
prefix fc00::/7 label 5 
prefix ::/0 label 1 
Run Code Online (Sandbox Code Playgroud)

当我连接到时bunny,我想使用2001:db8:d00d:babe:22fc:11ff:fe53:b2e7,因为它没有被标记为“ temporary”。当我连接到 时nosey.example.com,我想使用2001:db8:d00d:babe:6d3b:96d0:f584:beb3它,因为它标记为“ temporary”。这是可能的,如果是,如何?

我已经阅读了IPv6 源地址选择如何在 Linux 中工作,但我没有看到任何规则将如何影响此选择,甚至根本看不到该temporary标志如何通知地址选择。

我认为我应该能够做到这一点的原因是因为这个摘录。

RFC-4941
Section 3.1 Assumptions

[...]

Finally, this document assumes that when a node initiates outgoing
communication, temporary addresses can be given preference over
public addresses when the device is configured to do so.
[ADDR_SELECT] mandates implementations to provide a mechanism, which
allows an application to configure its preference for temporary
addresses over public addresses.  It also allows for an
implementation to prefer temporary addresses by default, so that the
connections initiated by the node can use temporary addresses without
requiring application-specific enablement.  This document also
assumes that an API will exist that allows individual applications to
indicate whether they prefer to use temporary or public addresses and
override the system defaults.
Run Code Online (Sandbox Code Playgroud)

San*_*ann 4

这似乎是一个奇怪的地方,但在 Linux 中你可以在路由表中做到这一点。

假设您的路由表当前如下所示:

# ip -6 route
2001:db8:d00d:babe::/64 dev eth0  proto kernel  metric 256 
default via 2001:db8:d00d:babe::1 dev eth0  metric 1024 
Run Code Online (Sandbox Code Playgroud)

您可以指定覆盖源地址的路由。在这种情况下你可以这样做:

# ip -6 route add 2001:db8:d00d:babe::/64 \
                  dev eth0 \
                  src 2001:db8:d00d:babe:22fc:11ff:fe53:b2e7 \
                  metric 128
Run Code Online (Sandbox Code Playgroud)

由于该路由的度量低于当前路由(度量为 256),因此它将覆盖它。当您现在连接到该bunny地址时,2001:db8:d00d:babe::1该路由将匹配并且将使用配置的源地址。

如果您还想对其他子网使用特定源地址,您也可以为其创建路由。例如:

# ip -6 route add 2001:db8:d00d::/48 \
                  via 2001:db8:d00d:babe::1 \
                  dev eth0 \
                  src 2001:db8:d00d:babe:22fc:11ff:fe53:b2e7 \
                  metric 128
Run Code Online (Sandbox Code Playgroud)