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
- D: this parameter creates the SOCKS proxy port 60000
- N: Do not execute a remote command. This is useful for just forwarding ports.
- n: Redirects stdin from /dev/null (actually, prevents reading from stdin). This must be used when ssh is run in the background.
- T: Disable pseudo-terminal allocation.
$ 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 :) ;)