SOCKS5 is a proxy protocol that relays TCP and UDP traffic between a client and a server without reading the application data, so it works with any app that supports SOCKS, not just web browsers. It is defined in RFC 1928, supports username/password authentication, and does not encrypt traffic on its own.
Because SOCKS5 operates between the application and transport layers instead of parsing HTTP, it is not limited to web traffic. If your use case needs SOCKS5, it's worth confirming a provider supports it before committing.
How a SOCKS5 Connection Works
- The client connects to the proxy, conventionally on TCP port 1080, and lists the authentication methods it supports.
- The proxy picks one, such as no authentication or username/password, and the client authenticates.
- The client sends the destination as an IPv4 address, IPv6 address or domain name. It uses CONNECT for TCP or UDP ASSOCIATE for UDP.
- The proxy opens the connection and relays data in both directions.
For UDP, the proxy replies with the address of a UDP relay. The client sends its datagrams there, and the association lasts only as long as the TCP connection that set it up.
SOCKS5 vs. SOCKS4
SOCKS5 extends the older SOCKS4 protocol:
- Authentication: SOCKS4 has only a user ID field. SOCKS5 adds methods such as username/password and GSSAPI.
- UDP: SOCKS4 handles TCP only. SOCKS5 can also relay UDP.
- IPv6: SOCKS4 accepts only IPv4 destinations. SOCKS5 adds IPv6.
- Hostnames: SOCKS5 lets the client send a domain name for the proxy to resolve. SOCKS4 needs the SOCKS4a extension to do this.
SOCKS5 vs. HTTP Proxy
An HTTP proxy reads each HTTP request and can add headers such as Via. A SOCKS5 proxy relays bytes without reading them, so it can carry non-web traffic too. The HTTP Proxy entry has a side-by-side table.
Authentication and Encryption
- Required methods: RFC 1928 says compliant implementations must support GSSAPI and should support username/password.
- Passwords in cleartext: the username/password method, defined in RFC 1929, sends the password unencrypted. The RFC doesn't recommend it where traffic can be sniffed.
- No encryption of its own: SOCKS5 doesn't encrypt the data it relays. HTTPS traffic stays encrypted because TLS runs between your app and the website.
Where DNS Lookups Happen
- curl: a
socks5://proxy URL resolves hostnames on your machine.socks5h://has the proxy resolve them. - Chrome: SOCKS5 hostnames are always resolved at the proxy. For SOCKS4, Chrome resolves them on the client.
A lookup made on your own machine can reveal the sites you visit to your local DNS resolver, which is a DNS leak.
What It Means for Web Scraping
- Chrome can't log in to SOCKS5: Chrome's documentation says it supports no SOCKS5 authentication methods and uses SOCKS5 only for TCP requests. For headless Chrome, use IP-based authentication or an HTTP proxy with credentials.
- Keep lookups on the proxy: use
socks5h://in curl so DNS queries go through the proxy instead of your network. - Test with SSH:
ssh -D <port>makes OpenSSH act as a local SOCKS4 and SOCKS5 server, which is a quick way to try a SOCKS setup.