IPv6 ULA(唯一本地地址)生成

IPv6 ULA(唯一本地地址)生成

RFC4193 包含用于生成 IPv6 ULA(唯一本地地址)的伪代码。我必须遵循此算法吗?还是任意 ULA 都有效?

   3.2.2. Sample Code for Pseudo-Random Global ID Algorithm

   The algorithm described below is intended to be used for locally
   assigned Global IDs.  In each case the resulting global ID will be
   used in the appropriate prefix as defined in Section 3.2.

     1) Obtain the current time of day in 64-bit NTP format [NTP].

     2) Obtain an EUI-64 identifier from the system running this
        algorithm.  If an EUI-64 does not exist, one can be created from
        a 48-bit MAC address as specified in [ADDARCH].  If an EUI-64
        cannot be obtained or created, a suitably unique identifier,
        local to the node, should be used (e.g., system serial number).

     3) Concatenate the time of day with the system-specific identifier
        in order to create a key.

     4) Compute an SHA-1 digest on the key as specified in [FIPS, SHA1];
        the resulting value is 160 bits.

     5) Use the least significant 40 bits as the Global ID.

     6) Concatenate FC00::/7, the L bit set to 1, and the 40-bit Global
        ID to create a Local IPv6 address prefix.

如果时间不是问题的话我会更喜欢。是否可以采用链路本地地址(Mac 派生)并替换第一个八位字节以将其转换为 ULA?

答案1

关于从链接本地地址获取一些位,并非所有地址都适合这样做。非 MAC 派生不会有任何随机性,fe80::1在某些网络中用作每个人的网关。

从技术上讲,该算法不是必需的。但 ULA 必须是随机的。从紧接在此之前的 3.2.1 节中:

本地分配的全局 ID 必须使用与以下规则一致的伪随机算法生成:[随机的]。第 3.2.2 节描述了建议的算法。重要的是,所有生成全局 ID 的站点都使用功能相似的算法来确保唯一性的可能性很高。

建议的算法使用常用的原语作为输入,以确保唯一性。其他人可能拥有相同的 MAC 地址,这是由于没有重新寻址 VM 或 NIC 供应商犯了错误。但生成具有相同 NTP 时间戳的 MAC 地址的可能性极小。当然,如果您不想编写代码,您可以找到已经编写的实现。

如果您正在使用其他东西,请不要使用纯基于 MAC 地址的方案。也许可以从 /dev/random 读取 40 位。

相关内容