Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot connect to 127.0.0.1, localhost, or linux IP address #4353

Closed
pacanukeha opened this issue Jul 29, 2019 · 37 comments
Closed

Cannot connect to 127.0.0.1, localhost, or linux IP address #4353

pacanukeha opened this issue Jul 29, 2019 · 37 comments
Assignees

Comments

@pacanukeha
Copy link

pacanukeha commented Jul 29, 2019

This was working for me prior to 18945

Please fill out the below information:

  • Your Windows build number: (Type ver at a Windows Command Prompt)
    10.0.18945.1001]

  • What you're doing and what's happening: (Copy&paste the full set of specific command-line steps necessary to reproduce the behavior, and their output. Include screen shots if that helps demonstrate the problem.)
    Trying to access network ports in my WSL2 (port forwarded via ssh over vpn) via localhost or 127.0.0.1 or eth0 IP address and getting connection refusal

    • for example

ssh -i ~/.ssh/your.key -l username -L 27027:mongo.server.ip:27017 -N -f mongo.server.ip

  • What's wrong / what should be happening instead:
    I should be able to connect from the windows host (eg in browser, or sql editor) to linux ports eg 127.0.0.1:8080 or localhost:27017
    • when I run NoSQLBooster for MongoDB in windows I get the error:
      "message" : "failed to connect to server [localhost:27027] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27027]

Connecting from Linux out (eg to initialize ssh port forwarding or lynx localhost:8080) works.
I can ping the linux IP but not connect to that either

Network Info from wsl:
ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 5e:ac:68:50:7d:20 brd ff:ff:ff:ff:ff:ff
3: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 9a:99:a8:e8:66:84 brd ff:ff:ff:ff:ff:ff
4: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
5: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:d1:ac:d2 brd ff:ff:ff:ff:ff:ff
    inet 172.27.47.10/16 brd 172.27.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::215:5dff:fed1:acd2/64 scope link
       valid_lft forever preferred_lft forever

ip r

default via 172.27.32.1 dev eth0
172.27.0.0/16 dev eth0 proto kernel scope link src 172.27.47.10

From windows

ifconfig

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::d121:7256:fceb:d6f0%42
   IPv4 Address. . . . . . . . . . . : 172.27.32.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

ping

ping 172.27.47.10

Pinging 172.27.47.10 with 32 bytes of data:
Reply from 172.27.47.10: bytes=32 time<1ms TTL=64
Reply from 172.27.47.10: bytes=32 time<1ms TTL=64
Reply from 172.27.47.10: bytes=32 time<1ms TTL=64

route print -4

 route print -4
===========================================================================
Interface List
 14...28 16 a8 04 45 1a ......Surface Ethernet Adapter #2
 17...00 15 5d f8 6b 1e ......Hyper-V Virtual Ethernet Adapter
 27...00 15 5d 84 73 11 ......Hyper-V Virtual Ethernet Adapter #2
 13...c6 9d ed aa cc 3c ......Microsoft Wi-Fi Direct Virtual Adapter #3
 18...c6 9d ed aa c9 3c ......Microsoft Wi-Fi Direct Virtual Adapter #4
 21...00 ff 8e 6b 18 73 ......TAP-Windows Adapter V9
 30...c4 9d ed aa cd 3d ......Marvell AVASTAR Wireless-AC Network Controller
 28...c4 9d ed aa cd 3e ......Bluetooth Device (Personal Area Network)
  1...........................Software Loopback Interface 1
 42...00 15 5d 72 59 7a ......Hyper-V Virtual Ethernet Adapter #3
