TodayTools

SOCKS version 5

How SOCKS5 works

A general-purpose relay for any app

Donate
L5SessionPort 1080TCP
What brings you here?

Watch it happen

How much detail

An app reaches a website through a SOCKS5 server, which also looks up the name for it.

Mateo's laptop
Cafe router
Internet
SOCKS5 server
Server's DNS
www.example.com
Wi-FiInternetCableSetupRequestResponseLookupEncrypted

5 steps, 14 packets

First up: Connect. Press Play to watch it happen, one step at a time.

0 of 50/5

What is SOCKS5?

SOCKS5 is a simple relay. An app connects to a SOCKS server, says which host and port it wants, and the server makes that connection and passes bytes both ways. Unlike an HTTP proxy, it does not care what protocol the app speaks: web, mail, chat or games all work.

It is used to send one app's traffic out through another network, for example through a server in an office. The SSH command ssh -D starts a SOCKS server on your own machine that tunnels through SSH. SOCKS5 itself does not encrypt anything.

Think of it like this. SOCKS5 is like a switchboard operator. You call the operator, say who you are and which number you want, and the operator connects the call. After that the operator just keeps the line open and never listens in on what language you speak.

Step by step

Normal

5 steps

An app reaches a website through a SOCKS5 server, which also looks up the name for it.

  1. 1

    Connect

    TCP to port 1080

    The app opens one TCP connection to the SOCKS server. Everything for this target will go through it.

  2. 2

    Greeting

    Agree on a login method

    The client says it speaks version 5 and lists its login methods. The server picks one.

  3. 3

    Login

    Username and password

    With method 0x02 the client sends a username and password (RFC 1929). The server answers success or closes the connection.

  4. 4

    CONNECT

    Please reach www.example.com:443

    The client sends the target as a domain name (address type 3). The server does the DNS lookup and opens TCP to the target, then replies with success and the address it is using.

  5. 5

    Relay

    Bytes pass both ways

    From now on the SOCKS server copies bytes between the app and the website. Here those bytes are TLS, so the server cannot read them. SOCKS does not understand or change the app's protocol.

DNS leak

3 steps

The app looks up the name itself before using SOCKS, so the cafe network sees which site you visit.

  1. 1

    Local lookup

    The name goes to the cafe DNS

    Some apps resolve the name themselves first. That DNS question goes to the cafe router in plain text, outside the SOCKS path.

  2. 2

    CONNECT by address

    Address type 1 (IPv4)

    The app then asks the SOCKS server to connect to 203.0.113.10. The connection is relayed, but the name already leaked.

  3. 3

    The fix

    Send the name, not the address

    Use socks5h:// or curl --socks5-hostname, or the app's remote DNS option. Then the request carries the domain (address type 3) and the SOCKS server does the lookup.

UDP relay

3 steps

A game sends UDP through SOCKS5 with UDP ASSOCIATE, each datagram wrapped in a small header.

  1. 1

    Ask for a UDP relay

    CMD 0x03 on the TCP connection

    After the greeting and login, the client sends UDP ASSOCIATE. Behind NAT it does not know its own public port yet, so it sends all zeros.

  2. 2

    Relay port given

    Send datagrams to port 40500

    The server replies with an address and port for UDP. The relay lasts only while the TCP control connection stays open.

  3. 3

    Wrapped datagrams

    10-byte header plus data

    Each UDP packet to the relay starts with a small header naming the real target. The server strips it, sends the data on, and wraps replies the same way.

Myths and mix-ups

  • SOCKS5 does not encrypt your traffic; only what the app sends inside, such as TLS, is protected.
  • SOCKS5 is not only for web browsing; it relays any TCP connection and UDP too.
  • Using SOCKS does not always hide your DNS; the app must send names to the server, not addresses.
  • SOCKS5 does not read or change your data; it only passes bytes along.

Try it yourself

Run these on your own computer to see SOCKS5 at work.

  • Fetch through SOCKS with remote DNS

    curl -v --socks5-hostname proxy.example.com:1080 https://example.com/

    Replace with your SOCKS server. The name is resolved by the server, not your laptop.

  • Make a SOCKS server over SSH

    ssh -D 1080 -N user@example.com

    Starts a local SOCKS5 server on port 1080 that tunnels through your SSH login.

  • Use that local server

    curl --socks5-hostname 127.0.0.1:1080 https://example.com/

    The request leaves from the SSH server's network, encrypted until it gets there.

SOCKS5 at a glance

Layer
Session (5), between TCP and the app
Default port
1080
Transport
TCP, plus UDP through UDP ASSOCIATE
Commands
CONNECT, BIND, UDP ASSOCIATE
Address types
IPv4, domain name, IPv6
Login
None, username/password, or GSSAPI
Encryption
None of its own
Standard
RFC 1928 (1996)

Defined inRFC 1928 (SOCKS5)RFC 1929 (username/password login)RFC 1961 (GSSAPI login)

Header fields

What SOCKS5 puts in its messages, with example values from the stories above.

SOCKS5 greeting

VER
5
NMETHODS
2
METHODS
0x00 (no auth), 0x02 (username/password)The client lists the login methods it can do. The server picks one.

SOCKS5 method choice

VER
5
METHOD
0x02 (username/password)0xFF here would mean: none of your methods are acceptable, goodbye.

SOCKS username/password

VER
1 (sub-negotiation version)
UNAME
mateo
PASSWD
(8 bytes)Sent as plain bytes. SOCKS5 has no encryption of its own, so only use it over a trusted or encrypted path.

Test yourself

Question 1 of 4Score 0

What does ATYP 0x03 in a SOCKS5 request mean?

Questions people ask

What is the difference between SOCKS5 and an HTTP proxy?

An HTTP proxy understands web requests and can cache or filter them. SOCKS5 understands nothing about the app; it just relays TCP connections and UDP datagrams for any protocol.

What port does SOCKS5 use?

1080 is the standard port. Any port works if the client is told to use it.

Is SOCKS5 a VPN?

No. It works per app, only for apps set to use it, and it does not encrypt. A VPN carries all of the device's traffic through an encrypted tunnel.

What is socks5h?

In curl and many tools, socks5h:// means: send host names to the SOCKS server and let it do the DNS lookup. Plain socks5:// resolves names locally first.

Is SOCKS5 safe to use?

The relay is as safe as the path to it. Over the open internet, wrap it in SSH or use only TLS inside, because SOCKS5 sends logins and data without encryption.

Donate