How to Use Socks5 Proxy with Curl quick start
Mark Vi
Tech UI/UX Expert
In this quick guide, I’ll show you how I usually set up curl to work with a SOCKS5 proxy, from the simplest one-liner to more advanced use cases with authentication, timeouts, environment variables. No fluff, just practical commands you can copy, paste, and run.
You can point curl at a SOCKS5 proxy with the -x (or --proxy) flag. Use socks5h:// so DNS resolves through the proxy. That’s the important bit.
# Basic GET through a local SOCKS5 proxy curl -x socks5h://127.0.0.1:10162 https://ifconfig.me
Auth on the proxy? Put user:pass@ in the URL.
# With username and password curl -x socks5h://myuser:mypassword@proxy.myhost.com:1080 https://ifconfig.me
Need to see what’s going on under the hood?
# Verbose and with tight timeouts curl -v --connect-timeout 5 --max-time 15 \ -x socks5h://127.0.0.1:10162 https://example.com
Force IPv4 or IPv6 if your network is picky:
# Force IPv4 curl -4 -x socks5h://127.0.0.1:10162 https://example.com # Force IPv6 curl -6 -x socks5h://[::1]:10162 https://example.com
POST requests work the same way:
curl -x socks5h://127.0.0.1:10162 \
-H "Content-Type: application/json" \
-d '{"ping":"pong"}' \
https://httpbin.org/post
If you prefer setting it once per shell session:
# Apply to all curl calls in this shell export ALL_PROXY="socks5h://myuser:mypassword@proxy.myhost.com:1080" # Then just run curl curl https://ifconfig.me
Small notes that save hours later:
- socks5h resolves hostnames via the proxy. socks5 resolves locally. Use socks5h unless you have a specific reason not to.
- Some targets block known proxy egress IPs. If something fails only over the proxy, try another endpoint to confirm.
- Mix --resolve or -H "Host: ..." with care. If you override DNS or Host, you might bypass what the proxy is supposed to handle.
Practical patterns and troubleshooting
Here are copy-pasteable snippets you’ll probably need on a real project.
Global env vs per call
Set once for the shell, override when needed.
# Session-wide default export ALL_PROXY="socks5h://user:pass@proxy.host:1080" # One command without proxy NO_PROXY="*" curl https://example.com # One command with a different proxy curl -x socks5h://another.host:1080 https://example.com
You can also use protocol-specific vars:
export HTTP_PROXY="socks5h://user:pass@proxy.host:1080" export HTTPS_PROXY="socks5h://user:pass@proxy.host:1080" export NO_PROXY="localhost,127.0.0.1,.internal"
Auth options
If you don’t want credentials in the URL:
curl --proxy socks5h://proxy.host:1080 \
--proxy-user "myuser:mypassword" \
https://ifconfig.me
Save to file and verify what went through
Good for debugging geofencing or IP reputation issues.
curl -sS -x socks5h://proxy.host:1080 https://ifconfig.me > ip.txt cat ip.txt
Quick health check of the proxy
You want a fast go/no-go.
curl -sS -o /dev/null -w "%{http_code}\n" \
--connect-timeout 5 --max-time 10 \
-x socks5h://proxy.host:1080 https://example.com
Retries for flaky lines
Mobile hotspots and coffee shop wifi will thank you.
curl -x socks5h://proxy.host:1080 \ --retry 5 --retry-all-errors --retry-delay 1 \ https://example.com
Force DNS over proxy
This is the trap many fall into. Use socks5h or the long flag.
# Good curl -x socks5h://proxy.host:1080 https://target.tld # Also good curl --socks5-hostname proxy.host:1080 https://target.tld
IPv4 and IPv6 sanity checks
Some proxies only expose v4 or v6.
curl -4 -x socks5h://proxy.host:1080 https://ipv4.icanhazip.com curl -6 -x socks5h://proxy.host:1080 https://ipv6.icanhazip.com
POST json and pass headers
Exactly like normal curl, just add the proxy flag.
curl -x socks5h://proxy.host:1080 \
-H "Content-Type: application/json" \
-H "Authorization: Bearer XXX" \
-d '{"hello":"world"}' \
https://api.example.com/endpoint
Upload a file
Same deal.
curl -x socks5h://proxy.host:1080 \ -F "file=@./report.pdf" \ https://uploader.example.com
Per-project .curlrc
Keep your repo clean and your fingers happier. Put this in a local .curlrc next to your scripts if your team is ok with it, or in your home folder if it’s only for you.
proxy = socks5h://user:pass@proxy.host:1080 connect-timeout = 5 max-time = 20 retry = 3 retry-all-errors
Then just run:
curl https://example.com
Common errors and fast fixes
Proxy connects but target fails
- Check if the target blocks the proxy egress IP. Test with another site.
- Add retries and a longer max-time for slow exits.
- Force IPv4 if DNS on the proxy returns only v6 and the target has poor v6.
Curl says could not resolve host
- You used socks5 instead of socks5h. Switch to socks5h so DNS goes through the proxy.
Proxy auth required
- Add user and pass with --proxy-user or embed user:pass in the URL.
Hangs forever
- Add --connect-timeout and --max-time. If it still hangs, the proxy is dead or filtered.
Bypass proxy for local services
- Set NO_PROXY to localhost, 127.0.0.1, and your internal domains.
Wrapping up
Using a SOCKS5 proxy with curl is one of those small tricks that makes a big difference when you’re debugging APIs, testing geo-restricted services, or building apps that need privacy-focused network calls. With a single -x socks5h:// flag you can route all requests through a proxy, resolve DNS remotely, handle authentication, and keep your local network clean. Combine it with retries, timeouts, and environment variables, and you get a flexible toolchain that works across dev, staging, and production.
If you’re working with CI pipelines, or external API integrations, learning how to control curl traffic through SOCKS5 will save you hours of headaches and give you more control over how your apps connect to the web. Keep these examples close, and next time you need to tunnel traffic through a proxy, it’ll be as simple as copy, paste, run.
Mark Vi
Tech UI/UX Expert with over 15 years of experience