参考:
windows11 搭建 WSL2 运行环境(2024)_python_以北丶-GitCode 开源社区
镜像网络模式配置WSL2——完美解决wsl2无法ping宿主机,也无法ping外网的问题_wsl2 镜像网络-CSDN博客
1. 在C:\Users\<你的用户名>
下,新建.wslconfig
文件
2. 添加如下配置(具体配置参考官方文档):
# Settings apply across all Linux distros running on WSL 2
[wsl2]
# Limits VM memory to use no more than 4 GB, this can be set as whole numbers using GB or MB
memory=8GB
# Sets the VM to use two virtual processors
processors=8
[experimental]
autoMemoryReclaim=gradual # 开启自动回收内存,可在 gradual, dropcache, disabled 之间选择
networkingMode=mirrored # 开启镜像网络
dnsTunneling=true # 开启 DNS Tunneling
firewall=true # 开启 Windows 防火墙
autoProxy=true # 开启自动同步代理
sparseVhd=true # 开启自动释放 WSL2 虚拟硬盘空间
3. 重启 WSL 实例
在 Windows PowerShell 中输入
wsl --shutdown