測試環境為 Vmware Fusion 10.1.5
- Windows 10 x64 (虛擬機)
- CentOS 7 x64 (虛擬機)
Vmware Fusion 會使用 NAT 的方式讓 MAC 分享網路給虛擬機使用,預設會配給 IPv4,如果需要使用 IPv6 上網則需要額外設定.
設定位於 VMware Fusion menu bar / Preferences / Network
預設為 Share with My Mac
Internet sharing – The virtual Machine shares the IP ddressof the Mac on the external network. The Mac provides network address ranslation (NAT) for network traffic from the virtual machine.
先解除鎖定並選擇 + 用以新增自訂有支援 IPv6 的網路連線 vmnet2 .
Enable IPv6 / IPv6 Prefix : 2001:db8::/64
IPv6 使用 128Bit 的位址空間,其中的 2001:db8: 就是 IPv6 的網段而 "64" 就類似 IPV4 的 subnet mask.
還需要將虛擬機的網路設定到 vmnet2 – settings / Removeable devices / Network Adapter / Custom / vmnet2
先來了解一下 IPv6 的位址指派 (address auto-configuration) 主要可以區分為下列幾種
- Link Local (預設值,不須設定)
網卡都會有屬於自己的 IPv6 link-local address,在 Linux (CentOS 7) 與 Windows 下是隨機產生的. - Static IP
自行設定 IPv6. - 透過 Dynamic Host Configuration Protocol v6 (DHCPv6)
透過 DHCPv6 來得到 IPv6 位址. - 透過 Router Advertisement (RA)
這功能通常是由 Router 來提供.
Windows 10 x64
開機後先來看一下 IP v4 , v6 的狀況.
C:\Windows\system32>ipconfig Windows IP Configuration Ethernet adapter Ethernet0: Connection-specific DNS Suffix . : localdomain IPv6 Address. . . . . . . . . . . : 2001:db8::495a:5c08:6aaf:758d Temporary IPv6 Address. . . . . . : 2001:db8::6010:c92f:15ad:7b03 Link-local IPv6 Address . . . . . : fe80::495a:5c08:6aaf:758d%10 IPv4 Address. . . . . . . . . . . : 172.16.17.128 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : fe80::250:56ff:fec0:2222%10 172.16.17.2 Ethernet adapter Bluetooth Network Connection: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : Tunnel adapter Teredo Tunneling Pseudo-Interface: Connection-specific DNS Suffix . : IPv6 Address. . . . . . . . . . . : 2001:0:9d38:90d7:3036:224c:53ef:ee7f Link-local IPv6 Address . . . . . : fe80::3036:224c:53ef:ee7f%2 Default Gateway . . . . . . . . . :
會看到三組 IPv6 Address
- IPv6 Address. . . . . . . . . . . : 2001:db8::495a:5c08:6aaf:758d
這是由 VMware NAT 所提供,因為 IPV6 的位址空間太長所以 IPV6 2001:db8::495a:5c08:6aaf:758d 為縮寫.- 真正的 IPV6 是
2001:db8::495a:5c08:6aaf:758d
=2001:db8:0000:0000:495a:5c08:6aaf:758d
這樣才有使用到 128bit 的定址空間 - 簡寫的規則如下:
每 32Bit 如開頭之4bit表示為0,即可省略,若32Bit全為0,則可簡寫為0
2001:db8:0000:0000:495a:5c08:6aaf:758d
=2001:db8:0:0:495a:5c08:6aaf:758d若連續完整之32Bit段落皆為 0000,則可全省略,簡寫為::,但以一次為限
2001:db8:0:0:495a:5c08:6aaf:758d
=2001:db8::495a:5c08:6aaf:758d
- 真正的 IPV6 是
- Temporary IPv6 Address. . . . . . : 2001:db8::6010:c92f:15ad:7b03
IPv6 Interface Identifier 隨機產生的,避免在網路上一直使用相同的位址,用以提高安全.這是依據 Privacy Extensions for Stateless Address Autoconfiguration in IPv6 (RFC 4941 )所定義的. - Link-local IPv6 Address . . . . . : fe80::495a:5c08:6aaf:758d%10
預設網卡都會有屬於自己的 IPv6 link-local address, 在 Windows 下是隨機產生的.
其格式固定為 FE80 開頭 (1111 1110 10 + 54 bits的0) ,在加上 64 bits 的 Interface Identifier,不過這個 Link local 無法跨越Router 至其他網段.
預設 IPv6 為 Automatically ,要設定 Static IP 可以在 Control Panel\Network and Internet\Network Connections 設定.
這時候我們可以利用 ping -6 來確認連線是否正常.
C:\Windows\system32>ping -6 www.google.com Pinging www.google.com [2404:6800:4008:c06::67] with 32 bytes of data: Reply from 2404:6800:4008:c06::67: time=58ms Reply from 2404:6800:4008:c06::67: time=64ms Reply from 2404:6800:4008:c06::67: time=65ms Reply from 2404:6800:4008:c06::67: time=93ms Ping statistics for 2404:6800:4008:c06::67: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 58ms, Maximum = 93ms, Average = 70ms
CentOS 7 x64
透過 ifconfig 先來看看我的 IPv6 位址.
[root@localhost ~]# ifconfig ens33 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.16.17.129 netmask 255.255.255.0 broadcast 172.16.17.255 inet6 fe80::fbcb:9dff:259b:f6ea prefixlen 64 scopeid 0x20<link> inet6 2001:db8::ce27:a3d8:4c4e:6a2f prefixlen 64 scopeid 0x0<global> ether 00:0c:29:eb:f1:61 txqueuelen 1000 (Ethernet) RX packets 190 bytes 20602 (20.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 187 bytes 23691 (23.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
可以看到兩組 IPv6.
- inet6 fe80::fbcb:9dff:259b:f6ea prefixlen 64 scopeid 0x20<link>
- inet6 2001:db8::ce27:a3d8:4c4e:6a2f prefixlen 64 scopeid 0x0<global>
不過 Link-Local – fe80::fbcb:9dff:259b:f6ea 看起來並不是透過 EUI-64 將 MAC Address – 00:0c:29:eb:f1:61 做轉換.似乎同 Windows 下是隨機產生的.
可以利用 ping6 工具來確認 IPv6 是否運作正常.
[root@localhost ~]# ping6 www.google.com PING www.google.com(ti-in-x67.1e100.net (2404:6800:4008:c04::67)) 56 data bytes 64 bytes from ti-in-x67.1e100.net (2404:6800:4008:c04::67): icmp_seq=1 ttl=255 time=91.5 ms 64 bytes from ti-in-x67.1e100.net (2404:6800:4008:c04::67): icmp_seq=2 ttl=255 time=58.3 ms 64 bytes from ti-in-x67.1e100.net (2404:6800:4008:c04::67): icmp_seq=3 ttl=255 time=50.2 ms ^C --- www.google.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2007ms rtt min/avg/max/mdev = 50.258/66.710/91.512/17.847 ms
如果不是透過 NAT 之類的還可以連上 http://test-ipv6.com/ 來確認你的 IPv4 , v6 狀態.