Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 666
Sanjeet A Avatar asked Nov 01 '20 07:11

Sanjeet A


People also ask

Can you have multiple WSL distros?

Windows Subsystem for Linux (WSL) allows you run a Linux enviroment on Windows, using your favourite Linux distribution. You can even install multiple types of distributions side-by-side. However, there is no out-of-the-box way to install multiple instances of the same distribution.

Does WSL have a different IP?

WSL 2 has a virtualized ethernet adapter with its own unique IP address.

How do I change my WSL distribution?

Set default Linux distro on WSL2Open Start on Windows 10. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Quick tip: You can also write the command like this: wsl -l . In the command, replace DISTRO-NAME for the name of the distro to set it as default (see step No.


Video Answer


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
like image 136
Leif Segen Avatar answered Oct 23 '22 07:10

Leif Segen


You can create new processes with new network namespaces, so you can achieve network isolation.

ip netns add net1
ip netns exec net1 ip addr add 192.168.99.10/24 dev sit0
ip netns exec net1 exec bash

Reference: https://blogs.igalia.com/dpino/2016/04/10/network-namespaces/

like image 38
Brito Avatar answered Oct 23 '22 05:10

Brito