当我尝试使用 WGet 下载某些内容时,如果域名转换为 IPv6 地址,通常会失败。
当存在链接重定向时,这种情况更常见。
例如:
$ wget --inet6-only https://raw.githubusercontent.com/walkxcode/Dashboard-Icons/main/png/ebay.png
--2022-11-13 10:27:05-- https://raw.githubusercontent.com/walkxcode/Dashboard-Icons/main/png/ebay.png
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 2606:50c0:8001::154, 2606:50c0:8000::154, 2606:50c0:8003::154, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|2606:50c0:8001::154|:443...
$ wget --inet6-only https://download.docker.com/linux/centos/9/x86_64/stable/Packages/docker-ce-20.10.21-3.el9.x86_64.rpm
--2022-11-13 10:32:52-- https://download.docker.com/linux/centos/9/x86_64/stable/Packages/docker-ce-20.10.21-3.el9.x86_64.rpm
Resolving download.docker.com (download.docker.com)... 2600:9000:21ed:e000:3:db06:4200:93a1, 2600:9000:21ed:2e00:3:db06:4200:93a1, 2600:9000:21ed:7000:3:db06:4200:93a1, ...
Connecting to download.docker.com (download.docker.com)|2600:9000:21ed:e000:3:db06:4200:93a1|:443...
在第一个示例中,raw.githubusercontent.com
名称解析为2606:50c0:8001::154, 2606:50c0:8000::154, 2606:50c0:8003::154
。然后,WGget 尝试连接到该 IP,但没有任何反应,只是冻结。没有进行下载。同样的情况也发生在第二个示例中download.docker.com
。
当我强制建立 IPv4 连接时,它会成功下载内容。
$ wget --inet4-only https://raw.githubusercontent.com/walkxcode/Dashboard-Icons/main/png/ebay.png
--2022-11-13 10:28:16-- https://raw.githubusercontent.com/walkxcode/Dashboard-Icons/main/png/ebay.png
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.109.133, 185.199.108.133, 185.199.110.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.109.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 24872 (24K) [image/png]
Saving to: ‘ebay.png’
ebay.png 100%[==================================================================================>] 24.29K --.-KB/s in 0.005s
2022-11-13 10:28:16 (4.48 MB/s) - ‘ebay.png’ saved [24872/24872]
$ wget --inet4-only https://download.docker.com/linux/centos/9/x86_64/stable/Packages/docker-ce-20.10.21-3.el9.x86_64.rpm
--2022-11-13 10:34:35-- https://download.docker.com/linux/centos/9/x86_64/stable/Packages/docker-ce-20.10.21-3.el9.x86_64.rpm
Resolving download.docker.com (download.docker.com)... 52.84.83.27, 52.84.83.65, 52.84.83.79, ...
Connecting to download.docker.com (download.docker.com)|52.84.83.27|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 21654080 (21M) [binary/octet-stream]
Saving to: ‘docker-ce-20.10.21-3.el9.x86_64.rpm’
docker-ce-20.10.21-3.el9.x86_64.rpm 100%[==================================================================================>] 20.65M 27.3MB/s in 0.8s
2022-11-13 10:34:36 (27.3 MB/s) - ‘docker-ce-20.10.21-3.el9.x86_64.rpm’ saved [21654080/21654080]
为什么 WGet 在使用 IPv6 时失败?