The SOCKS5 Protocol in Depth
SOCKS5, defined in RFC 1928, is the most capable proxy protocol available. It extends SOCKS4 with UDP support, IPv6 compatibility, proper authentication, and detailed error reporting. SOCKS5 is the recommended protocol for any use case that goes beyond simple HTTP/HTTPS web traffic.
Why SOCKS5 Matters
Most proxy protocols are limited to specific application-layer protocols. HTTP proxies only handle HTTP traffic. HTTPS proxies tunnel TCP but cannot handle UDP. SOCKS5 is unique in its ability to proxy virtually any network traffic — TCP connections, UDP datagrams, and even protocol negotiation for future extensions.
The Three-Phase Handshake
SOCKS5 uses a three-phase connection process, which is more structured than SOCKS4's single-packet handshake:
**Phase 1 — Method Negotiation**
The client announces which authentication methods it supports:
Client → Proxy: [0x05] [num_methods] [method_1] [method_2] ...
Proxy → Client: [0x05] [chosen_method]Common methods: 0x00 (no auth), 0x02 (username/password). If the proxy responds with 0xFF, no acceptable method was offered and the connection is terminated.
**Phase 2 — Authentication**
For username/password authentication (method 0x02), defined in RFC 1929:
Client → Proxy: [0x01] [uname_len] [uname] [passwd_len] [passwd]
Proxy → Client: [0x01] [status] (0x00 = success)**Phase 3 — Connection Request**
After authentication, the client requests the actual connection:
Client → Proxy: [0x05] [cmd] [0x00] [addr_type] [dst_addr] [dst_port]
Proxy → Client: [0x05] [status] [0x00] [addr_type] [bnd_addr] [bnd_port]Address types enable flexible destination specification: - `0x01`: IPv4 (4 bytes) - `0x03`: Domain name (1 byte length + name) — proxy resolves DNS - `0x04`: IPv6 (16 bytes)
UDP Association
SOCKS5's UDP support is its most distinctive feature. The UDP ASSOCIATE command (0x03) works differently from CONNECT:
- Client sends a CONNECT request with command 0x03, specifying which address/port it will send UDP from.
- Proxy allocates a UDP relay endpoint and returns its address and port.
- Client sends UDP datagrams to the proxy's relay port, each prefixed with a SOCKS5 UDP header containing the destination address and port.
- Proxy strips the header, forwards the datagram to the destination, and relays responses back with the same header format.
This enables proxying of DNS queries, VoIP traffic, gaming packets, and any other UDP-based communication.
Error Handling
SOCKS5 provides detailed error codes, unlike SOCKS4's binary grant/reject:
- 0x00: Succeeded
- 0x01: General SOCKS server failure
- 0x02: Connection not allowed by ruleset
- 0x03: Network unreachable
- 0x04: Host unreachable
- 0x05: Connection refused
- 0x06: TTL expired
- 0x07: Command not supported
- 0x08: Address type not supported
DNS Leak Prevention
When the client specifies a domain name (address type 0x03) instead of an IP address, the proxy performs DNS resolution. This prevents DNS leak attacks where a local DNS query reveals the target hostname even though traffic is proxied. Hex Proxies performs DNS resolution on our proxy infrastructure, ensuring that your target domains are never exposed through local DNS queries.
SOCKS5 with Hex Proxies
Hex Proxies fully supports SOCKS5 on all proxy types through `gate.hexproxies.com`. Our SOCKS5 implementation includes:
- Username/password authentication with the same credentials used for HTTP proxies
- Full domain name addressing for DNS leak prevention
- TCP CONNECT for all TCP-based protocols
- Automatic IP rotation (per-request or sticky sessions)
- IPv4 and IPv6 destination support
For most use cases, SOCKS5 with domain addressing and username/password authentication is the recommended configuration. It provides the best combination of compatibility, security, and flexibility.
Choosing SOCKS5 for Your Project
If your application uses any non-HTTP protocol, needs UDP support, or requires DNS leak prevention, SOCKS5 is the clear choice. It integrates seamlessly with Hex Proxies' rotation and geo-targeting features while supporting the widest range of application protocols.