Wget
wget 使用 ipv6 地址,完成時間太長
在伺服器上
wget-1.16
需要 8 分鐘才能完成:$ wget http://http.debian.net/debian/dists/stable/Release -O - --2017-06-12 23:44:40-- http://http.debian.net/debian/dists/stable/Release [4693/5569] Resolving http.debian.net (http.debian.net)... 2001:4f8:1:c::15, 2605:bc80:3010:b00:0:deb:166:202, 2001:610:1908:b000::148:14, ... Connecting to http.debian.net (http.debian.net)|2001:4f8:1:c::15|:80... failed: Connection timed out. Connecting to http.debian.net (http.debian.net)|2605:bc80:3010:b00:0:deb:166:202|:80... failed: Connection timed out. Connecting to http.debian.net (http.debian.net)|2001:610:1908:b000::148:14|:80... failed: Connection timed out. Connecting to http.debian.net (http.debian.net)|140.211.166.202|:80... connected. HTTP request sent, awaiting response... 302 Found Location: http://cdn-fastly.deb.debian.org/debian/dists/stable/Release [following] --2017-06-12 23:51:02-- http://cdn-fastly.deb.debian.org/debian/dists/stable/Release Resolving cdn-fastly.deb.debian.org (cdn-fastly.deb.debian.org)... 2a04:4e42:3::204, 151.101.12.204 Connecting to cdn-fastly.deb.debian.org (cdn-fastly.deb.debian.org)|2a04:4e42:3::204|:80... failed: Connection timed out. Connecting to cdn-fastly.deb.debian.org (cdn-fastly.deb.debian.org)|151.101.12.204|:80... connected. ...
因為它正在嘗試使用 IPv6 地址進行連接。
curl-7.38.0
在同一台機器上立即響應。因為它使用 IPv4 地址。他們解析域的方式不同嗎?他們是如何做到的呢?如何wget
使用 IPv4 地址?UPD
$ ip a ... 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether d8:cb:8a:37:cf:57 brd ff:ff:ff:ff:ff:ff inet 188.40.99.4/26 brd 188.40.99.63 scope global eth0 valid_lft forever preferred_lft forever inet6 2a01:4f8:100:738b::2/64 scope global valid_lft forever preferred_lft forever inet6 fe80::dacb:8aff:fe37:cf57/64 scope link valid_lft forever preferred_lft forever $ ip route default via 188.40.99.1 dev eth0 10.0.0.0/24 dev br0 proto kernel scope link src 10.0.0.1 188.40.99.0/26 via 188.40.99.1 dev eth0 188.40.99.0/26 dev eth0 proto kernel scope link src 188.40.99.4
curl
並且wget
不要使用不同的機制來解析域(他們正在使用getaddrinfo()
)。但是,curl
在 IPv6 連接性不佳的情況下,實施快速回退算法以改善使用者體驗。該算法在 RFC 6555(Happy Eyeballs)中有詳細描述:https ://www.rfc-editor.org/rfc/rfc6555
根據
curl/lib/connect.h
這個超時設置為200ms:https ://github.com/curl/curl/blob/a8e523f086c12e7bb9acb18d1ac84d92dde0605b/lib/connect.h#L43
curl
和support /選項將wget
分別強制連接到 IPv4 或 IPv6。-4``-6