# 6. IPv6

* IPv6
  * 128 bits
  * X:X:X:X:X:X:X:X   (X-hexa)
  * Each X - xxxx     (x-binary)
  * prefix (64) + interface ID (64)
  * :: omit zero
* Delivery
  * Unicast
  * Multicast
  * Anycast
* Type
  * Global unicast&#x20;
    * prefix&#x20;
      * /48 global routing
      * /16 subnet
    * interface id&#x20;
      * /64
        * random
        * generate
        * EUI-64
  * Link Local Address
    * FE80::/10&#x20;
      * Not routable
    * Loopback&#x20;
      * ::1
    * Unspecified address&#x20;
      * ::/128
    * Unique local&#x20;
      * FC00::/7 to FDFF::/7
    * Multicast
      * FF02::1 All-nodes multicast&#x20;
      * FF02::2 All-routers multicast
      * FF02::1:FF + (24 bits interface id)
* Stateless Address Auto Configuration (SLAAC)
  * to obtain prefix, prefix length, and default gateway&#x20;
  * each host send router solicitation (RS) to router
  * router respond with router advertisement (RA)
  * to enable (ipv6 unicast-routing)
* Interface ID
  * manually
  * random&#x20;
    * Duplicate Address Detection (DAD)
      * host send network solicitation to all (multicast - 24 bits)
        * if another device reply network advertisement, the interface id&#x20;

          cannot be used
        * if no reply, the interface id is unique     &#x20;
  * EUI-64

    <https://eui64-calc.princelle.org/>

    * 48-bit MAC&#x20;
    * insert FFFE in the middle
    * Swap bit 7th
* Address Resolution Protocol
  * host send NS
  * node reply NA which contains MAC address
* IPv4 to IPv6 Migration
  * Dual Stack
    * both IPv4 & IPv6
  * Tunneling&#x20;
    * IPv6 encapsulate in IPv4 packet
  * Translation&#x20;

![](https://1515939446-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M_AEyEcue-ZdfPiP9yt%2F-MdCX3gkgAZL_CK8VfWA%2F-MdCXlx9DfwxRmsAZM-5%2Fimage.png?alt=media\&token=d9f95eae-aa8e-44e3-9273-92c3909ed2e1)

![](https://1515939446-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M_AEyEcue-ZdfPiP9yt%2F-MdCX3gkgAZL_CK8VfWA%2F-MdCYDtrkMHjOo_f4jxJ%2Fimage.png?alt=media\&token=5061af75-8011-4177-a310-5d8932af9753)

&#x20;[主机](https://baike.baidu.com/item/%E4%B8%BB%E6%9C%BA)A 的[以太网](https://baike.baidu.com/item/%E4%BB%A5%E5%A4%AA%E7%BD%91)MAC 地址是 00-AA-00-3F-2A-1C。首先，通过在第三个和第四个字节之间插入 FF-FE 将其转换为 EUI-64 格式，其结果是 00-AA-00-FF-FE-3F-2A-1C。然后，对 U/L 位（第一个字节中的第七位）求反。第一个字节的[二进制](https://baike.baidu.com/item/%E4%BA%8C%E8%BF%9B%E5%88%B6/361457)形式为 00000000。将第七位求反后，变为 00000010 (0x02)。最后的结果是 02-AA-00-FF-FE-3F-2A-1C，当转换为[冒号](https://baike.baidu.com/item/%E5%86%92%E5%8F%B7/998617)[十六进制](https://baike.baidu.com/item/%E5%8D%81%E5%85%AD%E8%BF%9B%E5%88%B6/4162457)符号时，成为接口标识 2AA:FF:FE3F:2A1C。结果是，对应于 MAC 地址 00-AA-00-3F-2A-1C 的[网络适配器](https://baike.baidu.com/item/%E7%BD%91%E7%BB%9C%E9%80%82%E9%85%8D%E5%99%A8)的链接本地地址是 FE80::2AA:FF:FE3F:2A1C

![](https://1515939446-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M_AEyEcue-ZdfPiP9yt%2F-MdCcfb_9Xid7AoSOq7J%2F-MdCd7be6JkE69pM-kCd%2Fimage.png?alt=media\&token=fdc4c91d-ea0c-478a-86ff-ddb0c41dce26)
