除非使用 IPv6 和 HTTPS,否则 cURL 会挂起

除非使用 IPv6 和 HTTPS,否则 cURL 会挂起

我需要向没有 ipv6 地址的服务器发出一些 cURL 请求,但我的机器似乎只有在 1) 使用 https 和 2) 使用 ipv6 时才能连接。其他请求在 DNS 解析后无限期挂起,然后才建立任何连接。

如果能得到关于如何解决此问题的指导将不胜感激。

该机器运行的是 Ubuntu 18.04.4,带有 curl 7.58.0 和 ufw 0.36。

任何域名都会发生这种情况,但以下是 google.com 的一些示例:

me@myserver:/$ curl -I4 http://www.google.com --trace-ascii /dev/stdout --no-tcp-nodelay
== Info: Rebuilt URL to: http://www.google.com/
== Info:   Trying 142.251.40.100...
*hangs*

me@myserver:/$ curl -I4 https://www.google.com --trace-ascii /dev/stdout --no-tcp-nodelay
== Info: Rebuilt URL to: https://www.google.com/
== Info:   Trying 142.251.40.100...
*hangs*

me@myserver:/$ curl -I6 http://www.google.com --trace-ascii /dev/stdout --no-tcp-nodelay
== Info: Rebuilt URL to: http://www.google.com/
== Info:   Trying 2607:f8b0:4006:81f::2004...
*hangs*

me@myserver:/$ curl -I6 https://www.google.com --trace-ascii /dev/stdout --no-tcp-nodelay
== Info: Rebuilt URL to: https://www.google.com/
== Info:   Trying 2607:f8b0:4006:81f::2004...
== Info: Connected to www.google.com (2607:f8b0:4006:81f::2004) port 443 (#0)
*no problems*

我尝试过在 UFW 中使用 IP 白名单,但是没有帮助:

me@myserver:/$ sudo ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip

To                         Action      From
--                         ------      ----
22                         ALLOW IN    Anywhere
80                         ALLOW IN    Anywhere
443                        ALLOW IN    Anywhere
Anywhere                   ALLOW IN    142.251.40.100
22 (v6)                    ALLOW IN    Anywhere (v6)
80 (v6)                    ALLOW IN    Anywhere (v6)
443 (v6)                   ALLOW IN    Anywhere (v6)

该机器正在运行 Ubuntu 18.04.4。

以下是(稍微重新格式化的)输出curl -V

curl 7.58.0 (x86_64-pc-linux-gnu) 
    libcurl/7.58.0 
    OpenSSL/1.1.1d 
    zlib/1.2.11 
    libidn2/2.3.0 
    libpsl/0.19.1 (+libidn2/2.0.4) 
    nghttp2/1.30.0 
    librtmp/2.3
Release-Date: 2018-01-24
Protocols: 
    dict file ftp ftps gopher http https 
    imap imaps ldap ldaps pop3 pop3s 
    rtmp rtsp smb smbs smtp smtps telnet tftp
Features: 
    AsynchDNS GSS-API HTTP2 HTTPS-proxy
    IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets

相关内容