当前位置:   article > 正文

wsl-oraclelinux 固定ip

wsl-oraclelinux 固定ip

0. 引言

工作需要,安装了一个 wsl Oracle Linux 8.9,也想给它一个固定的 ip。

1. Windows 创建启动脚本

删除 PSScheduledJob

notepad $PSHOME\powershell.config.json

--- Remove
PSScheduledJob in WindowsPowerShellCompatibilityModuleDenyList
---
  • 1
  • 2
  • 3
  • 4
  • 5

创建 fix_wsl_ip.ps1 脚本文件,

netsh interface ip add address "vEthernet (WSLCore)" 192.168.99.1 255.255.255.0
  • 1

创建 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")
  • 1
  • 2

2. 配置 wsl Oracle Linux

安装 hostname

dnf install hostname -y
  • 1

创建了 /etc/wsl.conf

vi /etc/wsl.conf

--- add
[boot]
systemd = true
[network]
generateHosts = false
generateResolvConf = false
---
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

修改 /etc/resolve.conf

vi /etc/resolv.conf

--- modify
# nameserver 172.25.192.1
nameserver 192.168.31.2
---
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

修改 /etc/hosts

192.168.99.2    thinkpad-pc
127.0.1.1       thinkpad-pc.
  • 1
  • 2

修改 /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
---
  • 1
  • 2
  • 3
  • 4
  • 5
sudo chmod +x /etc/rc.local
  • 1

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

完结!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/260055?site
推荐阅读
相关标签
  

闽ICP备14008679号