13

WSL2网络的最终解决方案

 1 year ago
source link: https://direct5dom.github.io/2023/01/07/WSL2%E7%BD%91%E7%BB%9C%E7%9A%84%E6%9C%80%E7%BB%88%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

WSL2网络的最终解决方案

2023-01-07WSL

参考:WSL2 网络的最终解决方案 - 知乎 (zhihu.com)

最新版的WSL2允许用户自行指定用于WSL2的网卡,不再需要脚本等方式固定WSL2地址,同时支持IPv6和外部访问。

使用方法很简单,在用户目录%USERPROFILE%下创建一个配置文件.wslconfig,内容为:

[wsl2]
networkingMode=bridged # 桥接模式
vmSwitch=my-switch # 你想使用的网卡
ipv6=true # 启用 IPv6

然后使用wsl --shutdown; wsl重启WSL2即可。

这里使用Hyper-V创建了一个名为WSLBridge的外部虚拟交换机给WSL2用,则配置文件为:

[wsl2]
networkingMode=bridged
vmSwitch=WSLBridge
ipv6=true

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK