wsl2-boot
wsl2-boot copied to clipboard
WSL2 ip doesn't stay static
Hi,
What could be wrong when the IP address of my WSL2 doesn't stay the same between computer boots? I can see that the wsl-boot.bat is executed and it changes the IP. The subnet mask is always set to 192.168.130 (which I've configured) but the last three digits are different everytime. F.ex. 192.168.130.113, then 192.168.130.266 etc.
Did I miss something?
Background: I have Docker running inside WSL2 and there I've got multiple projects under development. My goal is to point all their domains (project1.local.dev, project2.local.dev, etc.) to the same static WSL2 IP address in Windows hosts file. Now, since the IP address changes, I need to revise the hosts file after every boot.
Strange, the IP should keep the same at reboot. What is the content of your wsl-boot.bat which you added in your Windows PATH ?
I already migrated to another solution but found the wsl-boot.bat I was using:
@echo off
REM Keep these 2 lines
set job=%USERPROFILE%\wsl-boot.job
if exist %job% (echo Cannot run this script several times at a time, exiting ... & goto :eof) else (echo. 2>%job%)
REM Boot default and other WSL distributions
PowerShell -Command %USERPROFILE%\git\github.com\wsl2-boot\windows\wsl-boot.ps1 -WslSubnetPrefix "192.168.130" %*
REM PowerShell -Command %USERPROFILE%\git\github.com\wsl2-boot\windows\wsl-boot.ps1 -WslSubnetPrefix "192.168.130" -distribution "Ubuntu-20.04.01" -ip "192.168.130.2"
REM If to keep on screen (if double click on this bat file)
REM pause
REM Keep these 2 lines
del %job%
:eof
May be you could use the parameter -ip "192.168.130.2"
too.