SSH SOCKS Proxy: Dynamic Forwarding

An SSH SOCKS proxy lets a SOCKS-aware application send TCP connections through an SSH server. OpenSSH creates the local listener with -D; the application still needs that listener in its own proxy settings. Start with an explicit loopback bind, then check the application request separately from SSH authentication.

8Local configuration evaluations
6Accepted by ssh -G
2Invalid port controls rejected
0End-to-end tunnel tests

An explicit wildcard bind remained in the configuration even with gatewayports no.

Configuration evaluated

1. Follow the connection from application to destination

The path has three parts: your application connects to a local SOCKS port, SSH carries a forwarding channel to the server, and the server opens the requested destination connection. The destination normally sees the server network egress. The application does not become proxied until it uses the configured local endpoint.

Three stages of an SSH SOCKS proxy path, with example addresses and what to verify at each stage.
StageAddress in the exampleWhat to verify
Application → listener127.0.0.1:1080SOCKS selected in the application
SSH transportdemo@example.com:22Server identity and account authentication
Server → destinationexample.com:443Forwarding permission and server egress

The local SOCKS port and the remote SSH port have different jobs. Changing -p 2222 changes the SSH transport destination; it does not change port 1080 in the application. With dynamic forwarding, the application supplies each destination, unlike a fixed local forward that names one target service in advance.

SSH encrypts the transport between the SSH client and server. The connection leaving the server still needs its own application protection, such as HTTPS. Dynamic forwarding is not a device-wide VPN and does not provide general UDP forwarding. Other applications, DNS queries and browser WebRTC traffic need their own scope checks. Read the SOCKS5 protocol overview for context.

2. Build a local listener and test one request

Use an SSH account and server you are authorized to access. This builder generates commands locally; it does not connect, collect credentials or start a listener. It fixes the bind address to 127.0.0.1 and keeps SSH in the foreground. Replace the example SSH hostname with your own before running the output.

Host accepts IPv4 or a DNS name. No schemes, credentials or IPv6 literals. Ports: 1–65535.

Enter your SSH endpoint and local port.

Your commands will appear here.

Step 1 — Inspect your configuration. Run ssh -V to identify the client. Use ssh -G with the intended options to inspect effective settings without opening a session. User configuration and host aliases can add forwards or jump hosts. Our experiment used -F none to isolate parsing; the generated connection command uses your normal SSH configuration.

Step 2 — Start the foreground session. Run the SSH line in one terminal. Check the server host key against a trusted source when prompted, then authenticate using your normal account method. The -N option requests no remote command. A quiet terminal can be normal after authentication; leave it running while testing from another terminal.

Step 3 — Make a SOCKS request. Run the generated curl.exe command in Windows PowerShell. On systems where the binary is named curl, use that executable name. The example uses socks5h so the destination name travels through the SOCKS request. The hostname of the SSH server itself is still resolved before the transport connects.

A returned HTTPS document establishes that request path, not every destination or every app. Inspect the exit address from the configured application when exit identity matters. Using socks5 instead resolves the destination locally in curl. Do not generalize either result to unrelated browser DNS or UDP traffic.

3. What eight OpenSSH configuration checks showed

We evaluated eight commands with ssh -G -F none on OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2. Each command included a dynamic forward, startup failure handling and keepalive options. The local client printed its effective configuration or rejected the specification. No SSH server was contacted, and no listener or destination request was tested.

Eight local ssh -G configuration evaluations: six accepted cases and two invalid port controls.
Configuration caseObserved outputInterpretation
Explicit loopback[127.0.0.1]:1080; gatewayports noBind address preserved
Bind omitted1080; gatewayports noNo explicit bind in dump
Explicit wildcard[0.0.0.0]:1080; gatewayports noWildcard preserved alongside no
-g plus loopback[127.0.0.1]:1080; gatewayports yesInspect bind and flag together
Remote SSH port 2222port 2222; local port 1080Transport and listener separated
Repeated identical forwardOne dynamicforward output lineDuplicate entry normalized
Local ports 65536 / 0Both exit 255; bad specificationTwo invalid input controls

The wildcard row is the useful distinction: gatewayports no alone is not enough to infer the complete requested bind scope. Read the explicit DynamicForward address as well. This output is configuration evidence; checking which interfaces actually listen requires a running session and operating-system socket inspection. This page does not claim that runtime verification occurred.

The duplicated forward was accepted and represented once in the dump. That does not mean an occupied local port will be available when SSH starts. Similarly, accepted parsing does not prove credentials, server forwarding policy or destination access. The eight-case CSV and raw arguments and output retain that evidence boundary.

4. Diagnose the failing stage and stop the tunnel

If SSH cannot bind the local port, inspect whether another process already uses it, then choose another port and update the application. ExitOnForwardFailure makes requested forwarding setup errors terminate the session. It does not turn every later channel failure into a startup failure. A server policy denial can appear only when an application requests a destination.

If authentication succeeds but requests fail, use -v on your own session to inspect channel errors. An administratively prohibited message suggests server forwarding restrictions; refusal or resolution errors can refer to the remote destination. Review logs before changing settings. A server administrator may need to inspect AllowTcpForwarding, DisableForwarding, PermitOpen or account key restrictions.

Keepalive settings help detect an unresponsive SSH transport. ServerAliveInterval 30 and ServerAliveCountMax 3 request periodic checks with a bounded unanswered count; they do not retry the session or certify destination health. If the session ends, rerun the command and repeat the application check. Persistent service supervision is a separate operational decision.

To stop this foreground example, press Ctrl+C in the SSH terminal and remove the application proxy setting. Leaving the app pointed at a closed port causes failures. Check the DNS path separately when changing clients. This experiment is a dated snapshot with no automatic refresh. References: OpenSSH command manual, client configuration and server policy.

Keep the browser profile pointed at the listener that is actually running.

Download RoxyBrowser

For a desktop profile workflow, review RoxyBrowser on its official site. Configure and verify the local SOCKS endpoint in the intended profile; the SSH session remains a separate process.

Frequently Asked Questions

Does ssh -D create a SOCKS proxy or an HTTP proxy?

OpenSSH dynamic forwarding provides a local SOCKS listener supporting SOCKS4 and SOCKS5 requests. Configure the application for SOCKS. An HTTP proxy field does not become compatible merely because the host and port are the same.

Does ExitOnForwardFailure prove that websites are reachable?

No. It makes SSH exit when a requested forwarding setup fails. It does not certify later connections through the forward to every destination. Test a request from the configured application after the session starts.

Where does DNS resolution happen with an SSH SOCKS proxy?

It depends on the client request. With curl, socks5h sends the destination hostname through the SOCKS connection, while socks5 resolves it locally. Resolving the SSH server hostname itself remains a separate step on your client.

Can another device use my loopback SSH proxy?

A listener bound to 127.0.0.1 is for the same device. Another device cannot use its own 127.0.0.1 to reach your computer. Sharing a listener requires a reachable bind address, firewall policy and access controls; this builder keeps the listener local.