6

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

1 Answer 1

17

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"
4
  • "hostname proxy" rolleyes Commented Dec 25, 2014 at 17:11
  • 1
    The environment variable should be ALL_PROXY="socks5h://..."
    – chris
    Commented Oct 24, 2017 at 9:08
  • @chris - thank you, it's fixed Commented Oct 24, 2017 at 9:52
  • 1
    you just saved my evening
    – Alexey Sh.
    Commented Jun 14 at 20:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .