![Linux Administration Cookbook](https://wfqqreader-1252317822.image.myqcloud.com/cover/18/36699018/b_36699018.jpg)
Using SSH to create a SOCKS Proxy
SSH is great.
I never get tired of talking about how great it is, and it would be remiss of me to not mention one of its best features: the ability to quickly and easily set up a SOCKS proxy.
In the previous sections, we forwarded individual ports, but what if we were using a bastion host to connect to a slew of different websites within a network? Would you like to add tens of lines to your SSH config file? Or manually type out each port and mapping every time?
I didn't think so.
That's where the -D flag comes in.
See -D [bind_address:]port in the SSH manual page (https://man.openbsd.org/ssh):
IPv6 addresses can be specified by enclosing the address in square brackets. Only the superuser can forward privileged ports. By default, the local port is bound in accordance with the GatewayPorts setting. However, an explicit bind_address may be used to bind the connection to a specific address. The bind_address of "localhost" indicates that the listening port be bound for local use only, while an empty address or '*' indicates that the port should be available from all interfaces.
What this means is that with a single command, you can set up a connection that you can then forward traffic through (from a web browser, or other applications that support SOCKS proxies). You don't have to punch holes through firewalls, and you don't have to manually map ports.
Let's get started.