SOCKS5h vs SOCKS5: What the h Means and Who Resolves the Hostname
Contents

In short: The h stands for hostname. With
socks5://your client looks the hostname up itself and sends the proxy an address. Withsocks5h://it sends the name, and the proxy does the lookup. The protocol is the same SOCKS5 either way. Usesocks5h://for regional checks, where the answer should come from the proxy’s side, andsocks5://for names that only resolve on your own network.
A SOCKS5 proxy can be given its destination in two forms: as a hostname, or
as an IP address your machine has already looked up. The proxy URL decides
which. socks5:// makes the client do the DNS lookup and send the address.
socks5h:// makes it send the name, so the proxy does the lookup. This guide
shows the two request flows, explains when the difference changes your
results, sets the scheme in curl, Python, Node and the browsers, and shows how
to see which form your client sent.
What does the h in socks5h mean?
It stands for hostname, and the convention is curl’s. The
curl manual describes --socks5 as using
the proxy “but resolve the hostname locally”, and --socks5-hostname as the
variant that lets “the proxy resolve the hostname”. In a proxy URL, the
schemes socks5:// and socks5h:// pick the same two behaviours. Python
requests says its schemes are in line with curl, and the Node package
socks-proxy-agent uses the same names, so the scheme reads the same across
tools.
The protocol underneath does not change. RFC 1928 lets a connect request carry its destination as an IPv4 address, an IPv6 address or a domain name, and the h only says which of these the client fills in.
With socks5://HOST:PORT, a request for https://example.com/ runs like
this:
- Your machine asks its own DNS resolver for
example.com. - The resolver answers with an address.
- The client asks the proxy to connect to that address.
- The proxy connects, and never sees the name.
With socks5h://HOST:PORT:
- The client asks the proxy to connect to
example.com. - The proxy asks its own resolver for the name.
- The proxy connects to the address its resolver returned.
Your machine makes no DNS query for the site in the second flow, and in both the site sees a connection from the proxy’s address.
Why does it matter where the name is resolved?
Because the answer to a DNS query can depend on who asks. Large sites and content delivery networks often give each region the address of a nearby server. RFC 7871 describes authoritative servers that “return different responses based on the perceived topological location of the user”, judged by the address of the resolver that asks them.
Say you test your own storefront from a static address in Germany while you
sit in the United States. With socks5://, your resolver in the United States
picks the server, and the proxy is then asked to fetch the page from a server
chosen for American visitors. The exit address is German, the server answering
it was picked for someone else, and a regional check can show content or
timings that no visitor in Germany gets. With socks5h://, the lookup is made
by the resolver the proxy uses, and the server is picked for the proxy’s side
of the connection. The post on
viewing your website from another country
sets up the rest of such a check, from language to time zone.
Three other cases change the answer, whichever country you test from:
- Names that only exist on your network. An internal hostname that your
office DNS answers and public DNS does not will fail through
socks5h://, because the proxy cannot resolve it. Usesocks5://for those, or the IP address itself. - IPv6 answers. With local resolution, your machine may get an IPv6 address
and ask the proxy to reach it, which works only if the proxy’s own network
can. With
socks5h://, the proxy picks from the answers its own resolver gives. - Your own resolver. With
socks5://, the lookup for each site goes to your own resolver. Withsocks5h://, your machine makes none, as our SOCKS5 page notes. The site you connect to receives the same request either way.
How do you use socks5h in curl, Python and Node?
Every example in this section sends the name to the proxy. To send an
address instead, change the scheme to socks5://. Replace HOST, PORT and the
credentials with the values on your order, which
using your static IP after purchase shows
where to find.
curl
# The proxy resolves the name
curl -x socks5h://USERNAME:PASSWORD@HOST:PORT https://example.com/
# The same, as separate options
curl --socks5-hostname HOST:PORT --proxy-user USERNAME:PASSWORD https://example.com/
# Your machine resolves the name
curl -x socks5://USERNAME:PASSWORD@HOST:PORT https://example.com/
curl’s manual says credentials in the proxy URL are URL-decoded, so encode special characters in the password. It also warns that a password on the command line is visible in the process list.
Python requests
requests needs its SOCKS extra, installed with python -m pip install 'requests[socks]'. Its documentation
says that socks5 resolves on the client and that you should use socks5h to
resolve on the proxy server.
import os
from urllib.parse import quote
import requests
user = quote(os.environ["PROXY_USER"], safe="")
password = quote(os.environ["PROXY_PASSWORD"], safe="")
proxy = "socks5h://" + user + ":" + password + "@HOST:PORT"
r = requests.get("https://example.com/", proxies={"http": proxy, "https": proxy}, timeout=30)
Set both keys. A dictionary with only http lets every HTTPS request leave
from your own address. Our requests guide
has the session and environment variable versions.
Python httpx
httpx takes one proxy argument and needs pip install 'httpx[socks]'. Its
proxy documentation shows
only a socks5:// URL and does not say which end resolves the name. The
changelog for
0.28.0 adds socks5h as a valid proxy scheme.
import httpx
with httpx.Client(proxy="socks5h://USERNAME:PASSWORD@HOST:PORT", timeout=30) as client:
r = client.get("https://example.com/")
In our test of httpx 0.28.1, both socks5:// and socks5h:// sent the
hostname to the proxy. So in httpx the scheme does not switch the lookup to
your machine; if a job needs your local DNS, requests with socks5:// does
that.
Node.js
Node’s http and https modules accept an agent, and the
socks-proxy-agent
package supplies one for SOCKS. In its source, socks5 and socks4 look the
name up locally, while socks5h, socks4a and a bare socks send it to the
proxy.
import https from "node:https";
import { SocksProxyAgent } from "socks-proxy-agent";
const agent = new SocksProxyAgent("socks5h://USERNAME:PASSWORD@HOST:PORT");
https.get("https://example.com/", { agent: agent }, (res) => {
console.log(res.statusCode);
res.resume();
});
What do browsers do with a SOCKS5 proxy?
A browser’s proxy settings dialog takes a host and a port, with no scheme to add an h to, so each browser decides for itself.
Chrome always sends the name. Chromium’s proxy notes say that for SOCKS5 “name resolution is always done proxy side”, and that Chrome has no option to change it. The same notes say Chrome supports no SOCKS5 authentication, so a SOCKS5 password is never sent. Put the address you connect from on the proxy’s allowlist instead; the post on proxy authentication methods walks through it.
Firefox has a checkbox in its connection settings, Proxy DNS when using
SOCKS v5. It is on by default since Firefox 128
(bug 1741375), and
behind it is the preference network.proxy.socks5_remote_dns, which the
browser’s own preference file describes as “making it a SOCKS5h proxy by
convention”. Check the box once in your own profile before you rely on it.
Where do the username and password go?
In the URL, before the host: socks5h://USERNAME:PASSWORD@HOST:PORT. The h
does not change that part. A slash, question mark, hash or percent sign in the
password has to be percent-encoded, or the URL ends early.
SOCKS5 has its own sign-in, defined in RFC 1929, and it sends the password to the proxy in clear text. Anything you send inside the tunnel over HTTPS stays encrypted, but the proxy password itself does not. If a client cannot send a SOCKS5 password, as with Chrome, or you would rather store no password on a server, use an IP allowlist; the authentication guide compares the two methods and the errors each one produces.
How do you check which one your client sends?
curl tells you. Add -v and look for the SOCKS5 line. For a request to
http://example.com/ it reads:
* SOCKS5 connect to 104.20.23.154:80 (locally resolved)
* SOCKS5 connect to example.com:80 (remotely resolved)
The first came from socks5://, the second from socks5h://, in our run of
curl 8.7.1. The address will differ on your machine, and an https:// URL
shows port 443. Libraries print no such line. For them, the table What each
client does with socks5 and socks5h gives what each sent in our test, and
the requests documentation and the socks-proxy-agent source match curl’s
convention.
Two further checks confirm the rest of the path. Open What Is My IP through the proxy to see the exit address a site sees; it shows the same address with either scheme. The proxy checker tells you whether a proxy answers over SOCKS5 with your credentials before you put it in code. Run these on your own setup and on pages you are allowed to test.
What does ProxyJam sell for this?
Static residential (ISP) proxies: one address on a named internet provider’s network, yours for the period you pay for, in 76 countries. Every one runs HTTP or SOCKS5, switched on the order from the dashboard or the API, and the order then shows the port and credentials for the new protocol. Changing the scheme in your client is not enough on its own: a proxy still set to HTTP does not answer SOCKS5.
A static address is the wrong fit if each request needs a new IP. That takes a rotating pool, which we do not sell today. Prices are on the pricing page, and the SOCKS5 page explains the protocol and the switch in more detail.
