Closed pacanukeha closed 4 years ago
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
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.
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.
If I'm reading it right you right you have the following setup
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!)
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.
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)
is there any work around for docker?
is there any work around for docker?
try this, only for docker:docker-desktop-wsl2-tech-preview
Still not work in 18963😭😭😭
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?
I rebooted. VM IP is now 192.168.229.123/20 localhost works!
Still broke in 18995. Was more reliable than before, but gave up on mysql after a few hours
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"
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
It would be very useful if somebody could identify an app or workflow that can reliably trigger any remaining issues.
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?
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
.)
I can now confirm that even with a fresh reinstall of WSL2 with Ubuntu 18.04, it still has the same issue.
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? )
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.
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.
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.
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:
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.
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
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.
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?
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?
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?
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.
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...
for me the only that works accessing WSL2 server apps from windows 10 :
ip addr
inside of your WSL distro and finding it under the inet
value of the eth0
interface.
ip addr | grep eth0
.made a small server in go and tested http://172.20.203.35:3006/ works fine !
Fixed in 18970.
Other landing zone over at #4851. For else, feel enouraged to open a new issue following the template.
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.
@kangzj make sure you didn't hit this bug https://github.com/microsoft/WSL/issues/5298
@kangzj make sure you didn't hit this bug #5298
you are a life saver thanks heaps
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
ssh -i ~/.ssh/your.key -l username -L 27027:mongo.server.ip:27017 -N -f mongo.server.ip
"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
ip r
From windows
ifconfig
ping
route print -4