Guide

SSH SOCKS proxy: SOCKS5, socks5h, DNS and application settings

An SSH SOCKS proxy is a SOCKS5 listener on your computer, created with ssh -D, that sends each application's TCP connections out through your SSH server. Each application has to be pointed at it, and DNS needs separate attention.

Short answer

An SSH SOCKS proxy is a SOCKS5 listener on 127.0.0.1, created with ssh -N -D 1080 user@server, that sends an application's TCP connections out through the SSH server. Each application has to be pointed at it. Use the setting that sends host names to the proxy (socks5h:// in curl and git, "Proxy DNS when using SOCKS v5" in Firefox) so DNS lookups happen on the SSH server and do not leak to your local resolver.

This page works with any SOCKS5 proxy made by OpenSSH. Transputty, the Windows SSH tunnel manager this site belongs to, is in development with no public build yet; see the release status.

This page is the reference: what SOCKS5 is, where DNS is resolved, which setting each application needs and when a proxy is the right tool. For numbered steps on Windows, follow how to set up an SSH SOCKS proxy.

Where the proxy comes from

The proxy is created by SSH dynamic port forwarding:

ssh -N -D 1080 deploy@bastion.example.com
application --SOCKS5--> 127.0.0.1:1080  ==SSH (encrypted)==>  bastion.example.com  -->  destination

How that works inside SSH, what the server must allow, and how it compares with a fixed forward are covered in dynamic port forwarding (ssh -D). This page is about the other half: making applications use the proxy correctly.

A SOCKS proxy suits web applications and many destinations, because the application names each destination and keeps real host names. For one fixed service such as a database, or a program with no SOCKS setting, a local forward is simpler.

What is SOCKS5?

SOCKS is a small protocol for asking a proxy to make a network connection on your behalf. Version 5 is defined in RFC 1928. A client connects to the proxy, negotiates an authentication method, and sends a request naming a destination as an IPv4 address, an IPv6 address or a domain name, plus a port. The proxy connects and then relays bytes without interpreting them, which is why SOCKS works for HTTPS, SSH, database protocols and anything else built on TCP.

SOCKS4 / SOCKS4a SOCKS5 HTTP proxy (CONNECT)
Specification Informal memos; no RFC RFC 1928 HTTP CONNECT method
Destination as host name SOCKS4: no, IPv4 address only. SOCKS4a: yes Yes Yes
IPv6 destinations No Yes Yes
Authentication A user ID field, no password Negotiated; username and password in RFC 1929 HTTP proxy authentication
UDP No Defined by the protocol (UDP ASSOCIATE) No
Provided by ssh -D Yes Yes, for TCP connections, without authentication No

The last row matters in practice. An application whose only proxy setting is "HTTP proxy" cannot talk to an SSH SOCKS listener directly. It needs either SOCKS support or a small local HTTP-to-SOCKS converter in between.

DNS: socks5 versus socks5h

A SOCKS5 client can put either an IP address or a host name in its request. That choice decides where DNS lookups happen.

Scheme or setting Who resolves the host name Effect
socks5:// (curl, git and many libraries) Your computer, with your local resolver Your local network sees the lookups; names known only to the remote network fail
socks5h:// The proxy end, which for ssh -D is the SSH server Lookups are hidden from the local network; internal names resolve
socks4:// Your computer Local lookups
socks4a:// The proxy end Remote lookups

The h stands for host name. For reaching internal sites through a bastion, socks5h is nearly always what you want, both for privacy and because a name like wiki.internal exists only in the server's DNS.

How do I check for a DNS leak?

A DNS leak means the traffic goes through the proxy while the name lookups still go to your local resolver. Two ways to check:

  1. Use a name only the remote side knows. If curl -x socks5h://127.0.0.1:1080 http://wiki.internal/ works and the socks5:// form fails with "Could not resolve host", name resolution is happening where you expect for each scheme.
  2. Watch port 53 locally. Capture DNS traffic while you browse through the proxy, with Wireshark using the capture filter port 53, or on Linux and macOS:
sudo tcpdump -n port 53

If queries for the sites you open appear, the application is resolving locally. One caveat: a browser using DNS over HTTPS does not send queries on port 53 at all, so an empty capture is not proof by itself. The first test is more direct.

Application settings

