随想

WSL

如果需要通过主机的IP地址,访问WSL操作系统的web服务,需要做如下设置:

// 以管理员身份运行 PowerShell
// 设置端口转发
netsh interface portproxy add v4tov4 listenport=8000 listenaddress=0.0.0.0 connectport=8000 connectaddress=172.20.167.165

// 配置防火墙(不确定是否必须)
New-NetFirewallRule -DisplayName "WSL 2 Port 80" -Direction Inbound -LocalPort 80 -Protocol TCP -Action Allow

如果需要ping 通主机,需要如下设置:

// 以管理员身份打开 PowerShell,运行以下命令
New-NetFirewallRule -DisplayName "WSL2 ICMP" -Direction Inbound -Protocol ICMPv4 -IcmpType 8 -Action Allow
New-NetFirewallRule -DisplayName "WSL2 ICMP" -Direction Outbound -Protocol ICMPv4 -IcmpType 8 -Action Allow

Leave a Reply

Your email address will not be published. Required fields are marked *