Image for post
Image for post
Photo by Claudia Soraya on Unsplash

What is SOCKS?

SOCKS is a network protocol that exchanges packets between two computers through a proxy server.

How a SOCKS proxy can help me?

It can used to solve many problems, because SOCKS can proxy traffic of any type this means that you can use it in cases that you have network restrictions but you still have access to one server that has all the network accesses you need, you can use this server as a SOCKS proxy and get the accesses you need through this server.

One other problem that it solves is that you dont need to do one-to-one port forwarding like SSH tunneling, since you have connected to a SOCKS server, all the network resources are available to you almost trasparently, you still need some configuration on the client side to use the SOCKS protocol to connect to the network resources you want.

Example: Create a SOCKS proxy that will listen on port 60000 and will have the network accesses of server ssh-host-gw

  • ssh-host-gw: is a server that has all the network accesses you need
$ ssh -D 60000 -nNT user@ssh-host-gw

Example: SSH to host server1 using the SOCKS proxy

Note: To do this, you need to have allready installed the nc command

  • -o ProxyCommand=’nc -x 127.0.0.1:60000 %h %p’ this parameter tells SSH to use the SOCKS proxy we have set on localhost and listens on port 60000 to connect to server1
$ ssh -o ProxyCommand='nc -x 127.0.0.1:60000 %h %p' user@server1

You can make your life easier if you have sort of a script that will execute on start and and create the SOCKS proxy, also you can modify your ssh_config file to automatically prefix the ProxyCommands to avoid much typing.

i hope you found this article useful :) ;)

Written by

DevOps engineer, loves Linux, Python, cats and Amiga computers

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store