The quickest way to find your WSL instance's IP address is by running ip a
inside your WSL terminal or wsl.exe hostname -I
from Windows Command Prompt or PowerShell.
How to Check IP Address in WSL?
Understanding your Windows Subsystem for Linux (WSL) instance's IP address is crucial for network configurations, accessing services running within WSL from your Windows host, or connecting to your WSL environment from other devices on your network. WSL instances typically receive a dynamic IP address that can change upon reboot, making it essential to know how to locate it efficiently.
Why You Might Need Your WSL IP Address
- Accessing Services: If you're running a web server (e.g., Apache, Nginx), a database (e.g., MySQL, PostgreSQL), or any other network service inside your WSL instance, you'll need its IP to connect from your Windows host or another machine.
- SSH Connections: For secure shell (SSH) access to your WSL instance from external clients.
- Troubleshooting Network Issues: Diagnosing connectivity problems between your Windows host and the WSL environment.
Checking Your WSL IP Address from Within WSL (Linux Terminal)
When you are inside your WSL distribution, you can use standard Linux networking commands to identify your instance's IP address.
-
Using
ip a
(orip addr show
)
This is the most common and recommended command in modern Linux distributions. It displays detailed information about all network interfaces.ip a
Look for an interface like
eth0
orensX
(where X is a number). Your IP address will be listed next toinet
for that interface.
Example Output Snippet: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 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:15:5d:xx:xx:xx brd ff:ff:ff:ff:ff:ff inet 172.xx.xx.xx/20 brd 172.xx.xx.xx scope global eth0 valid_lft forever preferred_lft forever
In this example,
172.xx.xx.xx
is the WSL instance's IP address. -
Using
hostname -I
This command provides a concise list of all IP addresses associated with the host. The-I
(uppercase i) flag is used to list all network interfaces and their IP addresses.hostname -I
This command will typically output only the IP address(es) directly.
Example Output:172.xx.xx.xx
-
Using
ifconfig
Whileifconfig
is deprecated in favor ofip a
in many modern Linux distributions, it can still be used if installed (you might need to installnet-tools
first:sudo apt install net-tools
).ifconfig
Similar to
ip a
, look foreth0
orensX
and find theinet
address.
Checking Your WSL IP Address from Windows (Command Prompt or PowerShell)
You can also query your WSL instance's IP address directly from your Windows host, without needing to open the WSL terminal first.
A powerful method involves using the wsl.exe
command to execute Linux commands within your WSL instance directly from Windows. Under the hood, wsl.exe
launches the target WSL instance and executes a Linux command such as hostname --ip-addresses
(or its equivalent hostname -I
), which then prints the IP address of the WSL instance to your Windows console.
-
Using
wsl.exe hostname -I
This is the most direct way to get your WSL instance's IP address from Windows. Open Command Prompt or PowerShell and type:wsl.exe hostname -I
This will output the IP address of your default WSL distribution.
-
Targeting a Specific WSL Distribution
If you have multiple WSL distributions installed, you can specify which one you want to query:wsl.exe -d <DistroName> hostname -I
Replace
<DistroName>
with the actual name of your distribution (e.g.,Ubuntu
,Debian
). You can list your installed distributions withwsl.exe -l -v
.
Note on ipconfig
on Windows: While running ipconfig
in Windows Command Prompt/PowerShell will show a vEthernet (WSL)
adapter, the IP address listed there is the IP address of the virtual network adapter on the Windows host side that WSL uses. This is not the IP address assigned inside your WSL instance itself, but rather the gateway address for the virtual network that WSL instances are connected to.
Understanding WSL Networking
WSL 2 uses a lightweight virtual machine that runs a real Linux kernel. This VM connects to a virtual network adapter on your Windows host, often called vEthernet (WSL)
. WSL instances typically receive a dynamic IP address from a NAT (Network Address Translation) internal virtual switch managed by Windows. This means:
- The IP address can change each time you restart your Windows machine or the WSL service.
- Your WSL instance is usually behind a NAT, meaning it's not directly exposed to your physical local network unless port forwarding is configured or if using the newer "mirrored mode" networking feature in some WSL builds.
Summary of IP Address Commands
Command (Location) | Description | Example Output |
---|---|---|
ip a (inside WSL) |
Displays detailed network interface information, including IP. | inet 172.xx.xx.xx/20 |
hostname -I (inside WSL) |
Lists all IP addresses assigned to the WSL host concisely. | 172.xx.xx.xx |
wsl.exe hostname -I (from Windows) |
Executes hostname -I in the default WSL instance from Windows. |
172.xx.xx.xx |
Practical Tips for WSL Networking
- Dynamic IPs: Remember that WSL IP addresses are dynamic. If you need a stable IP for services, consider configuring static IP in WSL (more complex and not officially supported in all scenarios) or relying on Windows' dynamic DNS registration if available, or port forwarding.
- Accessing WSL Services from Windows: You can usually access services running on your WSL instance from your Windows host using the WSL IP address. For example, if a web server is running on
http://172.xx.xx.xx:80
, you can access it from your Windows browser at that address. - Accessing Windows Services from WSL: Your Windows host is typically accessible from WSL via the special DNS name
host.docker.internal
(if Docker Desktop is installed and configured with WSL) or by finding your Windows host's IP address on your primary network adapter (e.g., Wi-Fi, Ethernet). - Firewall Considerations: Ensure that your Windows Defender Firewall (or any third-party firewall) is configured to allow incoming connections to the ports your WSL services are using if you want to access them from outside your Windows machine.
For more in-depth information on WSL networking, refer to the official Microsoft documentation on WSL networking.