Curl 7.27: [ANY]_PROXY set; curl does not resolve the hostname via proxy

curlPROXY

I'm using curl with a Socks proxy. The proxy is configured via ANY_PROXY="socks5://NNN.NNN.NNN.NNN.PPPP"

I observed that curl resolves the hostname locally, not via the proxy. When requesting a URL with an IP, the request works fine, with hostname that can't be resolved locally, curl fails.

In the man page I found this explicit CLI option:

   --socks5-hostname <host[:port]>
          Use the specified SOCKS5 proxy (and let the proxy resolve the host name).

Interestingly the text within the parens emphassis, that this option will also resolve the hostname via the proxy. But that's all on hostname resolving, in the rest of the man page, there is no word mentioning how name resolving works with proxies.

Version: curl 7.27.0 (x86_64-redhat-linux-gnu) libcurl/7.27.0 NSS/3.15.1 zlib/1.2.7 libidn/1.26 libssh2/1.4.3

Is there an option or alternative environment variable that will make curl resolve hostnames via proxy without having to specify --socks5-hostname <host:port>?

Best Answer

OK for idiots like me, here's the subtle part:

Since 7.21.7, this option is superfluous since you can specify a socks5 hostname proxy with -x, --proxy using a socks5h:// protocol prefix.

The little h following the socks5 tells curl to lookup hostnames via proxy, too.

To make curl look up hostnames via proxy one has to export:

ALL_PROXY="socks5h://NNN.NNN.NNN.NNN.PPPP"

compared to a proxy that will lookup locally:

ALL_PROXY="socks5://NNN.NNN.NNN.NNN.PPPP"
Related Question