---
title: "SOCKS5 vs SOCKS5H: Where Does the DNS Lookup Happen?"
description: "With socks5:// your device resolves the domain; with socks5h:// the proxy does. That one letter decides DNS leaks and which location a site answers for."
url: https://proxynet.io/blog/socks5h-vs-socks5-dns
date: 2026-12-01
author: "Acar Diveroli"
category: "Proxies"
lang: en
---

# SOCKS5 vs SOCKS5H: Where Does the DNS Lookup Happen?

`socks5://` and `socks5h://` are two ways to write a connection to the same SOCKS5 proxy. The difference between them is who resolves the target site's name. With `socks5://`, your own device makes the DNS query and only an IP address goes to the proxy. With `socks5h://`, the domain name goes to the proxy as is, and the proxy resolves it. This post covers the difference between the two schemes, where DNS leaks come from and the right scheme in cURL and Python Requests.

> **Note: Short answer**
>
> `socks5h://` (`--socks5-hostname` in cURL) sends the domain name to the proxy, and the proxy resolves it. `socks5://` (`--socks5`) resolves the name on your device, so when you use a proxy, `socks5h://` is the right choice in most cases.

## Address types in SOCKS5

The SOCKS5 protocol accepts a target in three forms: an IPv4 address, an IPv6 address or a domain name. RFC 1928 tells them apart with the `ATYP` field in the connection request: `X'01'` means IPv4, `X'03'` a domain name and `X'04'` IPv6. For a domain name, the first byte carries the name's length, so a name can be at most 255 bytes.

The client decides which type to send, not the protocol. There is no separate version called "SOCKS5H". The `h` is a URL scheme convention that cURL introduced, and libraries such as Requests follow it. The handshake and authentication are the same under both schemes. We cover the protocol basics in our [SOCKS5 proxy guide](/blog/socks5-proxy-101).

| Scheme | Who resolves the name | What the proxy sees | cURL option |
|---|---|---|---|
| `socks5://` | Your device | IP address (`X'01'` / `X'04'`) | `--socks5` |
| `socks5h://` | The proxy server | Domain name (`X'03'`) | `--socks5-hostname` |

Always write the scheme explicitly in your code. Relying on a default means not knowing which side asks DNS.

## Where the DNS leak comes from

With `socks5://`, the DNS query does not pass through the proxy. Your device sends it to its own DNS server, which is usually your ISP or your company network. Traffic flows through the proxy, but the list of domains you visit stays on the local network. This is called a DNS leak.

`socks5h://` moves that query to the proxy side, and your local DNS server never sees the target name. The proxy can still learn the name either way. In an HTTPS connection, the name also travels in clear text in the SNI field of the TLS handshake. `socks5h` hides the name from your local network, not from the proxy.

There is one more limit: the scheme only covers the target name of that request. Other DNS queries an app makes outside its proxy setting are not affected. We gathered browser-side leak sources and a test method in our [WebRTC and DNS leak article](/blog/webrtc-dns-leak).

## Geo results and CDNs

A DNS answer can change with the location of whoever asks. According to RFC 7871, many authoritative name servers guess the user's network location from the IP the query comes from and pick the answer accordingly. Content delivery networks (CDNs) return different server addresses for the same domain in different regions.

With `socks5://`, that choice follows your location. Your device in Türkiye resolves the name and gets the address of a server near Türkiye, and then the proxy in Germany connects to that address. The site sees a German IP, but a server picked for Türkiye answers. The path gets longer, and region-specific content can arrive mixed.

With `socks5h://`, the proxy resolves the name and the server is picked for the proxy's location. The exit IP and the DNS answer then point to the same region. If you send country-targeted requests, this is where consistency comes from.

There is a side effect too: a name that only resolves on the proxy side never works with `socks5://`. Your device cannot find the name, and the request ends before any target reaches the proxy.

## When local resolution makes sense

