Using Mirrored Network Default WSL2 Distribution with NAT-bound Applications
In this article, we will explore how to use the mirrored network default WSL2 distribution while keeping the applications NAT-bound. This is particularly useful for Docker Desktop and containers, as it ensures they are not impacted by the configuration.
What is WSL2?
WSL2 (Windows Subsystem for Linux 2) is a compatibility layer for running Linux binary executables natively on Windows 10 and Windows Server 2019. It is a significant improvement over WSL1, as it provides a real Linux kernel and better performance for Linux applications.
What is a Mirrored Network Default WSL2 Distribution?
A mirrored network default WSL2 distribution is a configuration where the WSL2 distribution's network is mirrored to the host's network, allowing the WSL2 distribution to access the host's network resources directly. This is useful for accessing network resources from within the WSL2 distribution without the need for complex configurations.
Configuring a Mirrored Network Default WSL2 Distribution
To configure a mirrored network default WSL2 distribution, follow these steps:
- Open the Windows Terminal and run the following command to check if WSL2 is enabled:
wsl --set-default-version 2- Create a new WSL2 distribution using the following command:
wsl --install -d Ubuntu- Open the
C:\Users\YourUsername\.wslconfigfile and add the following configuration:
[wsl2]
network = hostThis configuration will enable the mirrored network for the default WSL2 distribution.
Using NAT-bound Applications with a Mirrored Network Default WSL2 Distribution
To use NAT-bound applications with a mirrored network default WSL2 distribution, follow these steps:
- Open the Windows Terminal and run the following command to start the WSL2 distribution:
wsl- Install the application you want to use in the WSL2 distribution.
- Configure the application to use the NAT-bound network interface.
This configuration will ensure that the application is not impacted by the mirrored network configuration and will continue to use the NAT-bound network interface.
Using a mirrored network default WSL2 distribution with NAT-bound applications is a powerful configuration that allows you to access network resources from within the WSL2 distribution while keeping the applications NAT-bound. This is particularly useful for Docker Desktop and containers, as it ensures they are not impacted by the configuration.
References
- Microsoft. (2021). WSL 2 networking
- Docker. (2021). Docker Desktop WSL 2 backend
This article contains references to the following types of resources:
- Online resources