WSL
如果需要通过主机的IP地址,访问WSL操作系统的web服务,需要做如下设置:
// 以管理员身份运行 PowerShell
// 设置端口转发
netsh interface portproxy add v4tov4 listenport=8000 listenaddress=0.0.0.0 connectport=8000 connectaddress=172.20.167.165
// 配置防火墙(不确定是否必须)
New-NetFirewallRule -DisplayName "WSL 2 Port 80" -Direction Inbound -LocalPort 80 -Protocol TCP -Action Allow
如果需要ping 通主机,需要如下设置:
// 以管理员身份打开 PowerShell,运行以下命令
New-NetFirewallRule -DisplayName "WSL2 ICMP" -Direction Inbound -Protocol ICMPv4 -IcmpType 8 -Action Allow
New-NetFirewallRule -DisplayName "WSL2 ICMP" -Direction Outbound -Protocol ICMPv4 -IcmpType 8 -Action Allow
一、wsl基本操作
// wsl version
wsl.exe --version
// wsl 正在运行的系统
wsl.exe -l -v
// wsl 支持的系统
wsl.exe --list --online
// 开始安装
wsl.exe --update
wsl.exe --set-default-version 2
wsl.exe --install -d Ubuntu-22.04
// 删除
wsl --unregister Ubuntu-22.04
二、备份/恢复
// 导出
wsl --shutdown
wsl --export Ubuntu-24.04 D:\backup\ubuntu24-backup.tar
// 导入
wsl --import Ubuntu-24.04-restore D:\wsl\Ubuntu24 D:\backup\ubuntu24-backup.tar
wsl -d Ubuntu-24.04-restore
// 关机
wsl --shutdown
// 备份VHDX文件
// 新建 同版本的系统,等待初始化完成
// 将备份文件替换

