SOCKS5h vs SOCKS5: Prevent DNS Leaks

Learn socks5h vs socks5, see where DNS resolves, configure curl, Python Requests and Firefox, and verify that your proxy does not leak hostnames.
A 4G USB dongle connects through a small computer and cloud route to a globe while a separate local path is shown below.

The difference in socks5h vs socks5 is where your client resolves the destination hostname: on your machine or through the SOCKS5 proxy. Choose the proxy-side option when the hostname should be resolved from the mobile-proxy network, then verify the result instead of assuming that a SOCKS5 connection prevents every DNS leak.

Where DNS happens with a proxy

When you request https://example.com, your application has to turn example.com into an IP address before it can open the connection. That lookup is DNS. It is separate from the later HTTP request and from the public IP that the destination sees.

There are three relevant points in the connection:

  1. Proxy endpoint lookup: your client may resolve proxy.example.net so it can connect to the proxy. This lookup normally happens locally and is expected.
  2. Destination lookup: your client resolves example.com, or it sends the hostname to the SOCKS5 proxy for resolution.
  3. Destination connection: the proxy opens the TCP connection to the destination and relays the traffic.

The DNS leak question is about the second point. If your local resolver receives the destination hostname, your network operator or DNS service can learn which hostname your application requested even though the web connection itself goes through the proxy.

SOCKS5 can carry either an IP address or a domain name in its connection request. RFC 1928 defines the domain-name address type; the client library decides whether it sends that domain name or resolves it first. That is why two settings can use the same SOCKS version while producing different DNS paths.

SOCKS5 vs SOCKS5h

The h in socks5h means hostname. In clients that support these URI schemes, it tells the library to pass the destination hostname to the SOCKS5 proxy. The proxy then resolves the hostname and connects to the resulting address.

SettingDestination DNS lookupWhat the SOCKS5 request carriesTypical reason to use it
socks5://Local machineAn IP address after local resolutionYou deliberately want local DNS or need a client-side resolver
socks5h://SOCKS5 proxyThe destination hostnameYou want the lookup to follow the proxy path
SOCKS v5 + browser remote DNSBrowser/proxy path, depending on its settingHostname when remote DNS is enabledYou are configuring a browser rather than a URL-aware script

These are client conventions, not two different proxy protocols. A SOCKS5 server can support hostname requests regardless of whether your client spells the endpoint socks5:// or socks5h://. The important question is what the application does before it starts the SOCKS handshake.

If you use a literal destination IP, there is no destination hostname to resolve for that request. That can be useful for a narrow diagnostic, but it does not test normal browsing, scraping, or API work where URLs contain hostnames.

For a 4G proxy farm, the same rule applies whether the endpoint is on a local box or a cloud-routed port. ProxyKite exposes HTTP and SOCKS5 access for each active dongle, so the consuming client still needs to choose its DNS behavior. The proxy formats guide shows the endpoint and authentication formats before you add the scheme required by your tool.

curl: --socks5 vs --socks5-hostname

curl makes the distinction explicit. The --socks5 option resolves the destination hostname locally. The --socks5-hostname option asks the proxy to resolve it. The same choice can be written in the proxy URL as socks5:// or socks5h://.

Set placeholders in your shell first. Keep real credentials out of a committed script and avoid putting them in a command that will be copied into a shared ticket or chat.

PROXY_HOST='proxy.example.net'
PROXY_PORT='30007'
PROXY_USER='replace-with-user'
PROXY_PASS='replace-with-password'
TARGET='https://example.com/'

This command uses local destination DNS:

curl --fail --silent --show-error \
  --socks5 "${PROXY_HOST}:${PROXY_PORT}" \
  --proxy-user "${PROXY_USER}:${PROXY_PASS}" \
  "${TARGET}"

This command sends the destination hostname to the SOCKS5 proxy:

curl --fail --silent --show-error \
  --socks5-hostname "${PROXY_HOST}:${PROXY_PORT}" \
  --proxy-user "${PROXY_USER}:${PROXY_PASS}" \
  "${TARGET}"

The equivalent URL forms are:

curl --fail --silent --show-error \
  --proxy "socks5://${PROXY_HOST}:${PROXY_PORT}" \
  --proxy-user "${PROXY_USER}:${PROXY_PASS}" \
  "${TARGET}"