===========================================================================

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0      192.168.1.1    192.168.1.128     35
         10.0.0.0      255.255.0.0        10.8.0.21        10.8.0.22    291
        10.0.75.0    255.255.255.0         On-link         10.0.75.1    271
        10.0.75.1  255.255.255.255         On-link         10.0.75.1    271
      10.0.75.255  255.255.255.255         On-link         10.0.75.1    271
         10.8.0.1  255.255.255.255        10.8.0.21        10.8.0.22    291
        10.8.0.20  255.255.255.252         On-link         10.8.0.22    291
        10.8.0.22  255.255.255.255         On-link         10.8.0.22    291
        10.8.0.23  255.255.255.255         On-link         10.8.0.22    291
        10.25.0.0      255.255.0.0        10.8.0.21        10.8.0.22    291
        10.64.0.0      255.255.0.0        10.8.0.21        10.8.0.22    291
       10.110.0.0      255.255.0.0        10.8.0.21        10.8.0.22    291
       10.233.0.0      255.255.0.0        10.8.0.21        10.8.0.22    291
        127.0.0.0        255.0.0.0         On-link         127.0.0.1    331
        127.0.0.1  255.255.255.255         On-link         127.0.0.1    331
  127.255.255.255  255.255.255.255         On-link         127.0.0.1    331
       172.18.0.0      255.255.0.0        10.8.0.21        10.8.0.22    291
     172.23.208.0    255.255.240.0         On-link      172.23.208.1    271
     172.23.208.1  255.255.255.255         On-link      172.23.208.1    271
   172.23.223.255  255.255.255.255         On-link      172.23.208.1    271
       172.24.0.0      255.255.0.0        10.8.0.21        10.8.0.22    291
      172.27.32.0    255.255.240.0         On-link       172.27.32.1   5256
      172.27.32.1  255.255.255.255         On-link       172.27.32.1   5256
    172.27.47.255  255.255.255.255         On-link       172.27.32.1   5256
       172.31.0.0      255.255.0.0        10.8.0.21        10.8.0.22    291
       172.42.0.0      255.255.0.0        10.8.0.21        10.8.0.22    291
       172.64.0.0      255.255.0.0        10.8.0.21        10.8.0.22    291
      192.168.1.0    255.255.255.0         On-link     192.168.1.128    291
    192.168.1.128  255.255.255.255         On-link     192.168.1.128    291
    192.168.1.255  255.255.255.255         On-link     192.168.1.128    291
        224.0.0.0        240.0.0.0         On-link         127.0.0.1    331
        224.0.0.0        240.0.0.0         On-link         10.8.0.22    291
        224.0.0.0        240.0.0.0         On-link         10.0.75.1    271
        224.0.0.0        240.0.0.0         On-link     192.168.1.128    291
        224.0.0.0        240.0.0.0         On-link      172.23.208.1    271
        224.0.0.0        240.0.0.0         On-link       172.27.32.1   5256
  255.255.255.255  255.255.255.255         On-link         127.0.0.1    331
  255.255.255.255  255.255.255.255         On-link         10.8.0.22    291
  255.255.255.255  255.255.255.255         On-link         10.0.75.1    271
  255.255.255.255  255.255.255.255         On-link     192.168.1.128    291
  255.255.255.255  255.255.255.255         On-link      172.23.208.1    271
  255.255.255.255  255.255.255.255         On-link       172.27.32.1   5256
===========================================================================
Persistent Routes:
  None
@owennewo
Copy link

You've not copied and pasted a full set of commands to reproduce. Can you give a minimal example?

One odd thing with the new localhost win10->wsl2 implementation is that the linux process needs to bind to 0.0.0.0 in order for win10 to access on localhost. I suspect this will be fixed before long.

example:
ng serve
This starts an angular/npm app but doesn't specify which interface to bind to. It cannot be accessed from win10
ng server --host 0.0.0.0
This binds to all interfaces and win10 can access on http://localhost:4200

@enachesilviu
Copy link

Big fan of accessing development stuff via localhost without having to configure security and access. localhost on WSL2 is great news.

Now, if you have to set 0.0.0.0 on every piece of software you don't really benefit of the localhost simple access feature. Tried mysql and postgresql, they need to bind to 0.0.0.0 to accept connections from outside. RabbitMQ admin plugin web interface works fine via localhost (guest account by default works only via localhost).

I hope the localhost access would expand to most services without additional setup (like bind 0.0.0.0), if possible. localhost accesss made WSL so much easier to use compared to the traditional development vm.

@pacanukeha
Copy link
Author

You've not copied and pasted a full set of commands to reproduce. Can you give a minimal example?

Good point. I've added a specific example of ssh port forwarding that normally works - it is connecting to a remote mongodb instance but anything that you have in your network should behave similarly.

