20

What's the difference between using SOCKS (SSH -D) and local port forwarding (SSH -L)

2

1 Answer 1

26

With -L, SSH forwards all connections to a fixed destination. When you connect to the local port, all data you send goes straight to the remote host which you specified in -L. This, obviously, requires you to know which host you want to forward connections to.

With -D, the destination is "dynamic" – after connecting to the local port, you have to use the SOCKS proxy protocol to further connect to whatever remote host you want. This basically makes SSH a real proxy server, suitable for such activities as web browsing, where you cannot know in advance the destination.

Run ssh -D 1080, for example, and configure Firefox to use a SOCKS 5 proxy at localhost:1080.

4
  • 2
    I often use ssh -D 8080 myhomecomputer when I use my laptop on public wifi.
    – Evan Krall
    Commented Jul 24, 2011 at 8:35
  • 2
    @EvanKrall Is the benefit of that approach the fact that all traffic (assuming applications are indeed using the SOCKS proxy) will be encrypted through your SSH connection (i.e. there will not be any plain text network requests) ? Also, how would one make sure all traffic is sent through the proxy? Is there a recommended way to do this for all applications?
    – blong
    Commented Jan 16, 2014 at 19:09
  • 2
    @blong: The recommended way would be to use an OS-wide VPN connection instead. Commented Sep 9, 2016 at 7:41
  • Ah, I see, thanks @grawity . I thought it might be something one could implement without a VPN client :)
    – blong
    Commented Sep 9, 2016 at 12:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .