6

Windows configs:

  1. Running a sample web server with port 5000 opened (see picture 1)
  2. Windows firewall fully closed

WSL2:

  1. Can successfully access the Internet and ping windows with host IP or $(hostname).local, but unable to curl http://172.18.16.1:5000
sandowner@ENIGMATIC-MACHINE:~$ hostip=$(ip route | grep default | awk '{print $3}')
sandowner@ENIGMATIC-MACHINE:~$ echo $hostip
172.18.16.1
sandowner@ENIGMATIC-MACHINE:~$ ping 172.18.16.1
PING 172.18.16.1 (172.18.16.1) 56(84) bytes of data.
64 bytes from 172.18.16.1: icmp_seq=1 ttl=128 time=0.514 ms
64 bytes from 172.18.16.1: icmp_seq=2 ttl=128 time=0.690 ms
^C
sandowner@ENIGMATIC-MACHINE:~$ ping $(hostname).local
PING ENIGMATIC-MACHINE (172.18.16.1) 56(84) bytes of data.
64 bytes from ENIGMATIC-MACHINE (172.18.16.1): icmp_seq=1 ttl=128 time=0.355 ms
64 bytes from ENIGMATIC-MACHINE (172.18.16.1): icmp_seq=2 ttl=128 time=0.729 ms
^C
sandowner@ENIGMATIC-MACHINE:~$ curl http://172.18.16.1:5000
^C (will timeout)
  1. Host's 5000 port also cannot be accessed from a WSL2 browser and it will end with ERR_CONNECTION_TIMED_OUT (see picture 2)

picture 1

picture 2

Any help will be appreciated! Thanks!

nonemaw
  • 163
  • 1
  • 6

1 Answers1

3

When you want to connect from WSL 2 to the host, there are no special mechanisms in place. WSL 2 runs in a VM and is a remote host as far as the Windows networking stack is concerned. That means:

  • You cannot reach applications bound to localhost, any IP on 127.0.0.0/8 or ::1
  • The firewall must allow the inbound connection

The WSL 2 virtual network unfortunately has totally unpredictable dynamic addresses, so listening only there means you’ll have to update the network service configuration all the time. It is easier to bind to 0.0.0.0 or :: (“all interfaces”) instead. This means everyone will be able to connect, so make sure you’re aware of the consequences if you’re on an untrusted network.

user219095
  • 65,551