此文档内容参考:[WSL环境搭建] 如何固定MAC地址 - 哔哩哔哩
由于软件的license是绑定MAC地址,但WSL的MAC地址每次启动都会变化。
固定方法:
方法1:这种情况设置起来比较简单。以网络名eth0为例:
sudo ifconfig eth0 down
sudo ifconfig eth0 hw ether aa:bb:cc:dd:ee:ff
sudo ifconfig eth0 up
如果觉得每次敲比较麻烦可以加到~/.bashrc ~/.cshrc等配置文件里
方法2(推荐):
这种情况需要使用 PowerShell 创建虚拟交换机。
(参考:https://learn.microsoft.com/zh-cn/virtualization/hyper-v-on-windows/quick-start/connect-to-network
创建具有外部连接的虚拟交换机。
1. 使用 Get-NetAdapter 返回连接到 Windows 系统的网络适配器列表。
Get-NetAdapter
2. 选择要用于 Hyper-V 交换机的网络适配器,并将一个实例放入名为“$net”的变量中。
$net = Get-NetAdapter -Name 'Ethernet'
3.执行以下命令来创建新的 Hyper-V 虚拟交换机。
New-VMSwitch -Name "External VM Switch" -AllowManagementOS $True -NetAdapterName $net.Name
(参考:
1.https://learn.microsoft.com/zh-cn/windows/wsl/wsl-config
2.https://github.com/microsoft/WSL/issues/5291#issuecomment-1355437876)
在windows系统中的%UserProfile%目录中找到.wslconfig文件,没有就新建一个。填入以下内容保存:
[wsl2]
networkingMode = bridged
vmSwitch = External VM Switch
macAddress = aa:bb:cc:dd:ee:ff
重启WSL
1、关闭WSL:wsl --shutdown
2、重新进入WSL,开PowerShell,输入wsl进入操作系统。