FMCorz
6/30/2016 - 5:59 PM

Port forwarding using SSH

Port forwarding using SSH

Local port forwarding

ssh -nNT -L LOCALPORT:DESTINATION:DESTPORT SSHACCOUNT

To forward localhost:5000 to destination.net:80:

ssh -nNT -L 5000:destination.net:80 user@example.net

Proxy HTTP

ssh -nNT -D LOCALPORT SSHACCOUNT

Using the following, the local port 8080 will proxied through example.net.

ssh -nNT -D 8080 user@example.net

Then, set-up your browser:

SOCKS host: localhost
      port: 8080
      
  [x] Socks v5

Arguments explained

  • -n Redirects stdin from /dev/null (actually, prevents reading from stdin). This must be used when ssh is run in the background.
  • -N Do not execute a remote command. This is useful for just forwarding ports (protocol version 2 only).
  • -T Disable pseudo-terminal allocation.
  • -L [bind_address:]port:host:hostport Local port forward to host:hostport
  • -D [bind_address:]port Local dynamic application-level port forwarding