Every entry assumes the proxy from above on 127.0.0.1:1080.

Application Setting Where host names are resolved
Firefox Settings › Network Settings › Manual proxy configuration: SOCKS Host 127.0.0.1, Port 1080, SOCKS v5, with the HTTP and HTTPS proxy fields empty Locally, unless "Proxy DNS when using SOCKS v5" is ticked
Chrome and Edge Start with --proxy-server="socks5://127.0.0.1:1080" and a separate --user-data-dir By the proxy for page loads; see the note below
curl -x socks5h://127.0.0.1:1080 or --socks5-hostname 127.0.0.1:1080; ALL_PROXY for a whole shell By the proxy with socks5h; locally with socks5 or --socks5
git (HTTPS remotes) git config --global http.proxy socks5h://127.0.0.1:1080 By the proxy with socks5h
Windows system proxy Not dependable for SOCKS; see the note below Not applicable

The click-by-click steps, with a check after each, are in the SSH SOCKS proxy tutorial. The notes below cover what is easy to get wrong.

Firefox

Firefox has its own proxy settings, independent of the operating system, which makes it the simplest browser to dedicate to a tunnel. Entries in "No proxy for" bypass the proxy, and a separate Firefox profile keeps your everyday browsing direct.

Chrome and Edge

Chromium-based browsers normally follow the operating system's proxy settings. To point one at a SOCKS proxy without touching system settings, start it with a command-line flag. Use a separate profile directory, because the flag is ignored when the new window joins a browser process that is already running:

& "C:\Program Files\Google\Chrome\Application\chrome.exe" `
  --user-data-dir="$env:LOCALAPPDATA\ChromeTunnel" `
  --proxy-server="socks5://127.0.0.1:1080"

Edge accepts the same --proxy-server flag through msedge.exe.

On DNS, Chromium's own documentation states that with the socks5:// scheme host names for proxied URLs are resolved by the proxy server, not locally. In other words, socks5 in Chrome behaves like socks5h in curl. The same document notes that the flag applies to URL loads only, that DNS prefetching and other browser components may still perform local lookups, and suggests a catch-all resolver rule as a safeguard, excluding the proxy's own address:

--host-resolver-rules="MAP * ~NOTFOUND , EXCLUDE 127.0.0.1"

Browser behavior changes between versions, so verify with the check above if it matters to you.

Windows system proxy settings

The proxy page in Windows Settings (Network & internet › Proxy) and the older Internet Options dialog configure the WinINET proxy, which is designed around HTTP proxies. The older dialog's Advanced button does show a "Socks" field. It is commonly reported to use SOCKS4 with local name resolution, not SOCKS5, and we have not verified its behavior on current Windows 11 builds, so treat it as unreliable for this purpose. A SOCKS4 request also will not work against a proxy that accepts only SOCKS5.

In addition, system proxy settings are advisory: many programs, including most command-line tools and services, do not read them. Configure SOCKS per application. If you need every program on the PC to use the remote network, that is the job of a VPN.

curl and git

curl --socks5 and -x socks5:// resolve names locally; only the socks5h and --socks5-hostname forms send the name to the proxy. On Windows, type curl.exe in PowerShell 5.1, where plain curl is an alias for a different command.

git's http.proxy applies to HTTP and HTTPS remotes only. Git remotes that use SSH (git@host:...) do not read it; route those with ProxyJump in your SSH configuration, described in the port forwarding overview.

Sending only some sites through the proxy

Usually you want internal names to use the tunnel and everything else to go direct. Two common tools:

  • A proxy auto-configuration (PAC) file, which browsers can load from their proxy settings:
function FindProxyForURL(url, host) {
  if (dnsDomainIs(host, ".internal")) return "SOCKS5 127.0.0.1:1080";
  return "DIRECT";
}
  • A proxy-switching browser extension such as FoxyProxy, which applies URL patterns and lets you switch from the toolbar.

What a SOCKS proxy does not hide

  • The SSH connection itself. Your network can see that you hold an SSH connection to the server, and roughly how much data it carries.
  • Applications you did not configure. Everything else on your machine connects directly, as before.
  • UDP traffic. An SSH SOCKS proxy relays TCP only. Browser features that use UDP, such as WebRTC calls, may bypass the proxy or fail, depending on the browser's settings.
  • DNS, unless you handled it as described above.
  • Who you are to the web site. Cookies, logins and browser fingerprints are unchanged. Only the source IP address differs.
  • Your destinations from the server's operator. Connections originate at the SSH server, and its administrator and network can log where they go. Content inside TLS stays private; plain HTTP does not.