@owennewo
Copy link

If I'm reading it right you right you have the following setup

  • a mongo db not running in win10 or wsl2
  • a wsl2 which you want to use to port forward the mongo db port on remote mongo server
  • win10 mongo client that you want to attached to forward port

interesting pattern!

Have you tried:
ssh -i ~/.ssh/your.key -l username -L 0.0.0.0:27027:mongo.server.ip:27017 -N -f mongo.server.ip

and setting GatewayPorts yes in /etc/ssh/sshd_config

My inspiration came from this:
https://stackoverflow.com/questions/23781488/how-to-make-ssh-remote-port-forward-that-listens-0-0-0-0

As I mentioned in an earlier post you need for ports to bind to 0.0.0.0 with wsl2 at the moment - I'm hoping the suggestion above will cause the ssh port binding to bind to 0.0.0.0 and the GatewayPorts would expose the port to Win10 (and potentially to other PCs on your network!)

@benhillis
Copy link
Member

benhillis commented Jul 31, 2019

Thanks for posting. I have identified an issue with the localhost feature and we are working on a fix. Binding to either localhost or 0.0.0.0 should work, but it seems only the later is working currently.

@benhillis benhillis self-assigned this Jul 31, 2019
@pacanukeha
Copy link
Author

interesting pattern!

Yeah - I have a number of mongo servers running elsewhere that don't have the ports exposed I normally connect to from wsl using the mongo cli but I have some Windows GUI tools that make some things easier so necessitating the song-and-dance

Have you tried:
ssh -i ~/.ssh/your.key -l username -L 0.0.0.0:27027:mongo.server.ip:27017 -N -f mongo.server.ip

This works.! Brilliant, thank you.

and setting GatewayPorts yes in /etc/ssh/sshd_config

This does not appear to be needed - I'm guessing because I'm using ssh and not sshd to provide the forwarding.

Thanks for the help and hopefully Ben will have a fix Soon (tm)

@Gorthog
Copy link

Gorthog commented Aug 5, 2019

is there any work around for docker?

@sxd111
Copy link

sxd111 commented Aug 7, 2019

is there any work around for docker?

try this, only for docker:docker-desktop-wsl2-tech-preview

@Lips7
Copy link

Lips7 commented Aug 19, 2019

Still not work in 18963😭😭😭

@benhillis
Copy link
Member

Fixed in 18970.

@sirber
Copy link

sirber commented Oct 3, 2019

I'm on 18999, and I cannot use localhost. Trying to get to a mysql server.

172.29.181.182 works, but not 127.0.0.1 or localhost.
in my.cnf , I commented bind-address.

do I have to do something special for localhost to work?

@sirber
Copy link

sirber commented Oct 3, 2019

I rebooted. VM IP is now 192.168.229.123/20
localhost works!

@sitepodmatt
Copy link

Still broke in 18995. Was more reliable than before, but gave up on mysql after a few hours

@sirber
Copy link

sirber commented Oct 7, 2019

Still broke in 18995. Was more reliable than before, but gave up on mysql after a few hours

I'm on 18995.1, it works using "localhost"

@sitepodmatt
Copy link

Still broke in 18995. Was more reliable than before, but gave up on mysql after a few hours

I'm on 18995.1, it works using "localhost"

Yes, it works "most of the time", if you boot up you can access anything run on WSL2 via localhost:port, but alas after a few hours it gets flakey again, not 100% for example already established long running connection such as persistent DB connection remain but struggles establishing new connections. It's much more reliable than earlier "localhost" featured versions

@benhillis
Copy link
Member

It would be very useful if somebody could identify an app or workflow that can reliably trigger any remaining issues.

@sitepodmatt
Copy link

sitepodmatt commented Oct 10, 2019

Just another observation, after last night hibernation I can't access /mnt/c/ inside WSL2 or localhost:port from windows, the WSL2 kernel has been up evident by uptime. wsl --shutdown and opening terminal again worked. Perhaps suspension/hibernation has an impact?

@enzanki-ars
Copy link

enzanki-ars commented Dec 13, 2019

I just switched to the insider previews, and switched my WSL distro to v2, and while it worked once, rebooting my system for something else caused this problem to begin.

