4

Is it possible to use SSH port forwarding in Windows Subsystem for Linux?

If I download the native OpenSSH package, I can forward ports:

> ssh -L 5432:localhost:5432 me@host
Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.6.5-x86_64-linode71 x86_64)
etc

But if I try the same thing from within WSL bash:

$ ssh -L 5432:localhost:5432 me@host
bind: Address already in use
Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.6.5-x86_64-linode71 x86_64)
etc

I am running bash as administrator (and have tried it not running as administrator as well).

8

Self answer: See this bug. The following works:

ssh -L 127.0.0.1:5432:localhost:5432 me@host

The problem is that IPv6 doesn't work in WSL and the failure flows through to the IPv4 port forwarding.

  • Wish I had discovered this a few hours ago :) – TekiusFanatikus Apr 8 '17 at 11:18
  • 1
    In more detail: ssh -L 5432:localhost:5432 implicitly means ssh -L localhost:5432:localhost:5432. That first localhost gets looked up locally and Windows gives the IPv6 loopback address by default, so ssh tries to open a local IPv6 port 5432. IPv6 doesn't work in WSL, so opening the port fails. By explicitly giving 127.0.0.1 as the local address, you force ssh to use IPv4. – Tom Apr 10 '17 at 10:15
  • Would ssh -4.... work to force IPv4? – Felipe Alvarez Apr 21 '18 at 16:57
  • @FelipeAlvarez - I don't know and I don't have one to hand to try it out, sorry. – Tom Apr 24 '18 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.