curl --fail --silent --show-error \
  --proxy "socks5h://${PROXY_HOST}:${PROXY_PORT}" \
  --proxy-user "${PROXY_USER}:${PROXY_PASS}" \
  "${TARGET}"

Both commands should return the destination response through the proxy. A successful response proves that the proxy connection and authentication work; it does not, by itself, prove where DNS happened. Use a packet capture or a controlled hostname test as described below.

The proxy hostname is a separate detail. curl must resolve PROXY_HOST somehow before it can connect, even when --socks5-hostname is enabled. Do not treat that one local lookup as a leak of the destination hostname.

If you want to see the connection negotiation while debugging, add --verbose. Verbose output can show the proxy connection and SOCKS handshake, but it is not a complete DNS audit. For a broader curl check, see the published guide to testing a SOCKS5 proxy with curl.

Python Requests and other clients

Requests supports SOCKS through its optional dependency. Install it into the same Python environment that runs the worker:

python -m pip install 'requests[socks]'

The Requests SOCKS documentation states that socks5 resolves on the client and socks5h resolves on the proxy. Use socks5h for both destination schemes when you want HTTP and HTTPS URLs to follow the same rule:

import os
from urllib.parse import quote

import requests

user = quote(os.environ["PROXY_USER"], safe="")
password = quote(os.environ["PROXY_PASSWORD"], safe="")
host = os.environ["PROXY_HOST"]
port = os.environ["PROXY_PORT"]

proxy_url = f"socks5h://{user}:{password}@{host}:{port}"
proxies = {
    "http": proxy_url,
    "https": proxy_url,
}

response = requests.get(
    "https://example.com/",
    proxies=proxies,
    timeout=(10, 30),
)
response.raise_for_status()
print(response.status_code)

The http and https dictionary keys describe the destination URL schemes. They do not force the proxy itself to be an HTTP proxy. The socks5h:// value is what selects SOCKS5 with proxy-side hostname resolution.

If you intentionally need local DNS, change only the scheme:

proxy_url = f"socks5://{user}:{password}@{host}:{port}"

Encoding the username and password matters when they contain URL-reserved characters such as @, :, /, #, or %. Use separate secret fields when your library supports them. The longer Python Requests proxy guide covers authentication, timeouts, sessions, and safe retries around this core setting.

The same principle appears in other clients, but the spelling varies. Look for an option named remote DNS, proxy DNS, resolve hostname through proxy, or SOCKS5 hostname. A generic SOCKS5 dropdown does not tell you whether the application resolves the destination locally.

Browsers and remote DNS

Browsers usually expose the choice as a checkbox or policy rather than as a socks5h:// URL. In Firefox, open the connection settings, select SOCKS v5, enter the proxy host and port, and enable Proxy DNS when using SOCKS v5. Mozilla documents this behavior as the proxyDNS setting; current Firefox documentation says it defaults to true for SOCKS5, while older Firefox versions used a different default, so make the setting explicit when you need repeatable behavior.

Microsoft documents a different behavior for Edge: SOCKS5 requests use proxy-side name resolution, and Edge does not expose the Firefox-style toggle. Read the browser’s current proxy documentation when you deploy managed settings rather than assuming that all Chromium-based tools share Firefox’s controls.

Browser settings apply only to that browser profile. A scraper, command-line tool, browser extension, update service, or separate application may use its own resolver or bypass the browser proxy. Check these points when a browser appears clean but a worker still leaks:

  • Confirm the proxy is configured as SOCKS v5, not SOCKS4.
  • Enable the browser’s remote-DNS option when one exists.
  • Review bypass or no_proxy entries for destination domains.
  • Check extensions that make direct network requests.
  • Test IPv4 and IPv6 behavior if your machine has both enabled.
  • Remember that DNS prefetching or preconnect features can create lookups outside the request you are watching.

For a client that accepts a proxy URL, prefer socks5h://. For a client with separate browser fields, select SOCKS v5 and enable its remote-DNS control.

How to test for a DNS leak

Use a test hostname that has not already been resolved and a proxy endpoint that you are authorized to use. A cached result can make a local lookup invisible in a packet capture, while the proxy endpoint’s own hostname will still be resolved locally.

