Linux 为什么 IPv6 允许具有多个地址的单个接口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9886711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:25:48  来源:igfitidea点击:

Why IPv6 allows a single interface with multiple addresses?

linuxipv6

提问by Simon Gong

"A single interface may also have multiple IPv6 addresses of any type(unicast, anycast, and multicast) or scope" ----quoted form RFC 4291

“单个接口也可能具有任何类型(单播、任播和多播)或范围的多个 IPv6 地址” ----引用形式 RFC 4291

Recently I came across this question during the experiment I proceeded. I went through RFC 4291, with no clue...

最近我在进行的实验中遇到了这个问题。我通过了 RFC 4291,没有任何线索......

Here is the brief intro of my experiment:
There are two hosts, and I have two IPv6 address assigned to them respectively. Then, I tested the connectivity between the two hosts. I use the command "ping6 ipv6_addr". But it turns out that it can't get to both of the address of peer host with command ping6.

More perceptive with examples*(both command execute at host A, with linux kenel 2.6.32)*:
ping6 addr_b_1 --- it works
ping6 addr_b_2 --- couldn't get through

下面是我的实验的简要介绍:
有两台主机,我分别为它们分配了两个 IPv6 地址。然后,我测试了两台主机之间的连通性。我使用命令“ping6 ipv6_addr”。但事实证明,它无法使用命令 ping6 到达对等主机的两个地址。

更直观的例子*(两个命令都在主机 A 上执行,使用 linux kenel 2.6.32)*:
ping6 addr_b_1 --- 它可以工作
ping6 addr_b_2 --- 无法通过

There are two questions I want to discuss with you guys:
1. why should ipv6 protocol allow this kind of mechanism, a single interface with multiple address?
2. Why can't I get to both of the addresses of host a, at the same time.(which should have been the case. Default address selection for IPv6 is defined in RFC 3484)

有两个问题想和大家讨论一下:
1. 为什么ipv6协议要允许这种机制,单接口多地址?
2. 为什么我不能同时访问主机 a 的两个地址。(应该是这种情况。IPv6 的默认地址选择在 RFC 3484 中定义)

Thank you guys!

谢谢你们!

采纳答案by Celada

Early IPv4 stacks didn't support more than one IP address per interface. Later improvements enabled "secondary" addresses. This was found to be very useful in practice, and the designers of IPv6 choose to mandate support for it as part of the standard so that you could always count on it being possible.

早期的 IPv4 堆栈不支持每个接口超过一个 IP 地址。后来的改进启用了“辅助”地址。这在实践中被发现非常有用,IPv6 的设计者选择强制支持它作为标准的一部分,这样您就可以始终指望它成为可能。

The designers of IPv6 did more than just mandate it. They made it an important part of the IPv6 protocol. Every IPv6 interface has a link-local IP address. If the interface is also able to communicate on a larger network (such as the Internet) then it also has a global scope address. That's two addresses minimum, right there. And if the host is behind a multihomed Internet connection, it probably has even more addresses. Multiple IP addresses per interface was not an afterthought in IPv6 like it was in IPv4.

IPv6 的设计者所做的不仅仅是授权它。他们使它成为 IPv6 协议的重要组成部分。每个 IPv6 接口都有一个本地链路 IP 地址。如果接口还能够在更大的网络(例如 Internet)上进行通信,那么它还有一个全局范围地址。最少两个地址,就在那里。如果主机位于多宿主 Internet 连接后面,则它可能具有更多地址。每个接口有多个 IP 地址在 IPv6 中不像在 IPv4 中那样是事后的想法。

You mention cons, but barring misconfigurations, I don't see this situation causing any problems. (Maybe you could elaborate on your setup and why one IP address works but not the other; however I guarantee you have some kind of error that's causing it).

您提到了缺点,但除非配置错误,否则我认为这种情况不会导致任何问题。(也许您可以详细说明您的设置以及为什么一个 IP 地址有效而另一个 IP 地址无效;但是我保证您有某种错误导致它)。

On the other hand, think of the advantages:

另一方面,想想优点:

  • Devices can discover each other on the local LAN using the link-local addresses even if there is no network infrastructure (i.e. router) available. Later, if a router is added and global scope addresses become available, these addresses augment the address set, they do not replace the link-local addresses; so existing communications using the link-local addresses are not disrupted.
  • When an Internet connection is dropped, added, or replaced, one IP address from the set can be withdrawn or added without affecting the others. Thanks to the "depracated" state, this enables a graceful renumbering from one IP address to another, with the interface supporting both for a period of time.
  • 即使没有可用的网络基础设施(即路由器),设备也可以使用本地链路地址在本地 LAN 上发现彼此。之后,如果添加了路由器并且全局范围地址可用,这些地址会增加地址集,它们不会替换链路本地地址;因此,使用本地链路地址的现有通信不会中断。
  • 当 Internet 连接断开、添加或替换时,可以撤消或添加一组 IP 地址,而不会影响其他 IP 地址。由于“已弃用”状态,这使得从一个 IP 地址到另一个 IP 地址的重新编号能够正常进行,并且接口在一段时间内同时支持这两种地址。

Also: keep in mind that almost all IPv4 stacks support multiple addresses per interface too, so this is not a big difference between v4 and v6. It's only really old v4 stacks that don't support it. The difference is that v6 has methods of managing the set of addresses automatically, but this doesn't exist in v4.

另外:请记住,几乎所有 IPv4 堆栈也支持每个接口的多个地址,因此 v4 和 v6 之间没有太大区别。只有非常老的 v4 堆栈不支持它。不同之处在于 v6 具有自动管理地址集的方法,但这在 v4 中不存在。