`socks5://` is not always wrong. It helps when you deliberately want to resolve the name on your side. An example: before taking a new server live, you pointed the domain at that server's IP with the hosts file or cURL's `--resolve` option. With `socks5://`, the proxy connects to the IP you chose. With `socks5h://`, the proxy resolves the name in its own DNS and reaches the old server. In our test, the IP given with `--resolve` reached the proxy in the `socks5://` request, while the `socks5h://` request still sent the domain name.

If the proxy does not accept domain names, `socks5://` is also all you have. In both cases you knowingly accept a local DNS query. Outside these cases, make `socks5h://` your default.

## Two options in cURL

In cURL you can set the scheme two ways: at the start of the `-x` address or with a separate option. Both do the same job.

```bash
# The device resolves the name: the proxy sees an IP address
curl --socks5 pr.proxynet.io:8000 -U user:pass https://example.com/
curl -x "socks5://user:pass@pr.proxynet.io:8000" https://example.com/

# The proxy resolves the name: the proxy sees the domain name
curl --socks5-hostname pr.proxynet.io:8000 -U user:pass https://example.com/
curl -x "socks5h://user:pass@pr.proxynet.io:8000" https://example.com/
```

To give the proxy to every command, use the `ALL_PROXY` environment variable and write `socks5h://` in its value as well. In our test, cURL and Requests both read this variable, and the domain name reached the proxy.

```bash
export ALL_PROXY="socks5h://user:pass@pr.proxynet.io:8000"
curl https://example.com/
```

Proxynet's [SOCKS5 Proxy](https://proxynet.io/socks5-proxy) service carries UDP alongside TCP. The `h` here only concerns the target name of the TCP connection that cURL and Requests open.

## The scheme in Python Requests

Requests gets SOCKS support from an extra package, so run `pip install "requests[socks]"` first. Without the package, the request fails with `InvalidSchema: Missing dependencies for SOCKS support.`

```python
import requests

# socks5h: the proxy resolves the domain name
PROXY = "socks5h://user:pass@pr.proxynet.io:8000"
proxies = {"http": PROXY, "https": PROXY}

r = requests.get("https://example.com/", proxies=proxies, timeout=15)
print(r.status_code)
```

Fill in both keys of the dictionary. If you only set `https`, `http://` URLs go out without the proxy. Changing the one letter in the scheme is enough to move DNS, and the rest of the code stays the same. Authentication and environment variable details are in the [Python Requests proxy guide](/blog/python-requests-proxy).

## Debugging

The quickest way to see which side resolves the name is the `curl -v` output. With `socks5://`, cURL prints these lines before it connects (output from our local test server):

```text
* Host example.com:443 was resolved.
* IPv6: (none)
* IPv4: 104.20.23.154, 172.66.147.243
* Opened SOCKS connection from 127.0.0.1 port 53512 to example.com port 443 (via 127.0.0.1 port 1080)
```

With `socks5h://`, the `was resolved` and `IPv4:` lines never appear. The `Opened SOCKS connection … to example.com` line shows the domain name in both cases. That line is the trap: do not use it to decide.

Error messages also tell you where resolution happened:

| Symptom | Meaning |
|---|---|
| `curl: (6) Could not resolve host` | The device tried to resolve the name (`socks5://`) |
| `curl: (97) cannot complete SOCKS5 connection … (4)` | The proxy could not resolve the name and returned `X'04'` |
| Requests: `getaddrinfo failed` | The name failed to resolve on the device |
| Requests: `0x04: Host unreachable` | The name failed to resolve on the proxy |
| `X'08'` address type not supported | The proxy does not accept domain names |

If you see `(6)`, the problem is not the proxy. It is your own DNS or the scheme.

## How we tested

We ran the tests on December 1, 2026 on Windows 11. Versions: curl 8.22.0, Python 3.13.17, Requests 2.34.2, PySocks 1.7.1, urllib3 2.6.3. Our local SOCKS5 server, written in Python, implements RFC 1928 and RFC 1929 for username/password. For every incoming request it logs the `ATYP` value and the target address, then relays the connection. The targets were `example.com` and an unresolvable name under `.invalid`.

