赞
踩
工作需要,安装了一个 wsl Oracle Linux 8.9,也想给它一个固定的 ip。
删除 PSScheduledJob
,
notepad $PSHOME\powershell.config.json
--- Remove
PSScheduledJob in WindowsPowerShellCompatibilityModuleDenyList
---
创建 fix_wsl_ip.ps1
脚本文件,
netsh interface ip add address "vEthernet (WSLCore)" 192.168.99.1 255.255.255.0
创建 trigger,
$trigger = New-ScheduledTaskTrigger -AtStartup -RandomDelay 00:00:15
Register-ScheduledTask -TaskName "FixWSLIP" -Trigger $trigger -Action (New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-File C:\Users\thinkpad\fix_wsl_ip.ps1")
安装 hostname
,
dnf install hostname -y
创建了 /etc/wsl.conf
,
vi /etc/wsl.conf
--- add
[boot]
systemd = true
[network]
generateHosts = false
generateResolvConf = false
---
修改 /etc/resolve.conf
,
vi /etc/resolv.conf
--- modify
# nameserver 172.25.192.1
nameserver 192.168.31.2
---
修改 /etc/hosts
,
192.168.99.2 thinkpad-pc
127.0.1.1 thinkpad-pc.
修改 /etc/rc.local
,
vi /etc/rc.local
--- add
sudo ip addr add 192.168.99.2/24 broadcast 192.168.99.255 dev eth0 label eth0:1
---
sudo chmod +x /etc/rc.local
refer: https://superuser.com/questions/1191249/unable-to-resolve-host-name-in-wsl
refer: https://superuser.com/questions/1582234/make-ip-address-of-wsl2-static
完结!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。