๐ŸŽ‰ Premium Proxies ยท 3-Day Free TrialClaim Now โ†’
Proxy Basic

What Is a SOCKS Proxy? SOCKS4 vs SOCKS5 Explained

A SOCKS proxy routes any TCP or UDP traffic at the session layer, not just HTTP. Learn how SOCKS4, SOCKS4a, and SOCKS5 differ, and when to use each.

S SparkProxy 1 15 min read
Share
What Is a SOCKS Proxy? SOCKS4 vs SOCKS5 Explained

An HTTP proxy speaks one language: HTTP. It reads your request, modifies headers, and forwards the content. That works well for web traffic, but it breaks down the moment you need to proxy an SMTP connection, a gaming client, or a custom TCP application that doesn't speak HTTP.

A SOCKS proxy solves that problem by working at a lower layer. It doesn't inspect or rewrite application-layer data. It simply acts as a relay for any TCP (and optionally UDP) connection, making it the right tool for protocols that HTTP proxies can't handle.

Key Takeaways

  • A SOCKS proxy operates at Session Layer 5 of the OSI model. It tunnels raw TCP (and SOCKS5 UDP) traffic without reading or modifying application-layer content.
  • SOCKS5 is the current standard, defined in RFC 1928 (IETF, 1996). It adds authentication, IPv6 support, and UDP relay, none of which exist in SOCKS4.
  • SOCKS4a is an informal extension to SOCKS4 that allows hostname resolution by the proxy, not the client. It isn't defined in any RFC but is widely implemented.
  • SOCKS5 proxies do not automatically prevent DNS leaks. If your application resolves the hostname before passing it to the proxy, the DNS query bypasses the proxy entirely.
  • For HTTP web scraping and browser automation, HTTP or HTTPS proxies are generally easier to integrate. SOCKS5 is the better choice for non-HTTP protocols, multi-protocol applications, and tools with native SOCKS5 support like curl and Python's requests.

What Is a SOCKS Proxy?

A SOCKS proxy (Socket Secure proxy) is a general-purpose proxy protocol that relays network traffic at the session layer (Layer 5 of the OSI model). Unlike HTTP proxies, which operate at the application layer and understand HTTP methods, headers, and status codes, a SOCKS proxy forwards raw TCP streams, and in the case of SOCKS5, UDP datagrams, without inspecting or modifying the payload.

The core function is simple: your client establishes a TCP connection to the SOCKS proxy, sends a connection request specifying the destination host and port, and the proxy opens a second connection to that destination. From that point, all data flows bidirectionally through the proxy without interpretation.

Because the proxy doesn't need to understand the application protocol, a SOCKS proxy can relay:

  • HTTP and HTTPS traffic
  • SMTP and IMAP email connections
  • FTP transfers
  • IRC and XMPP messaging
  • P2P protocols like BitTorrent
  • Gaming clients
  • Any custom TCP application

This protocol-agnosticism is the defining advantage over HTTP proxies. The trade-off is that SOCKS proxies cannot modify headers, inject cache-control directives, or perform application-layer functions that HTTP-aware proxies handle natively.

SOCKS listens on port 1080 by default, the registered IANA port for the protocol. Many providers also offer SOCKS5 on port 443 or custom ports to avoid firewall blocks.


What Are the Differences Between SOCKS4, SOCKS4a, and SOCKS5?

Three versions of the SOCKS protocol exist in practice. The differences in capability are significant enough to affect which version your use case requires.

