惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
D
Docker
Google DeepMind News
Google DeepMind News
Y
Y Combinator Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
U
Unit 42
博客园 - 【当耐特】
N
Netflix TechBlog - Medium
V
Visual Studio Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Recent Announcements
Recent Announcements
GbyAI
GbyAI
T
Tailwind CSS Blog
S
SegmentFault 最新的问题
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
L
LangChain Blog
A
About on SuperTechFans
M
MIT News - Artificial intelligence
B
Blog

博客园 - DHclly

Aspose.Words 合并单元格的原理、配置方式、代码示例以及常见误区 Gpustack 运行一段时间后出现 Failed to initialize NVML: Unknown Error 解决办法 wps dispimg python 解析实现参考 NVIDIA GPU 计算能力( compute capability,SM version)兼容性查询 Amazon S3 Tools:S3cmd 介绍 nginx 根路径同时代理 http ws sse 三种请求 在 X86_64(amd64) 平台上的docker支持打包跨平台的镜像(如arm64) 以图搜图功能介绍 docker 容器调试技巧 open ai sdk 的额外请求头说明 x-stainless 大模型常见的概念 创建软连接的几种方式 基于node.js 的 web server 实现 对个人的警醒 jQuery对象与DOM对象之间的转换方法 【BUG】浏览器控制台提示:net::ERR_INVALID_CHUNKED_ENCODING 200 (OK) 的解决思路 实用浏览器脚本 关于Lambda表达式(箭头函数)的get属性访问器和常规的get属性访问器的差异 转换字符串为二进制编码字符串
wsl 和win主机互相访问
DHclly · 2024-10-31 · via 博客园 - DHclly

参考文档

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)"