Narendra ・ Dec 18th, 2020 Views

Access windows localhost from wsl2

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.

  1. Launch Windows Defender Firewall with Advanced Security
  2. On the left pane select Incoming Rules.
  3. On the right pane click on New Rule.
  4. For the rule type select Port. Next.
  5. Select TCP and Specific local ports. Insert the port, a comma-separated list of ports, or a port range. Next.
  6. Select Allow connection. Next.
  7. Check only the Public profile. Next.
  8. Enter a name for the rule. e.g. WSL. Done

Comments (1)