%20%E7%9A%84%E9%9A%A8%E6%A9%9F%20IP%20%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8.png)
我有一個scaleway.com 伺服器(DEV1-S),它為我提供了/64 IPv6 子網路。我想使用此子網路中的 IP 發出 HTTP 請求(將在範例中使用 wget),但我無法讓它工作。請求(使用 wget 以及其他程式和程式語言)將掛起。
IPv6 位址為 2001:bc8:1830:1b18::1,閘道為 2001:bc8:1830:1b18::,網路遮罩為 64。
ip -6 addr
在乾淨的/剛剛建立的伺服器上運行,將輸出以下內容:
root@test:~# ip -6 addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 state UNKNOWN qlen 1000
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
inet6 2001:bc8:1830:1b18::1/64 scope global
valid_lft forever preferred_lft forever
inet6 fe80::dc2e:4cff:fe57:a019/64 scope link
valid_lft forever preferred_lft forever
我在論壇和其他問題/答案中讀到,為了使您能夠綁定到子網路中的位址,您需要執行以下命令:
ip add add local 2001:bc8:1830:1b18::/64 dev lo
ip route add local 2001:bc8:1830:1b18::/64 dev ens2
sysctl -w net.ipv6.ip_nonlocal_bind=1
這些命令之後,輸出ip -6 addr
如下:
root@test:~# ip -6 addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 state UNKNOWN qlen 1000
inet6 2001:bc8:1830:1b18::/64 scope global
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
inet6 2001:bc8:1830:1b18::1/64 scope global
valid_lft forever preferred_lft forever
inet6 fe80::dc2e:4cff:fe57:a019/64 scope link
valid_lft forever preferred_lft forever
我現在可以 ping6 例如,2001:bc8:1830:1b18::9
而不是僅2001:bc8:1830:1b18::1
,但只能從我自己的伺服器。不是來自其他伺服器/網路。
如果沒有sysctl -w net.ipv6.ip_nonlocal_bind=1
,wget 將會回傳:
root@test:~# wget --bind-address=2001:bc8:1830:1b18::2 -v google.com
--2021-08-13 00:29:45-- http://google.com/
Resolving google.com (google.com)... 2a00:1450:400e:802::200e, 142.250.179.174
Connecting to google.com (google.com)|2a00:1450:400e:802::200e|:80... failed: Cannot assign requested address.
Connecting to google.com (google.com)|142.250.179.174|:80... failed: Address family not supported by protocol.
現在,在 3 個命令之後,當我運行 wget 並將 --bind-address 標誌設置為子網中除 之外的地址時2001:bc8:1830:1b18::1
,請求將永遠掛起:
root@test:~# wget --bind-address=2001:bc8:1830:1b18::1 google.com
--2021-08-12 23:55:48-- http://google.com/
Resolving google.com (google.com)... 2a00:1450:400e:802::200e, 142.250.179.174
Connecting to google.com (google.com)|2a00:1450:400e:802::200e|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.google.com/ [following]
--2021-08-12 23:55:48-- http://www.google.com/
Resolving www.google.com (www.google.com)... 2a00:1450:400e:80f::2004, 142.251.36.4
Connecting to www.google.com (www.google.com)|2a00:1450:400e:80f::2004|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html’
index.html [ <=> ] 13.03K --.-KB/s in 0.009s
2021-08-12 23:55:48 (1.44 MB/s) - ‘index.html’ saved [13342]
root@test:~# wget --bind-address=2001:bc8:1830:1b18::2 google.com
--2021-08-12 23:55:52-- http://google.com/
Resolving google.com (google.com)... 2a00:1450:400e:802::200e, 142.250.179.174
Connecting to google.com (google.com)|2a00:1450:400e:802::200e|:80...
lsof
對於 wget 進程,內容如下: wget 3413 root 3u IPv6 58660 0t0 TCP[2001:bc8:1830:1b18::2]:56623->ams15s41-in-x0e.1e100.net:http (SYN_SENT)
我究竟做錯了什麼?預先非常感謝!