How to configure unique IP addresses for WSL2 instances? #12069
Replies: 4 comments 4 replies
-
|
Anyone? |
Beta Was this translation helpful? Give feedback.
-
|
I stumbled over the same problem. |
Beta Was this translation helpful? Give feedback.
-
|
Answered by #4304 |
Beta Was this translation helpful? Give feedback.
-
|
🌐 Why WSL2 Instances Share the Same IP (and How to Configure Unique Ones) WSL2 doesn’t run VMs like VirtualBox/VMware with individual NICs. Instead, it uses a single lightweight utility VM with a virtual switch (Hyper-V) that hosts all your Linux distributions. Each distro (Ubuntu 22.04, 24.04, etc.) is isolated at the process level, but they share the same network namespace, so they appear under the same internal IP. That’s why your Ubuntu 22.04 and 24.04 both show the same IP — they’re riding on the same network interface provided by the WSL2 VM. 🛠️ Options to Assign Unique IPs Use localhost/port binding (Recommended for most use cases) Instead of relying on per-distro IPs, bind each service to a unique port. Example: Ubuntu 22.04 service → localhost:8080 Ubuntu 24.04 service → localhost:9090 WSL automatically handles port forwarding from Windows to the right instance. Enable WSL2 networking with separate NAT adapters (Experimental / Hacky) You can configure separate Hyper-V NAT networks and attach different WSL distros to them using wsl.conf and custom scripts. Example: Create a new vSwitch and assign it to a distro manually. Run one instance under WSL2 and another under WSL1 WSL1 instances have their own unique networking model (they use Windows’ network stack directly). This way you can run 22.04 on WSL2 and 24.04 on WSL1 with distinct IP behavior. Use Docker or VM approach for strict IP separation If you truly need per-distro unique IPs (like for complex multi-host setups), it’s cleaner to use Docker networks or full Hyper-V VMs. 📌 Bottom Line By design, WSL2 distros share the same virtualized network interface → same IP. For most workflows, unique ports per instance is the recommended solution. If you absolutely need unique IPs, you’ll have to rely on advanced networking (custom Hyper-V NAT) or switch one distro to WSL1. ✅ In short: WSL2 isn’t designed to give each distro its own IP — they all share the same VM’s network namespace. The practical solution is to differentiate services by ports or use WSL1/VMs for strict per-distro IP isolation. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm running WSL2 on Windows 10 22H2. I have an existing instance of Ubuntu 22.04 and I want to migrate it to Ubuntu 24.04. I want to leave the 22.04 instance alone while I'm setting up the new 24.04 instance. I created the 24.04 instance and I noticed that it has the same IP address as the 22.04 instance. Why is this? It makes no sense that both instances should have the same IP address when they are clearly distinct from each other. Is there a way to change the IP address of the 24.04 instance?
Beta Was this translation helpful? Give feedback.
All reactions