$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 6a:05:33:e7:f5:ed brd ff:ff:ff:ff:ff:ff
3: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 06:79:51:51:a7:30 brd ff:ff:ff:ff:ff:ff
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:8f:2e:0a brd ff:ff:ff:ff:ff:ff
    inet 172.24.170.19/20 brd 172.24.175.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::215:5dff:fe8f:2e0a/64 scope link
       valid_lft forever preferred_lft forever
5: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0

$ ip route
default via 172.24.160.1 dev eth0
172.24.160.0/20 dev eth0 proto kernel scope link src 172.24.170.19

I am able to ping out of ubuntu, but starting a simple python3 -m http.server 5000 is enough to trigger the issue for me. I can not connect to servers hosted in WSL via localhost or 127.0.0.1, but I am via the rotating IP. I am going to try wiping my WSL install and starting it from scratch is enough to fix the issue.

Edit: Forgot Windows build version:

> ver
Microsoft Windows [Version 10.0.19041.1]
> wsl --list --verbose
  NAME            STATE           VERSION
* Ubuntu-18.04    Running         2

Also was running Ubuntu 19.04 (updated 18.04 to 19.04 by changing lts to normal in /etc/update-manager/release-upgrades.)

@enzanki-ars
Copy link

I can now confirm that even with a fresh reinstall of WSL2 with Ubuntu 18.04, it still has the same issue.

@sitepodmatt
Copy link

sitepodmatt commented Dec 13, 2019

At least now I can wsl --shutdown and reopen a terminal and get back localhost connectivity (and /mnt/c access)

But it (localhost and mnt/c - I guess the whole interop services) never works on resume from standby/sleep (i.e. close laptop in evening and open in morning) - wondering is the standby/resume issue is considered somewhere else or perhaps laptop usage isn't considered at the moment

@benhillis is there an issue for sleep resume? cant seem to find it (perhaps using wrong terminology - standby/suspend/resume/hibernation/sleep? )

@enzanki-ars
Copy link

I tried the wsl --shutdown trick, but even that was not enough to fix the issue. I am continuing to see if I can find something that can point to what's going on better.

@enzanki-ars
Copy link

It does look to be something sleep related. After a fresh reboot yesterday, I was able to access items via localhost, but today, I have been unable to after placing my system into sleep mode.

@haljac
Copy link

haljac commented Dec 18, 2019

I'm using Laravel.

Running php artisan serve --host 0.0.0.0 with default port of 8000. The app is not accessible from chrome at 127.0.0.1:8000

Same with Spring/Tomcat. My issues began when I installed Docker Desktop Edge for Windows with wsl2 integration.

Edit:
@sitepodmatt is correct. I can run wsl --shutdown and reopen the terminal. This gives me the ability to hit apps running in wsl2 on localhost from windows. I was about 5 minutes from wiping the machine and starting fresh.

@sitepodmatt
Copy link

@douglascorrea
Copy link

I have a issue that looks like this but was better described on #4347 which was closed as duplicated by this.

Anyways, here is the description:

  • Windows build 19041.1
  • WSL 2 running Ubuntu 18.04.3
  • Apache2

Apache2 default site is working great from Windows with localhost.

When I create a new Virtual Host on Apache2, with a different tld like test.tld, it works from inside WSL2, but not from the windows machine.

I put test.tld on Ubuntu hosts file and also on Windows hosts file.

I'm describing it here again because @craigloewen-msft closed #4347 in favor of this issue, but I'm not seeing any description that looks like my use case here, so I'm documenting it.

@douglascorrea
Copy link

I realized that, if I put:

::1             test.tld localhost

instead of

::1             localhost test.tld

in the Windows hosts file, it works, I don't know if this is a normal behaviour for IPv6

@webash
Copy link

webash commented Jan 3, 2020

