Tutorials

How to Set Up a SOCKS5 Proxy (curl, Browser & Python)

Pointing a tool at a SOCKS5 proxy is usually one line of config. Below are copy-paste setups for curl, your browser, and Python, including username/password auth and remote DNS. We use HOST:PORT for the proxy address and USER / PASS for the credentials — swap in your real values. (On o2co the host and port are on your dashboard, and the endpoint speaks HTTP or SOCKS5 on the same port — so the same credentials also work as http://USER:PASS@HOST:PORT for any tool that prefers an HTTP proxy.)

1. curl

Use the --socks5-hostname flag so DNS is resolved by the proxy (not your machine — this prevents DNS leaks):

curl --socks5-hostname HOST:PORT --proxy-user USER:PASS \
  https://api.ipify.org

If it prints the proxy's IP instead of yours, it's working. Avoid plain --socks5 for hostnames — it resolves DNS locally and can leak which sites you're visiting.

2. Environment variable (many tools)

curl and many other CLIs respect the ALL_PROXY variable:

export ALL_PROXY=socks5h://USER:PASS@HOST:PORT
# the "h" in socks5h means remote DNS

3. Browser (Firefox and Chrome)

Neither Firefox nor Chrome accepts a username and password for a SOCKS5 proxy, so SOCKS5 in a browser only works with an endpoint that needs no credentials. For an endpoint with username/password auth, configure it as an HTTP proxy instead — both browsers then prompt for the credentials on the first request.

In Firefox: Settings → General → Network Settings → Settings… → Manual proxy configuration. Enter HOST and PORT under HTTP Proxy and tick Also use this proxy for HTTPS. (For a no-auth SOCKS5 endpoint, fill in SOCKS Host instead, choose SOCKS v5, and tick Proxy DNS when using SOCKS v5.)

Chrome takes a command-line flag:

google-chrome --proxy-server="http://HOST:PORT"

With an HTTP proxy the hostname is resolved on the proxy side, so there is no DNS-leak setting to worry about. o2co requires credentials, which is why the HTTP form is the one to use in a browser — the same USER/PASS work over both protocols.

4. Python (requests)

Install the SOCKS extra, then route the request:

pip install "requests[socks]"
import requests

proxies = {
    "http":  "socks5h://USER:PASS@HOST:PORT",
    "https": "socks5h://USER:PASS@HOST:PORT",
}
r = requests.get("https://api.ipify.org?format=json", proxies=proxies, timeout=30)
print(r.json())   # -> the proxy's egress IP

Again, socks5h:// (with the h) keeps DNS resolution on the proxy. More patterns in How to Use a Proxy With Python Requests.

5. Python (httpx)

# pip install "httpx[socks]"
import httpx

# httpx passes the hostname to the proxy, so DNS is resolved remotely
proxy = "socks5://USER:PASS@HOST:PORT"
with httpx.Client(proxy=proxy, timeout=30) as c:
    print(c.get("https://api.ipify.org").text)

Verify it's working

Always confirm the egress IP changed before trusting your setup. Hit an IP-echo service through the proxy and check the result isn't your own address:

curl --socks5-hostname HOST:PORT --proxy-user USER:PASS https://ipinfo.io/json

Common gotchas

  • DNS leaks — use socks5h:// / --socks5-hostname / “Proxy DNS” so lookups go through the proxy.
  • Auth fails — URL-encode special characters in your password when it sits inside a proxy URL (@ becomes %40, : becomes %3A).
  • Connection times out — some corporate and cloud networks block outbound traffic on uncommon ports; test from another network to rule it out.
  • UDP — SOCKS5 defines a UDP relay, but many client libraries and proxy services (ours included) handle TCP only.

Next steps

Once it's working, read up on sticky vs rotating sessions and which IP pool fits your target. New to the protocol itself? See What Is a SOCKS5 Proxy? Need an endpoint to test with? Get 1 GB free or see pricing.