1. Watch local DNS traffic

On Linux, start a capture in one terminal:

sudo tcpdump -ni any '(udp port 53 or tcp port 53)'

In a second terminal, run the same hostname through socks5:// and then through socks5h://:

curl --proxy "socks5://${PROXY_HOST}:${PROXY_PORT}" \
  --proxy-user "${PROXY_USER}:${PROXY_PASS}" \
  "https://a-fresh-hostname.example/"

curl --proxy "socks5h://${PROXY_HOST}:${PROXY_PORT}" \
  --proxy-user "${PROXY_USER}:${PROXY_PASS}" \
  "https://a-different-fresh-hostname.example/"

With the usual local-resolver setup, the first request produces a local DNS query for its destination, while the second should not. You may still see a query for the proxy hostname. That is expected and is not the destination leak you are testing.

2. Use a controlled DNS name when possible

The strongest test uses a unique subdomain under a domain you control and an authoritative DNS log you can inspect. Put a random label in the URL, make one request with socks5h://, and check which resolver received the query. Repeat with socks5:// as a control.

This avoids relying on a public “DNS leak test” page and lets you distinguish a query from your machine, a local network resolver, or the proxy’s network. Do not reuse a cached label, and do not send sensitive hostnames to a third-party test service.

3. Account for encrypted DNS

Port 53 capture is useful but not universal. Your operating system or browser may use DNS over HTTPS or DNS over TLS, so the lookup could travel inside HTTPS or TLS instead of appearing as a plain DNS packet. In that case, inspect the browser’s DNS settings and use a controlled authoritative log alongside the local capture.

The result you want is consistent: the destination hostname is not resolved by the client’s ordinary local resolver when the request is configured for proxy-side DNS. If the proxy itself cannot resolve the hostname, the request may fail; a failure is not evidence that the hostname was resolved locally.

Common mistakes

Confusing the proxy hostname with the destination hostname

proxy.example.net is the server you connect to first. example.com is the destination. socks5h does not remove the need to resolve the proxy endpoint locally; it changes the handling of the destination hostname.

Assuming all SOCKS5 fields mean remote DNS

SOCKS5 is capable of carrying a hostname, but the client may choose to resolve that hostname first. Check the exact client option, scheme, or browser setting.

Using socks5h with a client that does not support it

Some applications reject an unknown scheme or silently fall back to a different proxy path. If the client has separate fields, use its documented remote-DNS setting. If it has no such setting, confirm behavior with a controlled test rather than guessing.

Testing only with an IP address

An IP-literal URL avoids the destination DNS step, so it cannot show whether normal hostnames leak. Use a fresh hostname for the DNS test and a normal hostname for the actual traffic test.

Treating one successful page load as proof

A page can load through the proxy while DNS, prefetching, an extension, or another application uses the local network. Test the exact client and workflow that will run in production.

FAQ

Is socks5h safer than socks5?

For destination-DNS privacy, socks5h is usually the correct choice because it asks the SOCKS5 proxy to resolve the hostname. It is not a complete privacy guarantee: the proxy still receives the hostname, and your client still needs to resolve the proxy endpoint.

Does SOCKS5 always prevent DNS leaks?

No. SOCKS5 supports hostname requests, but a client can resolve the destination locally and send only the resulting IP address to the proxy. Use the client’s remote-DNS option or the socks5h:// scheme, then verify the path.

What does the h mean in socks5h?

The h means “hostname”. It is a client URL convention that tells supported libraries to pass the destination hostname to the proxy for resolution. It does not describe a new SOCKS protocol version.

Does Python Requests support socks5h?

Yes. Install Requests’ optional SOCKS dependencies, then use a socks5h:// proxy URL in the http and https entries of the proxies dictionary. Requests documents socks5:// as client-side DNS and socks5h:// as proxy-side DNS.

Should I use socks5 or socks5h in curl?

Use socks5h:// or --socks5-hostname when the destination hostname should be resolved through the proxy. Use socks5:// or --socks5 only when local destination DNS is intentional or required by your workflow.

Previous Article

IPv6 Mobile Proxy: NAT64 and 464XLAT Explained

Next Article

How to Set Up a Proxy on iPhone and iPad