I can reliably reproduce this with ssh -L bindings, like the OP. Start up ssh client with -L 1234:remote:1234, use that port forward a little in a browser, then use ~C SSH escape command to add another port forward using -L 5678:localhost:5678 and it more often than not won't be available on localhost:5678. This can be confirmed using netstat -a -b -n, as the only result for wslhost.exe is the 1234 port from the original binding. Once it breaks like this, I also have to use wsl --shutdown to get localhost port forwarding working again in SSH client. Non-localhost connectivity (eg, binding to 0.0.0.0 using -L 0.0.0.0:5678:remote:5678 and connecting to the 172.x.x.x IP) works without a hitch.

@didibaba
Copy link

I'm using build 10.0.19041.21, also have the same problem. In my memory, I have successfully connected to 127.0.0.1:8080 only once using python -m SimpleHTTPServer 8080. Form then on, I cannot connect to the localhost any more.

Any progress made so far?

@lackovic
Copy link

It would be very useful if somebody could identify an app or workflow that can reliably trigger any remaining issues.

I have postgres:10 running in a Docker container on ports 0.0.0.0:5432->5432/tcp on Windows 10.0.19551.1005: I am able to access it from WSL 1 with no issue, but on WSL 2 I get the following error:

PG::ConnectionBad - could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?

@odbayar
Copy link

odbayar commented Mar 19, 2020

It would be very useful if somebody could identify an app or workflow that can reliably trigger any remaining issues.

I have PostgreSql 8.4 installed on an WSL distro (Ubuntu 18.04). If I kill a locked JDBC (running an alter table query on a read locked table using DataGrip) connection to the database server, all listening sockets on wslhost.exe disappears. Maybe wslhost.exe crashes?

@gerryhd
Copy link

gerryhd commented Mar 24, 2020

For what it's worth, I also use postgresql on 9.5 and on a Rails setup.

I can't imagine such a critical issue going unfixed for so much time, are people just not using WSL2 for developing anything on the web? I was hoping to but I guess with this issue the hype just comes crashing to the ground when a basic function can't work correctly.

@luxzg
Copy link

luxzg commented Mar 24, 2020

I believe WSL2 in current shape is useless for anything that involves networking. And in today's world, that's pretty much everything. If you want to develop web apps, having Apache on WSL2 is useless, as there are bunch of hoops to jump through, and even those aren't guaranteed to work. You can't reliably access that web server from outside, nor occasionally from local PC. If you want to use that WSL2 for management & monitoring tools to manage other (real) Linux servers using remote management/monitoring, again you have to rely on buggy and badly thought through network implementation. I'm not even talking about bunch of other scenarios people do or try to do with WSL2. I'm talking about 99% of what WSL was made to solve - give developers and admins (be it net/sys/db) access to tools from Linux ecosystem. From my point of view, it fails for most admin and dev uses with current networking stack. We're all way better off creating our own lightweight VMs on Hyper-V, that's just 4GB disk space and 10min of time. Slightly longer than installing WSL distro through Store, but you have 100% compatibility, 100% access to networking, and it is a reliable solution.

We aren't meant to be browsing web from WSL2, and that's just about it in a list of networking features that work on WSL2.

I beg excuse of all developers that are spending countless hours on this project, indeed a wonderful project with huge potential. But I hope you people still get the point. Perhaps you should just ask project managers to rethink the strategy...

@emranhamdan
Copy link

for me the only that works accessing WSL2 server apps from windows 10 :

  • Obtain the IP address of your distro by running the command ip addr inside of your WSL distro and finding it under the inet value of the eth0 interface.
    • You can find this more easily by filtering the output of the command using grep like so: ip addr | grep eth0.
  • Connect to your Linux server using the IP you found above.
    from release notes of WSL2 WSL-1870.zip founded here .

made a small server in go and tested http://172.20.203.35:3006/
works fine !

@therealkenc
Copy link
Collaborator

Fixed in 18970.

Other landing zone over at #4851. For else, feel enouraged to open a new issue following the template.

@kangzj
Copy link

kangzj commented Jun 11, 2020

Fixed in 18970.

Other landing zone over at #4851. For else, feel enouraged to open a new issue following the template.

I don't think so. Still experiencing it on 19577.

@onomatopellan
Copy link

@kangzj make sure you didn't hit this bug #5298

@kangzj
Copy link

kangzj commented Jun 14, 2020

@kangzj make sure you didn't hit this bug #5298

you are a life saver thanks heaps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests