How can I have different ip for differnt distrubutions on wsl2?

Viewed 2000

I am running 5 different Ubuntu distro on wsl2 but all are having the same ip address.For example Ubuntu 18.04 and Ubuntu 20.04 are having the same ip. Is it possible to have different ips on each Ubuntu versions?

2 Answers

Full disclosure: This answer does not address networking between to wsl2 instances. Rather, it presents - as requested from a commenter - an alternative way to have two guest operating systems to each have their own IP address within a network that is "inside" the host OS.

The following allows for two VMs (rather than wsl2 instances) to have different IP addresses within a network within a host Windows 10 operating system:

  • Prerequisites in no particular order:
    • Disable the Hyper-V Windows Feature. This page describes a variety of ways to go about it, but I went the Control Panel route.
    • Install VirtualBox
  • Set up a network for the VMs to share:
    1. Open VirtualBox
    2. Click File > Preferences
    3. Click Network
    4. Click the icon with a plus sign (+) in it to add a new network
  • Create your VMs and connect them to this network
    1. Create the VM and give it an operating system as you would otherwise
    2. Shut down the VM
    3. Select the VM in the main VirtualBox window, click the Settings/gear button
    4. Click Network
    5. Select NAT Network for "Attached to"
    6. Select the name of the network you created above. (A sample that worked for me is below.) enter image description here
  • Customize the overall network settings for the VMs
    1. Return to main VirtualBox window > File > Preferences > Network
    2. Click gear icon to edit the network
    3. Click Port Forwarding
    4. Enter details (such as the following, but modified for you needs) to direct traffic from local host to certain IP addresses/ports within this network enter image description here
Related