DEV Community

Cover image for Find the IP address of your WSL instance
Adrien
Adrien

Posted on

Find the IP address of your WSL instance

In Windows, I'm exclusively using WSL2 for development purposes. But sometimes, it's nice to have a GUI to do some works. For example, you are using a DB engine running in Ubuntu via WSL2 but you'd like to read your data in a nice way. When you find out how it works, it's simple.

Well, I did the digging for you and I'll show you how it works (whatever the WSL version you're using).

Check your WSL instances

For various reasons, you might have more than one WSL instances on your machine. For example, using docker will set up some depending on your uses. We need to find if this is our case. If it is, then we need to check which one is the default one and change it to the one we are interested in.

Make sure to run these commands in a PowerShell terminal.

List all the instances:

    PS C:\Users\adrien> wsl -l -v
      NAME                   STATE           VERSION
    * docker-desktop-data    Stopped         2
      Ubuntu                 Running         2
      docker-desktop         Stopped         2
Enter fullscreen mode Exit fullscreen mode

As we can see, I have 3 instances of WSL. Since Docker is not running at the time, it shows as Stopped. The * shows the default instance which is not the one we are interested in. We want Ubuntu.

If this is not your case, meaning you only have one, you can skip the rest and go to "Find the IP address".

Change the default instance:

    PS C:\Users\adrien> wsl --set-default "Ubuntu"
    PS C:\Users\Plouf> wsl -l -v
      NAME                   STATE           VERSION
    * Ubuntu                 Running         2
      docker-desktop         Stopped         2
      docker-desktop-data    Stopped         2
Enter fullscreen mode Exit fullscreen mode

Smooth.

Find the IP address

Now, that's gonna be simple. Run this command:

    PS C:\Users\adrien> wsl hostname -I
    172.24.72.193
Enter fullscreen mode Exit fullscreen mode

EZ.

Discussion (2)

Collapse
spyshow profile image
jihad khorfan

if it's returning 3 ip addresses , how can i select the first one

Collapse
agiboire profile image
Adrien Author

You mean wsl hostname -I returns you more than one addresses?