参考文档
- 使用 WSL 访问网络应用程序 | Microsoft Learn(https://learn.microsoft.com/zh-cn/windows/wsl/networking)
- 界面端口代理的 Netsh 命令 | Microsoft Learn(https://learn.microsoft.com/zh-cn/windows-server/networking/technologies/netsh/netsh-interface-portproxy)
- Windows 防火墙概述 | Microsoft Learn(https://learn.microsoft.com/zh-cn/windows/security/operating-system-security/network-security/windows-firewall/)
- 为 WSL2 网络的 Windows 防火墙添加“允许”规则 ·问题 #4585 ·微软/WSL --- Add "allow" rule to Windows firewall for WSL2 network · Issue #4585 · microsoft/WSL(https://github.com/microsoft/WSL/issues/4585)
- 使用 WSL 运行 Linux GUI 应用程序 |Microsoft 学习 --- Run Linux GUI apps with WSL | Microsoft Learn(https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps)
- cascadium/wsl-windows-toolbar-launcher: Adds linux GUI application menu to a windows toolbar(https://github.com/cascadium/wsl-windows-toolbar-launcher#firewall-rules)
- 配置 Windows 防火墙日志记录 | Microsoft Learn(https://learn.microsoft.com/zh-cn/windows/security/operating-system-security/network-security/windows-firewall/configure-logging?tabs=gpo)
windows 访问
# windows 以太网 ip 地址
(curl http://192.168.0.100:8090/api/Tool/DateTime).Content
# window 在 WSL 上的 ip 地址
(curl http://172.26.192.1:8090/api/Tool/DateTime).Content
# windows localhost
(curl http://localhost:8090/api/Tool/DateTime).Content
# windows ipv4 127.0.0.1
(curl http://127.0.0.1:8090/api/Tool/DateTime).Content
# windows ipv6 127.0.0.1
(curl http://[::1]:8090/api/Tool/DateTime).Content
# windows wsl unbuntu系统的 ip 地址
(curl http://172.26.198.196:8090/api/Tool/DateTime).Content
# wsl 中查询windows访问wsl的ip地址
hostname -I
172.26.198.196
wsl unbuntu访问
# linux ubuntu localhost
curl -s http://localhost:8090/api/Tool/DateTime | sed '$a\'
# linux ubuntu ipv4 127.0.0.1
curl -s http://127.0.0.1:8090/api/Tool/DateTime | sed '$a\'
# linux ubuntu ipv6 127.0.0.1
curl -s http://[::1]:8090/api/Tool/DateTime | sed '$a\'
# linux ubuntu eth0网卡上的 ip 地址
curl -s http://172.26.198.196:8090/api/Tool/DateTime | sed '$a\'
# host.docker.internal 地址
curl -s http://host.docker.internal:8090/api/Tool/DateTime | sed '$a\'
curl -s http://gateway.docker.internal:8090/api/Tool/DateTime | sed '$a\'
curl -s http://kubernetes.docker.internal:8090/api/Tool/DateTime | sed '$a\'
# window 在 WSL 上的 ip 地址
curl -s http://172.26.192.1:8090/api/Tool/DateTime | sed '$a\'
# windows 以太网 ip 地址(无法访问)
curl -s http://192.168.0.100:8090/api/Tool/DateTime | sed '$a\'
# wsl 中查询wsl访问windows的ip地址
ip route show | grep -i default | awk '{ print $3}'
172.26.192.1
转发 wsl 服务端口到 windows,可通过windows 外部 ip 访问
即除了127.0.0.1外的其他 ip 地址都可以访问。
hostname -I
172.26.198.196
netsh interface portproxy add v4tov4 listenport=<yourPortToForward> listenaddress=0.0.0.0 connectport=<yourPortToConnectToInWSL> connectaddress=(wsl hostname -I)
netsh interface portproxy add v4tov4 listenport=80 listenaddress=0.0.0.0 connectport=80 connectaddress=172.26.198.196
netsh interface portproxy delete v4tov4 listenport=80 listenaddress=0.0.0.0
netsh interface portproxy add v4tov4 listenport=65535 listenaddress=0.0.0.0 connectport=65535 connectaddress=172.26.198.196
netsh interface portproxy show all
windows 防火墙允许 wsl 访问 windows 服务
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
Set-NetFirewallProfile -DisabledInterfaceAliases "vEthernet (WSL)"
标签:8090,windows,win,Tool,wsl,DateTime,api,主机
From: https://www.cnblogs.com/DHclly/p/18517410