SOCKS proxy or VPN?

SSH SOCKS proxy VPN
What it covers TCP connections from applications you configure All traffic the routes cover, from every program
Setup An SSH login; no administrator rights on your PC VPN server and client, usually administrator rights
UDP No Yes
DNS Per application (socks5h, browser settings) Set for the whole system
Selectivity Natural: only what you point at it Needs split-tunnel configuration
Good for A browser or a few tools reaching a private network or testing from another location Whole-machine access, non-proxy-aware software, teams

How Transputty handles SOCKS proxies

Transputty is in development and has no public build yet. In the current internal build for Windows 11, a SOCKS proxy is a rule of kind "SOCKS (-D)"; the "SOCKS" preset creates one on 127.0.0.1:1080. Applications are configured exactly as on this page, with a SOCKS5 proxy at that address.

A connected SOCKS rule in the inspector (bottom right), labelled 'SOCKS5 proxy · DNS resolved on the server'. This rule listens on 127.0.0.1:1081 because another connection in the list already uses 1080. The app is connected to local test servers with fictional host names.

Transputty does not resolve proxied host names locally: a name sent by the application is handed to the SSH server, and the inspector shows "SOCKS5 proxy · DNS resolved on the server". That only applies when the application sends names, so the socks5h and Firefox settings above still matter. While a dropped connection is being re-established the proxy port stays bound; see automatic reconnection.

Limits: the proxy is SOCKS5 only, so SOCKS4 and SOCKS4a clients will not work, which is one more reason not to rely on the Windows "Socks" field. It handles CONNECT requests only, with no UDP. The app has no proxy username or password to set, and the listener is on loopback only. Transputty does not change browser or Windows proxy settings for you. The SSH SOCKS proxy tutorial walks through a full setup.

Common questions

What is the difference between socks5 and socks5h?

socks5 and socks5h are proxy URL schemes used by curl and many other tools. With socks5:// the application resolves the host name itself, using your local DNS, and sends the proxy an IP address. With socks5h:// it sends the host name to the proxy, so the lookup happens at the far end. Through an SSH SOCKS proxy that means the SSH server resolves the name.

When should I use an SSH SOCKS proxy instead of a local forward?

Use an SSH SOCKS proxy (ssh -D) for web applications or many destinations: the application names each destination itself and keeps the real host names, so HTTPS certificates and virtual hosts work. Use a local forward (ssh -L) for one fixed service such as a database, or for a program with no SOCKS setting. A SOCKS proxy only helps programs that can be configured to use one.

Does an SSH SOCKS proxy hide my IP address?

From the sites reached through the proxy, yes: they see the SSH server's address instead of yours. It does not hide that you are connected to the SSH server, it does not cover applications that are not configured to use the proxy, and it does not carry UDP. The operator of the SSH server can see which destinations you connect to.

What is a DNS leak with a SOCKS proxy?

A DNS leak is when an application sends its traffic through the proxy but still looks up host names with your local DNS resolver. Your local network or internet provider can then see which names you visit, and names that exist only in the remote network fail to resolve. The fix is to make the application pass host names to the proxy.

Can I set an SSH SOCKS proxy for all of Windows?

Not dependably. The Windows system proxy settings are built around HTTP proxies, and applications are free to ignore them. Configure SOCKS in each application that supports it, such as Firefox, a Chromium-based browser started with a proxy flag, curl or git. If every program on the PC must use the remote network, a VPN is the right tool.

Is a SOCKS proxy over SSH encrypted?

The part between your computer and the SSH server is encrypted by SSH. From the SSH server to the destination, traffic travels as the application sent it: HTTPS stays protected by TLS end to end, while plain HTTP is readable on that last leg. SOCKS itself adds no encryption; the SSH connection provides it.

Sources and further reading

Transputty keeps SSH tunnels running on Windows

Local, remote and SOCKS5 forwards in one window, automatic reconnection with ports that stay bound, and a clear reason when something fails. In development; no public build yet.