Environment Introduction#
WSL2: Ubuntu 22.04
Windows Host: Win11 Professional Edition
Windows Host IP Address#
In WSL2, use the following command:
cat /etc/resolv.conf
Accessing Windows Host from WSL2#
By default, the Windows host firewall will block WSL2 applications from accessing the Windows network.
Solution: Add a firewall rule to allow WSL2 to access Windows.
Run PowerShell as an administrator and enter the following command:
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
Note: You can use the ipconfig command to check the InterfaceAlias
Test if the firewall rule is successfully added.
Ping the Windows host from WSL2, if you can ping successfully, it means the rule was added successfully.