brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: curl socks5h:// lets the proxy look up the host name too

Curl
~/tips/tip-curl-socks5h-proxy

curl -x socks5h://localhost:1080 https://intranet.example.com/

Send both the request and the name lookup through a SOCKS proxy, so DNS does not leak.

With a SOCKS proxy, the letter at the end of the scheme matters. socks5:// resolves the name on your machine first; socks5h:// hands the name to the proxy.

A common setup is an SSH tunnel as a SOCKS proxy, started with ssh -D 1080 [email protected]. Then:

curl -x socks5h://localhost:1080 https://intranet.example.com/
curl -x socks5://localhost:1080 https://intranet.example.com/

The first line sends the name intranet.example.com to the proxy, which looks it up on the far side. That is what you want for names that only exist in the remote network, and when your local DNS should not see which sites you visit. The second line looks the name up locally, fails if your own resolver does not know it, and tells your local DNS server where you are going.

I’d make socks5h:// the default for exactly that reason. You can also set it once for a shell with export ALL_PROXY=socks5h://localhost:1080; curl reads that variable.

A SOCKS proxy only carries the connection. With an https:// URL the content is encrypted end to end, but with plain http:// the proxy and the network behind it can read everything. Also, an SSH tunnel stops when the SSH session ends, so a long job through it should handle a dropped connection.

Further reading: curl man page, everything curl: SOCKS proxy

More Curl tips curl --trace-ascii – https://example.com/ Retry-After: 120 curl -fsS --fail-early \ url = "https://example.com/data/latest.json" curl -4 -s -o /dev/null -w '%{remote_ip} %{http_code}\n' https://example.com/ All Curl tips (71) All topics

Link