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