The method for configuring a static IP address in WSL2 #40334
Replies: 1 comment
|
WSL2 normally uses NAT, so the distro's IP address can change when WSL restarts. For Windows 11 22H2+, you can use mirrored networking instead of trying to manually assign a static IP: %USERPROFILE%.wslconfig[wsl2] Then run wsl --shutdown from PowerShell and start WSL again. In mirrored mode, WSL shares the Windows network stack/IP, which can make host/WSL connectivity much simpler. If you specifically need a fixed address for a service, another option is to keep WSL in NAT mode and expose the service through Windows using port forwarding rather than relying on the WSL VM's internal IP. Microsoft documents this approach with netsh interface portproxy. The best approach depends on whether the goal is WSL-to-Windows, Windows-to-WSL, or access from another machine on the LAN. |
Uh oh!
There was an error while loading. Please reload this page.
I need to use some special functions that require the configuration of a static IP address to facilitate the mutual access of various services. Is there any way to achieve this?
All reactions