wsl2 和 win主机的网络映射关系

介绍NAT,镜像和桥接三种网络配置。

使用 WSL 访问网络应用程序 | Microsoft Learn

默认网络模式是NAT

NAT模式

Windows :arrow_right: Linux

使用localhost 从Windows应用直接访问Linux应用。

Linux :arrow_right: Windows

使用主机IP从Linux访问Windows网络应用。

镜像模式

Linux 与 Windows 共享网络堆栈 ,使得 WSL2 更像物理主机一样出现在网络上。

networkingMode=mirrored

桥接模式

桥接到主机的网络接口。拥有独立IP,能够被局域网发现。

networkingMode=bridged

配置

附上我的镜像配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[wsl2]
kernel=C:\\opt\\kernel_
memory=8GB
processors=8
[experimental]
autoMemoryReclaim=gradual
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true
sparseVhd=true
hostAddressLoopback=true
[network]
generateResolvConf = false