I have windows 11 with wsl2(ubuntu) installed on it.

I've setup a gdb listener server on my windows localhost and want to access it from wsl2. but it seems my windows machine and wsl vm are using different network adapters.


Windows IP Configuration

Ethernet adapter vEthernet (Default Switch):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::1114:bb:d0ad:93f8%18
   IPv4 Address. . . . . . . . . . . :
   Subnet Mask . . . . . . . . . . . :
   Default Gateway . . . . . . . . . :

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::897:849a:5fed:1c6e%52
   IPv4 Address. . . . . . . . . . . :
   Subnet Mask . . . . . . . . . . . :
   Default Gateway . . . . . . . . . :

my server is actively listening on 8888 port and is accessible on the windows but not on ubuntu.

I've opened the 8888 port both from the windows firewall and ubuntu firewall

what is the solution?

  • The accepted answer is ubiquitous on the internet and probably works in most cases. However, it did not for me. I found a workaround for my own problem of accessing a server on the windows host from WSL2: I setup the server running on WSL2 instead, mounting the relevant host directories into the WSL, and became happy bidirectionally. Note, that it is no problem to access the WSL2 from the Windows host. Only WSL2 to host is difficult. This is no general answer but a workaround for some of those whose problem is not solved by the accepted answer. Aug 11, 2022 at 11:57

4 Answers 4


localhost doesn't work because WSL2 is running with a virtual network (vNIC) created by the Windows Virtual Machine Platform (a subset of Hyper-V). Inside WSL2, localhost is the address of the vNIC.

WSL2 does set up a virtual router on the Windows host to allow connectivity to both the outside world as well as the Windows host. You can see this via:

ip route

The "default via" address is the address to use for the Windows host.

You could parse it from the above, or from /etc/resolv.conf, but WSL also sets up a convenience mDNS, the .local domain, using the Windows "computer name", which is also used as the hostname of the WSL instance.

Accessing it is by concatenating $(hostname) with .local.


ping "$(hostname).local"

Or, if ICMP is blocked (seems so on new Windows 11 installs), use netcat. It's available by default in the WSL Ubuntu installation, but may need to be installed in other distributions like openSUSE:

nc -zv "$(hostname).local" <portnumber>

Reference: Access a localhost running in Windows from inside WSL2? answer by NotTheDr01ds.

  • 13
    That looks suspiciously like my Stack Overflow answer of a few days ago :-). Please remember to add a reference/attribution when copying/pasting from another answer. Oct 4, 2021 at 18:20
  • @NotTheDr01ds: Sorry, I forgot to add the reference. Feel free to add here your answer; let me know and I'll delete mine.
    – harrymc
    Oct 4, 2021 at 18:26
  • No worries - I just try to link people back to the original source so that they can upvote there as well. I don't ask for upvotes for the original source, but I hope folks will do so if they find it useful. Oct 4, 2021 at 18:27
  • Also, funny thing - You accidentally linked back to this answer (yours, here) instead of the SO one. I'll edit and fix. Oct 4, 2021 at 18:28
  • 1
    But yeah, as an aside, I don't usually ask for upvotes, but if you found my SO answer useful enough to copy/paste from, you could have at least thrown an upvote on it while you were at it! :-) Oct 4, 2021 at 18:29

"Localhost" always refers to system itself. When you're running a host OS and a virtualized OS, you're running 2 systems, both of which refer to themselves as "localhost". So you can never access "localhost" of another system, you need to use its external IP.

In your case if you want to access from the Ubuntu system a service that's running on your host Windows listening to port 8888, you have to access Only the system that's actually offering the service must listen to the port and allow new incoming connections through that port.

Because the Ubuntu is a separate system, you won't have anything there listening to port 8888 unless you install a service that listens to that port.

  • 3
    But won't that address change every time you restart the computer? So if you bookmark a page under that address the bookmark will be broken each time the IP changes. How do you get around that?
    – luisdev
    Feb 16, 2022 at 6:03

Further elaborating on the answer from @harrymc and @NotTheDr01ds:

Generally, you can contact Windows services from wsl2 command line using "$(hostname).local" as the host name. If such connections seem to be blocked, you can try the following:

  • Check whether Windows Firewall blocks the traffic. One easy check would be to turn it off for a few seconds and repeat the test. If that works, add appropriate Firewall rules.

  • Issue nslookup "$(hostname).local". This will give you a bunch of IPs. By default, the first one will be used, but that might not be the one which works. Try the other ones as well. If you find one that works, you can tailor a short script for your own system which will always return the correct IP.

  • 1
    "$(hostname).local" cannot be resolved. nslookup etc. does not give me any IP for this. (WSL2 on Win11)
    – Tino
    Jun 25, 2023 at 18:28
  • @Tino hostname is a standard Linux command, and $(...) is a standard way to include the result of an external command into a command line. You either use a shell which needs a different syntax, or the hostname command is not installed. Both should be easy to fix.
    – malamut
    Jul 2, 2023 at 8:50

Other answers have solved this by using "$(hostname).local".

However, for my case at least (Ubuntu 23.10 on WSL 2), running the command ping "$(hostname).local" errored:

ping: <myhostname.local: Name or service not known

I managed to fix this by installing libnss-mdns, letting the ping command run normally. (Run sudo apt install libnss-mdns to install on Ubuntu)

Source for the fix: https://github.com/microsoft/WSL/issues/10077#issuecomment-1736181588

You must log in to answer this question.

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