12

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).

1 Answer 1

16

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.

4
  • Wish I had discovered this a few hours ago :)
    – TechFanDan
    Commented Apr 8, 2017 at 11:18
  • 2
    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
    Commented Apr 10, 2017 at 10:15
  • Would ssh -4.... work to force IPv4? Commented Apr 21, 2018 at 16:57
  • @FelipeAlvarez - I don't know and I don't have one to hand to try it out, sorry.
    – Tom
    Commented Apr 24, 2018 at 15:12

You must log in to answer this question.

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