By default wsl2 enables wsl localhost to be accessible from windows but not vice versa. To able to access you need to use windows system IP from wsl2. Running below command gives us Network Interface (WSL) IP.
vim /etc/resolv.conf
nameserver 172.20.144.1
or
grep -m 1 nameserver /etc/resolv.conf | awk '{print $2}'
We can use this IP to access windows localhost.
Enabling ports:
Windows firewall may disable some ports by default. You need to enable ports to be able to access them from wsl2.
- Launch Windows Defender Firewall with Advanced Security
- On the left pane select Incoming Rules.
- On the right pane click on New Rule.
- For the rule type select Port. Next.
- Select TCP and Specific local ports. Insert the port, a comma-separated list of ports, or a port range. Next.
- Select Allow connection. Next.
- Check only the Public profile. Next.
- Enter a name for the rule. e.g. WSL. Done
Comments (1)