Skip to content

Mixed proxy and destination ip versions don't connect #21146

Closed

Description

@terrancewong

I did this

V proxy / target > IPv4 IPv6
IPv4 Y N
IPv6 N Y
 % curl -4 --proxy http://127.0.0.1:1080 -o /dev/null http://www.google.com
  % Total    % Received % Xferd  Average Speed  Time    Time    Time   Current
                                 Dload  Upload  Total   Spent   Left   Speed
100  79445   0  79445   0      0  49515      0           00:01          49534

 % curl -6 --proxy='http://[::1]:1080' -o /dev/null http://www.google.com   
  % Total    % Received % Xferd  Average Speed  Time    Time    Time   Current
                                 Dload  Upload  Total   Spent   Left   Speed
100  79271   0  79271   0      0  50789      0           00:01           2973

 % curl -6 --proxy http://127.0.0.1:1080 -o /dev/null http://www.google.com
  % Total    % Received % Xferd  Average Speed  Time    Time    Time   Current
                                 Dload  Upload  Total   Spent   Left   Speed
  0      0   0      0   0      0      0      0                              0
curl: (7) Failed to connect to www.google.com port 80 via 127.0.0.1 after 0 ms: Could not connect to server

 % curl -4 --proxy='http://[::1]:1080' -o /dev/null http://www.google.com
  % Total    % Received % Xferd  Average Speed  Time    Time    Time   Current
                                 Dload  Upload  Total   Spent   Left   Speed
  0      0   0      0   0      0      0      0                              0
curl: (7) Failed to connect to www.google.com port 80 via ::1 after 0 ms: Could not connect to server

So, if the proxy is configured in ~/.curlrc, It almost have 50% chance to fail, if the wen site has IP both v4 and v6.

I can confirm my proxy works all 4 ways, tested using firefox.

I expected the following

I expect both version of proxy can work with both version of IP,

curl/libcurl version

 % curl --version
curl 8.19.0 (x86_64-pc-linux-gnu) libcurl/8.19.0 OpenSSL/3.5.5 zlib/1.3.1 brotli/1.2.0 zstd/1.5.7 libidn2/2.3.8 libpsl/0.21.2 libssh2/1.11.1 nghttp2/1.68.0 ngtcp2/1.21.0 nghttp3/1.15.0 librtmp/2.3 mit-krb5/1.22.1 OpenLDAP/2.6.10
Release-Date: 2026-03-11, security patched: 8.19.0-1
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps mqtt mqtts pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp ws wss
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTP3 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM PSL SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd

operating system

Linux  6.19.6+deb14+1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.19.6-2 (2026-03-12) x86_64 GNU/Linux

Activity

  1. bagder commented on Mar 29, 2026

    @bagder
    Member

    I can confirm my proxy works all 4 ways, tested using firefox.

    But Firefox has no -4 / -6 options so it's not really the same thing you've tested.

    For example, just to understand what we are talking about:

    curl -6 --proxy http://127.0.0.1:1080 -o /dev/null http://www.google.com

    What exactly do you expect this command line to do?

    -6 is documented to

    Request only IPv6 addresses when resolving hostnames, and not for example any IPv4.

  2. jay commented on Apr 12, 2026

    @jay
    Member

    Ref: https://curl.se/docs/manpage.html#--ipv4
    Ref: https://curl.se/docs/manpage.html#--ipv6

    curl -6 --proxy http://127.0.0.1:1080/ -o /dev/null http://www.google.com/

    What exactly do you expect this command line to do?

    I think the reporter has a point. He's saying basically this:

    • if -6 is used then no connection can be made to a proxy with an IPv4 address, for example 127.0.0.1
    • if -4 is used then no connection can be made to a proxy with an IPv6 address, for example ::1

    -4, --ipv4 doc says: "Request only IPv4 addresses when resolving hostnames, and not for example any IPv6."
    -6, --ipv6 doc says: "Request only IPv6 addresses when resolving hostnames, and not for example any IPv4."

    Furthermore curl -4 and -6 map internally to libcurl CURL_IPRESOLVE_V4 and CURL_IPRESOLVE_V6, respectively, and that doc says: "If the URL provided for a transfer contains a numerical IP version as a host name, this option does not override or prohibit libcurl from using that IP version."

    I think it's reasonable to assume that -4 and -6 do not stop connections to the opposite type of IP address if that IP address is user specified (ie it is not resolved). As the reporter said this issue can make it hard to use --proxy with an IP address in the curlrc

  3. icing commented on Apr 13, 2026

    @icing
    Contributor

    I think it's reasonable to assume that -4 and -6 do not stop connections to the opposite type of IP address if that IP address is user specified (ie it is not resolved). As the reporter said this issue can make it hard to use --proxy with an IP address in the curlrc

    Makes sense to me.

  4. added a commit that references this issue on Apr 13, 2026
  5. icing commented on Apr 13, 2026

    @icing
    Contributor

    My proposal on fixing this: #21295.

    @terrancewong care to test the PR to see if it does what you want? Thanks!

  6. added a commit that references this issue on Apr 13, 2026
    40d57c9
  7. added a commit that references this issue on Jun 3, 2026
    1bfecaf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions