brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ssh -D 1080 turns an SSH connection into a SOCKS proxy

Network and access
~/tips/tip-ssh-dynamicforward-socks

ssh -D 127.0.0.1:1080 [email protected]

Starts a local SOCKS proxy that sends your browser traffic through an SSH server.

A SOCKS proxy sounds like something you need extra software for. With ssh it is one flag, and any server I can log in to becomes an exit point for my browser.

The -D option sets up local dynamic application-level port forwarding. ssh listens on a port on your machine and acts as a SOCKS server; the manual says SOCKS4 and SOCKS5 are supported. Every connection that arrives on that port is sent through the SSH connection, and the server on the other end decides where it goes, based on the SOCKS request.

ssh -D 127.0.0.1:1080 [email protected]

The argument has the form [bind_address:]port. I spell out 127.0.0.1 so it is obvious that the proxy is meant for this machine only. Keep the session open and point an app at it: in a browser’s network settings choose a manual proxy with SOCKS host 127.0.0.1 and port 1080. Close the SSH session and the proxy is gone.

If you do this often, put it in ~/.ssh/config so the flag is built in:

Host proxy-example
    HostName example.com
    User user
    DynamicForward 127.0.0.1:1080

Then ssh proxy-example is enough. The ssh_config manual describes DynamicForward with the same [bind_address:]port argument.

Two caveats. First, only programs that you configured to use the SOCKS proxy go through the tunnel; everything else on the machine keeps using your normal connection. Second, ssh encrypts the hop between you and the server. From the server onwards the traffic leaves the way any other traffic from that machine would, and whoever runs the server can see which destinations you ask for. Only use a server you trust.

Ports below 1024 are privileged and the manual says only root can forward them, so stay with something like 1080 or 8080.

Further reading: ssh(1), ssh_config(5)

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link