| Client | Scheme | Proxy log | Result |
|---|---|---|---|
| cURL | `--socks5` / `socks5://` | `X'01'` IPv4 address | 200 |
| cURL | `--socks5-hostname` / `socks5h://` | `X'03'` `example.com` | 200 |
| Requests | `socks5://` | `X'01'` IPv4 address | 200 |
| Requests | `socks5h://` | `X'03'` `example.com` | 200 |
| Both | `ALL_PROXY=socks5h://…` | `X'03'` `example.com` | 200 |
| cURL | `--resolve` + `socks5://` | `X'01'` the given IP | 200 |
| Both | `socks5://`, unresolvable name | No target logged | Error on device |
| Both | `socks5h://`, unresolvable name | `X'03'` name, `X'04'` reply | Error on proxy |

We did not measure the geo effect in this setup, because the test server ran on the same machine and in the same country as the client.

## The bottom line

Write `socks5h://` in every tool that uses a proxy, and use the same scheme in environment variables. If you work with a country-targeted [Residential Proxy](https://proxynet.io/residential-proxy), resolving DNS in the exit country as well keeps results consistent. Above all, check the `was resolved` line in the `curl -v` output: if it is there, you are resolving the name yourself.

## Sources

- [RFC 1928, SOCKS Protocol Version 5](https://www.rfc-editor.org/rfc/rfc1928.html), sections 4-6: rfc-editor.org
- [RFC 7871, Client Subnet in DNS Queries](https://www.rfc-editor.org/rfc/rfc7871.html), section 1: rfc-editor.org
- [Everything curl, SOCKS proxy](https://everything.curl.dev/usingcurl/proxies/socks.html): everything.curl.dev
- [Requests, Advanced Usage, SOCKS](https://requests.readthedocs.io/en/latest/user/advanced/#socks): requests.readthedocs.io

## Frequently asked questions

### What does socks5h mean?

It means a SOCKS5 connection where the proxy resolves the hostname. The trailing `h` stands for "hostname". The client does not turn the target into an IP address; it sends the domain name to the proxy as is. The protocol is still SOCKS5. The only difference is the address type in the connection request: `X'03'` for a domain name, `X'01'` or `X'04'` for an IP.

### What do I need to install for socks5h in Requests?

You need the `requests[socks]` package. The `pip install "requests[socks]"` command brings in PySocks, the library SOCKS support depends on. After installing it, writing the proxy address as `socks5h://user:pass@host:port` is enough. Without the package, Requests does not send the request and raises a missing dependency error. That error means the package is missing, not that the scheme is wrong.

### Is there a similar setting for HTTP proxies?

No. A request to an HTTP proxy already carries the target as a domain name. For HTTPS sites, the client sends `CONNECT example.com:443` and the proxy resolves the name; with plain HTTP, the full URL goes to the proxy. That is why the `http://` proxy scheme has no option like `h`. The question of where DNS happens only comes up with SOCKS proxies.

### Does socks5h fully prevent DNS leaks?

No. `socks5h` only covers the target name of the request that goes through the proxy. DNS queries the app makes outside the proxy still leave from the local network. To be sure, check the proxy log or the `curl -v` output. If you use a browser, run a separate DNS leak test as well, because the browser may make its own queries.

### What happens if the proxy does not accept domain names?

The connection fails with an address type error. RFC 1928 defines the `X'08'` reply for an unsupported address type. In that case `socks5h://` does not work, and resolving the name locally with `socks5://` is the only option left. Keep in mind that the DNS query will then leave from your local network. In such errors, cURL prints the proxy's reply code in parentheses at the end of the message.

### The proxy is right but the site shows the wrong country. Why?

Local DNS resolution is one of the reasons. With `socks5://`, the CDN picks a server for your location, while the exit IP is in another country. First switch the scheme to `socks5h://`. If the problem persists, look at other signals the site receives: account country, language header and stored cookies. These can set the location independently of the IP.
