2

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>?

5

OK for idiots like me, here's the subtile 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 looking 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"
  • "hostname proxy" rolleyes – try-catch-finally Dec 25 '14 at 17:11
  • 1
    The environment variable should be ALL_PROXY="socks5h://..." – chris Oct 24 '17 at 9:08
  • @chris - thank you, it's fixed – try-catch-finally Oct 24 '17 at 9:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.