FeatureSOCKS4SOCKS4aSOCKS5
RFC / SpecificationNone (original Ying-Da Lee spec)Informal extension[RFC 1928](https://www.rfc-editor.org/rfc/rfc1928) (1996)
TCP CONNECT supportโœ“โœ“โœ“
UDP ASSOCIATE supportโœ—โœ—โœ“ (optional)
IPv6 supportโœ—โœ—โœ“
Authenticationโœ—โœ—โœ“ (username/password, GSS-API)
Hostname resolutionClient-side onlyProxy-side (de-facto extension)Proxy-side or client-side
DNS leak protectionโœ—PartialPartial (see note below)

SOCKS4 requires the client to resolve the hostname to an IPv4 address before connecting. If DNS resolution fails on the client side, the connection fails. There's no authentication mechanism, anyone who can reach the proxy port can use it.

SOCKS4a is a de-facto extension (not in any RFC) that allows the client to pass a hostname string instead of a resolved IP address. The proxy resolves the hostname on the client's behalf. This was added to handle cases where the client cannot or should not resolve DNS, for example, when the client is inside a restricted network. Most modern proxy clients and servers support SOCKS4a.

SOCKS5 is the current standard (RFC 1928, IETF 1996). It adds IPv6 addressing, UDP relay (the ASSOCIATE command), and a pluggable authentication framework. Sub-negotiation for username/password authentication is specified separately in RFC 1929 (IETF, 1996).

INFO-GAIN: SOCKS5 supports hostname resolution by the proxy, but this only prevents DNS leaks if your SOCKS5 client is configured to send the hostname string to the proxy (not resolve it first). In curl, --socks5-hostname sends the hostname to the proxy for resolution. --socks5 resolves the hostname locally, which leaks DNS. The distinction is subtle but matters for privacy-sensitive operations.


Free trial

Scraping at scale? Skip the blocks.

Fast, unblockable datacentre proxies with unlimited bandwidth.

How Does SOCKS5 Establish a Connection?

The SOCKS5 connection process follows a defined three-phase handshake specified in RFC 1928.

Phase 1, Authentication negotiation:

The client sends a greeting with the list of authentication methods it supports:

Client โ†’ Proxy:  VER=0x05, NMETHODS=0x02, METHODS=[0x00, 0x02]
                 (SOCKS5, 2 methods: no-auth + username/password)

Proxy โ†’ Client:  VER=0x05, METHOD=0x02
                 (selected method: username/password)

If the proxy selects 0x02 (username/password), sub-negotiation per RFC 1929 follows. If the proxy selects 0xFF, no acceptable method was found and the connection closes.

Phase 2, Authentication (if required):

Client โ†’ Proxy:  VER=0x01, ULEN, UNAME, PLEN, PASSWD
Proxy โ†’ Client:  VER=0x01, STATUS=0x00  (0x00 = success)

Phase 3, Connection request:

Client โ†’ Proxy:  VER=0x05, CMD=0x01 (CONNECT), RSV=0x00,
                 ATYP=0x03 (domain), DST.ADDR="example.com", DST.PORT=443

Proxy โ†’ Client:  VER=0x05, REP=0x00 (success), RSV=0x00,
                 ATYP, BND.ADDR, BND.PORT

CMD values:

  • 0x01, CONNECT (TCP stream)
  • 0x02, BIND (accept incoming connection, rarely used)
  • 0x03, UDP ASSOCIATE (UDP relay)

Once the proxy returns a success response, raw data flows bidirectionally through the established tunnel. The proxy does not inspect, modify, or log the payload content.


What Authentication Methods Does SOCKS5 Support?

SOCKS5 supports a pluggable authentication framework. Three methods are defined by IANA and relevant RFCs:

Method byteMethodSpecification
`0x00`No authentication requiredRFC 1928
`0x01`GSSAPIRFC 1961
`0x02`Username/passwordRFC 1929
`0x03`, `0x7F`IANA assigned (reserved)N/A
`0x80`, `0xFE`Private/vendor methodsN/A
`0xFF`No acceptable methodsRFC 1928

No authentication (0x00) is the default for many private proxy deployments where access is controlled by IP allowlisting rather than credentials. If your client IP is on the proxy's allowlist, no username or password is required.

Username/password (0x02) is the most common method for commercial proxy services. Credentials are sent in plaintext over the SOCKS5 connection, which means SOCKS5 over unencrypted TCP transmits credentials in the clear. For credential security, use SOCKS5 through a TLS tunnel or ensure the proxy endpoint uses TLS transport.

GSSAPI (0x01) enables Kerberos-based mutual authentication. This is standard in enterprise environments using Active Directory but uncommon in commercial proxy services.

INFO-GAIN: Commercial residential and datacenter proxy providers almost universally use 0x02 username/password. They typically authenticate via either static credentials or an IP-allowlist whitelist (0x00). If your provider gives you a user:pass@host:port URI, it's using method 0x02.


How Does a SOCKS Proxy Compare to an HTTP Proxy?

The choice between SOCKS5 and HTTP proxy depends on your application's protocol requirements and how much application-layer control you need.

AttributeHTTP/HTTPS ProxySOCKS5 Proxy
OSI layerLayer 7 (Application)Layer 5 (Session)
Protocols supportedHTTP, HTTPS (via CONNECT)Any TCP + UDP (SOCKS5)
Header modificationYes, can modify, inject, strip headersNo, passes raw TCP
AuthenticationHTTP Basic, Digest, NTLMNone, username/password, GSSAPI
IPv6 supportDepends on implementationYes (RFC 1928)
UDP supportNoYes (SOCKS5 ASSOCIATE)
DNS resolutionClient-sideProxy-side (with SOCKS4a/5 hostname mode)
Caching supportYes (forward proxy caching)No
Native browser supportYesYes (Firefox/Chrome settings)
curl integration`--proxy http://host:port``--socks5-hostname host:port`
Typical port80, 443, 8080, 31281080

For web scraping and browser automation, HTTP proxies are typically the better fit. They integrate more cleanly with HTTP clients, allow header injection (e.g., forwarding User-Agent), and most web-specific tools are designed around HTTP proxy support.

For non-HTTP protocols, email, FTP, P2P, gaming, custom TCP apps, SOCKS5 is often the only option that works without protocol-specific proxy support baked into the application.

A practical note: some providers offer the same proxy pool accessible via both HTTP and SOCKS5 endpoints. If your use case is purely HTTP/HTTPS web traffic, either works, but HTTP proxies often provide better diagnostic output and easier debugging.


Which Use Cases Require SOCKS5 Instead of an HTTP Proxy?

SOCKS5 is required or preferable over HTTP proxies in these scenarios:

Non-HTTP protocol proxying. Any application that uses SMTP, IMAP, POP3, FTP, IRC, or a custom TCP protocol cannot use an HTTP proxy. SOCKS5 proxies these connections transparently. An email client authenticating via IMAP over a corporate proxy, for example, needs SOCKS5.

P2P and BitTorrent. P2P clients use both TCP and UDP connections to communicate with peers and trackers. HTTP proxies can't handle UDP traffic. SOCKS5 with UDP ASSOCIATE support (when available from the provider) can proxy these connections. Note that many commercial proxy providers don't enable UDP ASSOCIATE by default.

Gaming applications. Online games typically use UDP for low-latency communication. Routing game traffic through a SOCKS5 proxy can reduce region-based latency or bypass ISP-level throttling on gaming ports.

SSH tunneling alternatives. When SSH tunneling isn't available, a SOCKS5 proxy can act as a forwarding layer for multi-protocol traffic. Tools like proxychains on Linux and proxifier on Windows support routing any application's traffic through a SOCKS5 proxy transparently.

Multi-protocol automation. If your automation stack uses HTTP requests alongside non-HTTP API calls, WebSocket connections, or raw TCP connections, a SOCKS5 proxy can handle the full mix through one proxy endpoint.

Reduced header fingerprinting. For anti-detection purposes, SOCKS5 avoids the automatic injection of proxy-identifying headers (Via, X-Forwarded-For) that some HTTP proxy implementations add. Properly configured SOCKS5 traffic arrives at the destination looking like a direct connection at the header layer, though IP reputation detection still applies. See the proxy anonymity levels guide for a full treatment of this topic.

For straightforward HTTP/HTTPS web scraping via residential proxies, HTTP proxies are simpler to configure and debug. SOCKS5 isn't a default upgrade, it's the right tool for specific protocol requirements.


How Do You Configure a SOCKS5 Proxy?

curl:

# Resolve hostname via the proxy (recommended, prevents DNS leaks)
curl --socks5-hostname user:pass@proxy.example.com:1080 https://httpbin.org/ip

# Resolve hostname locally, then connect via proxy (leaks DNS)
curl --socks5 user:pass@proxy.example.com:1080 https://httpbin.org/ip

Use --socks5-hostname for all privacy-sensitive operations. The --socks5 flag resolves the hostname on your machine before the proxy connection, which means your DNS queries are visible to your local resolver and ISP.

Python (requests + PySocks):

import requests

proxies = {
    "http":  "socks5h://user:pass@proxy.example.com:1080",
    "https": "socks5h://user:pass@proxy.example.com:1080",
}

response = requests.get("https://httpbin.org/ip", proxies=proxies, timeout=15)
print(response.json())

The socks5h:// scheme (note the h) tells requests (via the requests[socks] package, which requires PySocks) to perform hostname resolution on the proxy side, equivalent to --socks5-hostname in curl. Plain socks5:// resolves locally.

Install the dependency: pip install requests[socks]

Python (aiohttp for async):

import aiohttp

async def fetch(url: str) -> dict:
    async with aiohttp.ClientSession() as session:
        async with session.get(
            url,
            proxy="socks5://user:pass@proxy.example.com:1080",
        ) as resp:
            return await resp.json()

Firefox: Settings โ†’ General โ†’ Network Settings โ†’ Manual proxy configuration โ†’ SOCKS Host: proxy.example.com, Port: 1080, SOCKS v5. Check "Proxy DNS when using SOCKS v5" to prevent DNS leaks.

Environment variable (system-wide):

export ALL_PROXY="socks5h://user:pass@proxy.example.com:1080"

Many CLI tools respect ALL_PROXY. Verify with each tool's documentation.


What Are the Security Risks of SOCKS5 Proxies?

Credential exposure over plaintext connections. SOCKS5 username/password authentication (RFC 1929 method 0x02) transmits credentials in plaintext over the TCP connection. If the connection between your client and the proxy isn't encrypted, credentials are visible to anyone who can intercept the traffic. Commercial proxy providers who require authentication typically offer TLS endpoints or IP allowlisting as alternatives.

DNS leaks. As noted above, using socks5:// instead of socks5h:// in your client causes hostname resolution to happen locally. The DNS query reveals the destination hostname to your local DNS resolver and upstream provider before the proxy is involved. This is a common misconfiguration. Always verify with a DNS leak test (dnsleaktest.com) when confidentiality matters.

No payload encryption. A SOCKS5 proxy is a relay, not a tunnel. It forwards your traffic without encrypting it. If you're proxying HTTP (not HTTPS) traffic, the destination content is visible to the proxy and any intermediate nodes. Use HTTPS endpoints and verify TLS certificate validation is enabled in your client.

Open SOCKS proxies. Public or open SOCKS5 proxies without authentication are frequently abused for spam, credential stuffing, and DDoS amplification. Using an unverified open proxy exposes you to traffic interception, malicious content injection, and association with abusive traffic from shared IPs. Use only proxies from providers you trust, with authenticated access.

IP reputation. A SOCKS5 connection arriving at a destination server looks like a direct connection at the header layer. However, the proxy's IP address is still evaluated by destination-side IP reputation systems. Datacenter IPs frequently appear in abuse databases regardless of protocol. For scraping and data collection where detection avoidance matters, IP reputation is often a larger factor than protocol choice. See the residential proxy guide for context on IP pool types.


How Do You Test Your SOCKS5 Proxy Connection?

Step 1, Verify the proxy IP is being used:

curl --socks5-hostname user:pass@proxy.example.com:1080 https://httpbin.org/ip

Expected response: {"origin": ""}, not your real IP.

Step 2, Verify DNS is resolving via the proxy:

curl --socks5-hostname user:pass@proxy.example.com:1080 https://httpbin.org/get

Check the response headers. If X-Forwarded-For is absent and the origin field shows the proxy IP, DNS resolution happened at the proxy. To confirm DNS isn't leaking, run a test at dnsleaktest.com with your proxy active.

Step 3, Confirm no proxy-identifying headers were added:

curl --socks5-hostname user:pass@proxy.example.com:1080 https://httpbin.org/headers

A properly configured SOCKS5 connection through a commercial proxy should show no Via, X-Forwarded-For, or Forwarded headers. SOCKS5 doesn't add these, but HTTP proxies configured as SOCKS5 endpoints sometimes do.

Interpreting the results:

Test resultMeaning
`origin` = proxy IP โœ“IP routing through proxy is working
`origin` = your real IP โœ—Proxy is not being used, check config
`Via` header presentProxy is injecting HTTP headers (expected for HTTP proxy, unexpected for SOCKS5)
DNS leak detected โœ—Using `socks5://` instead of `socks5h://`, switch to hostname mode
Connection timeoutProxy port blocked by firewall, try port 443 if available

INFO-GAIN: httpbin.org/headers tests HTTP header injection but doesn't assess IP reputation or TLS fingerprinting. Even with clean headers and the correct proxy IP, destination sites with active bot protection evaluate TLS fingerprints (JA3/JA4) and behavioral signals independently. A passing header test doesn't guarantee acceptance by hardened targets.


Conclusion

A SOCKS proxy gives you a protocol-agnostic relay at the session layer, the most flexible transport-level proxy type available. SOCKS5 in particular adds authentication, IPv6 support, and UDP relay that make it useful across a broader range of applications than any HTTP proxy can cover.

The practical decision comes down to protocol requirements. If your stack is HTTP/HTTPS only, an HTTP proxy is simpler to configure and debug. If you need to proxy non-HTTP traffic, multi-protocol connections, or want to avoid HTTP header injection by design, SOCKS5 is the right choice.

Two configuration details have an outsized impact on both security and reliability: always use socks5h:// (hostname-mode) rather than socks5:// to prevent DNS leaks, and verify your proxy configuration with an IP and DNS leak test rather than assuming it's working correctly.

For production use at scale, IP reputation, not protocol, typically determines whether your requests succeed or fail. Whether you use HTTP or SOCKS5, the quality of the IP pool matters more than the proxy protocol.


Related guides: What Is a Forward Proxy? ยท Proxy Ports Explained ยท Proxy Anonymity Levels ยท What Is a Residential Proxy?

Frequently asked questions

Is SOCKS5 faster than an HTTP proxy? {#faq-speed}

At the protocol level, SOCKS5 has less overhead because it doesn't parse or modify HTTP headers. In practice, the latency difference is negligible compared to the network round-trip time to the proxy server. The more meaningful performance factors are the proxy provider's uptime and reliability, the proxy's geographic proximity to your target, and available bandwidth per connection.

Can I use SOCKS5 with Playwright or Puppeteer? {#faq-browsers}

Yes. Both support SOCKS5 proxy configuration. In Playwright: Browser.launch(proxy={"server": "socks5://user:pass@host:1080"}). In Puppeteer: pass --proxy-server=socks5://host:1080 as a launch argument. Chromium and Firefox handle hostname resolution via the proxy when using socks5:// in browser launch args, browser behavior differs from curl/requests here, so DNS leak testing is still advised.

Does SOCKS5 support HTTPS? {#faq-https}

Yes. SOCKS5 relays raw TCP traffic, so it tunnels TLS/HTTPS connections without modification. Your client establishes a TLS connection to the destination through the SOCKS5 relay. The proxy sees encrypted bytes and can't read the payload. This is different from an HTTP CONNECT proxy, functionally the same outcome, different mechanism.

What port does SOCKS5 use? {#faq-port}

Port 1080 is the IANA-registered default port for SOCKS. Commercial providers often offer SOCKS5 on additional ports such as 443 or 8080 to reduce the risk of firewall-based blocking. See the proxy ports guide for a full breakdown of common proxy port assignments.

Can SOCKS5 proxies handle UDP traffic? {#faq-udp}

The SOCKS5 protocol specifies a UDP ASSOCIATE command for relaying UDP datagrams (RFC 1928, Section 7). However, not all commercial proxy providers enable UDP ASSOCIATE on their endpoints. Most residential and datacenter proxy services support TCP CONNECT only. If UDP relay is required, for gaming, DNS-over-SOCKS, or P2P, verify UDP ASSOCIATE support explicitly with your provider before purchasing.


Limited-time ยท 50% off

Get 50% off your first purchase

Premium datacentre proxies with unlimited bandwidth. Use the code at checkout.

Offer ends soon โ€” claim it before it's gone

Claim Discount
S

Written by

SparkProxy

Proxy infrastructure and web-data experts at SparkProxy.

Keep reading

Related articles

What Is a Rotating Proxy API and How It Works

What Is a Rotating Proxy API and How It Works

A rotating proxy API gives you one endpoint that serves a fresh IP per request or sticky sessions, so you never manage a proxy list. Here is how it works.

SparkProxyยทProxy Basic