How to create a SOCKS proxy server through SSH

Socket Secure (SOCKS) is an Internet protocol that routes network packets between a client and server through a proxy server. SOCKS5 additionally provides authentication so only authorized users may access a server. Practically, a SOCKS server proxies TCP connections to an arbitrary IP address, and provides a means for UDP packets to be forwarded.

Dynamic port forwarding through SSH turns your SSH client into a SOCKS proxy server. SOCKS is a little-known but widely-implemented protocol for programs to request any Internet connection through a proxy server. Each program that uses the proxy server needs to be configured specifically, and reconfigured when you stop using the proxy server.

Start SOCKS proxy server through a target server:

➜  ~  ssh -D 1080 user@target-server

Use SOCKS proxy through SSH:

➜  ~  ssh -o ProxyCommand='/usr/bin/nc -x 127.0.0.1:1080 %h %p' user@target-server

Use SOCKS proxy through Chrome (following flags):

--proxy-server="socks5://127.0.0.1:1080"
--host-resolver-rules="MAP * 0.0.0.0 , EXCLUDE myproxy"

Use SOCKS proxy through Firefox:

1) go to Edit -> Preferences -> Advanced -> Network -> Connection -> Settings...
2) check "Manual proxy configuration"
3) make sure "Use this proxy server for all protocols" is cleared
4) clear "HTTP Proxy", "SSL Proxy", "FTP Proxy", and "Gopher Proxy" fields
5) enter "127.0.0.1" for "SOCKS Host"
6) enter "1080" (or whatever port you chose) for Port.

comments powered by Disqus