SOCKS5 vs SOCKS5h and Where DNS Is Resolved

With SOCKS5, the client can send the destination’s IP address or its hostname to the proxy. Use two requests to the same URL to see how the socks5 and socks5h options change where the destination name is resolved.

Two rack servers on a workbench with separate Ethernet paths and a printed network diagram

Which side resolves the destination hostname?

In cURL and Python Requests, socks5:// asks the client to resolve the destination hostname before it requests a connection through the SOCKS proxy. The client sends an IPv4 or IPv6 address to the proxy. With socks5h://, the client sends the original hostname and the proxy resolves it. Both choices use SOCKS version 5. The extra h is a client-side option for handing the hostname to the proxy. SOCKS proxy schemes in cURL. SOCKS5 request address types.

The client still has to find the proxy’s own address in either mode. A typo in the gateway hostname or a failed lookup for that name can break both requests before any SOCKS exchange begins. The hostname that changes behavior is the one in the destination URL. Keep that URL as a hostname when comparing the modes. Typing an IP literal changes the TLS and virtual-host assumptions of the test as well as removing the hostname lookup.

The meaning of a scheme is also client-specific. Chromium’s SOCKSv5 proxy configuration resolves destination hostnames on the proxy side even though the URI can be written socks5://. Read the documentation for the application you are testing, especially when cURL is standing in for a browser or another runtime. Chromium SOCKSv5 behavior.

Compare socks5 and socks5h with cURL

Use a SOCKS5 proxy you operate or are authorized to test. Replace socks-gateway.example:1080 with the same gateway in both commands. The examples target the TestMyProxies IP endpoint. It returns JSON with the IP that reached the site, so you can also check whether the proxy exit is the one you expected. Keep the destination, proxy account and network constant. The empty --noproxy value ensures cURL applies the explicitly selected proxy in this controlled test. More cURL proxy examples.

curl --disable --noproxy "" --proxy "socks5://socks-gateway.example:1080" \
  --silent --show-error --max-time 15 "https://testmyproxies.com/api/my-ip"

curl --disable --noproxy "" --proxy "socks5h://socks-gateway.example:1080" \
  --silent --show-error --max-time 15 "https://testmyproxies.com/api/my-ip"

On Windows, use curl.exe and put each command on a single line. PowerShell 7.3 or later preserves the empty argument in its default native argument handling for cURL. If your approved endpoint calls for username and password authentication, supply the same credentials for both tests. cURL can prompt for the password when you pass only a username via --proxy-user. Keep credentials out of saved command examples and support logs.

Both calls can succeed and report the same exit IP because both requests leave through the same gateway. The JSON shows the source of the connection at the destination. It says nothing about which resolver picked the destination address. To prove the DNS difference, repeat with an approved test hostname and look at the request address type in the proxy’s diagnostics, if available. A domain name in the SOCKS request shows that the client handed it off. A numeric address shows the client supplied an address.

Verify the result with a hostname you control

If you administer both networks, choose a test hostname with a known DNS answer on each network and an HTTPS test endpoint that logs incoming requests. Record the expected answer from each resolver before sending either request. Keep the hostname in the URL so normal certificate and virtual-host checks still apply. Correlate timestamps from cURL, the proxy and the test server to confirm which resolved address was contacted. The same address from both resolvers is a valid result. In that case the proxy’s address-type log is the clearest evidence of where resolution happened.

Resolve the proxy hostname separately if the failure mentions the gateway. A SOCKS destination name can go to the gateway for resolution only after the client has reached that gateway.

Repeat the DNS comparison with Python Requests

Install SOCKS support in the project’s virtual environment with python -m pip install "requests[socks]". The https key in the proxy mapping applies to the destination URL. The scheme in the value tells Requests where to resolve that destination. The example uses explicit session settings to keep inherited proxy or bypass variables from changing either test. Use trust_env = False here only in an authorized comparison where you also control any required TLS settings. Requests SOCKS documentation.

import requests

target = "https://testmyproxies.com/api/my-ip"
gateway = "socks-gateway.example:1080"  # Replace with your approved proxy

with requests.Session() as session:
    session.trust_env = False
    for scheme in ("socks5", "socks5h"):
        try:
            response = session.get(
                target,
                proxies={"https": f"{scheme}://{gateway}"},
                timeout=(5, 10),
                allow_redirects=False,
            )
            if response.status_code == 200:
                print(scheme, response.json()["ip"])
            else:
                print(scheme, "destination HTTP", response.status_code)
        except requests.RequestException as error:
            print(scheme, type(error).__name__)

The timeout tuple sets connect and read timeouts. If your environment uses a private CA for approved inspection, pass the trusted CA bundle explicitly for this comparison because trust_env = False also skips environment-based CA settings. The example leaves certificate verification enabled. For ordinary HTTP proxy configuration, see the Python Requests proxy guide.

Troubleshoot DNS failures without guessing from one error

If only socks5:// fails and the client reports a destination lookup error, test the same hostname from the machine or container that runs the client. A simple check for the local system resolver is python -c "import socket; print(socket.getaddrinfo('testmyproxies.com', 443, type=socket.SOCK_STREAM))". Substitute the affected host that you are allowed to test. This checks what the local runtime resolves. A cURL build can use a different resolver backend, so compare its own diagnostic message with that result.

If only socks5h:// fails, ask the gateway operator to check the destination hostname on the proxy’s network. A SOCKS host-unreachable response can also reflect access rules or a route failure after resolution. If both attempts fail, check whether you can reach and authenticate to the proxy first. For a test with an internal name, confirm that both the intended resolver and the destination route are approved for that environment before changing the scheme. SOCKS5 reply codes. Why a proxy can behave differently inside Docker.

All proxy testing guides · Open the proxy tester