Introduction
In this article, we will discuss the issue of not using a bridge adapter in VirtualBox for Ubuntu installed on WSL2. Many users may encounter this issue when they try to connect the Ubuntu instance on WSL2 to a VirtualBox Ubuntu instance. We will explain the concepts related to this issue and provide detailed solutions to fix it.
What is WSL2?
WSL2 (Windows Subsystem for Linux version 2) is a feature of Windows 10 that allows users to run Linux distributions natively on Windows without the need for a virtual machine. WSL2 uses a lightweight virtual machine that runs in the background and provides a Linux kernel to the Linux distribution installed on it.
Benefits of using WSL2
WSL2 provides several benefits over using a traditional virtual machine, such as:
- Faster boot times
- Better integration with Windows applications
- Less disk space usage
- Improved file system performance
Why use VirtualBox with WSL2?
While WSL2 provides a significant improvement over traditional virtual machines, it may not be able to provide all the functionalities that a full virtual machine can offer. In such cases, users may need to use a virtual machine application, such as VirtualBox, on top of WSL2.
Benefits of using VirtualBox with WSL2
Using VirtualBox with WSL2 provides several benefits, such as:
- Running GUI applications on the Linux distribution
- Isolating the Linux distribution from the Windows host
- Providing network functionalities not available in WSL2
Issue: Not Using Bridge Adapter in VirtualBox for Ubuntu on WSL2
Users who try to connect the Ubuntu instance on WSL2 to a VirtualBox Ubuntu instance may encounter issues when using the default NAT network adapter in VirtualBox. Instead, users should use the bridge adapter in VirtualBox to connect the VirtualBox Ubuntu instance to the same network as the WSL2 Ubuntu instance.
Why use a Bridge Adapter?
A bridge adapter in VirtualBox connects the VirtualBox virtual machine to the same network as the host machine. This allows the VirtualBox virtual machine to have a unique IP address on the same network as the WSL2 Ubuntu instance. This configuration enables both instances to communicate with each other without any issues.
How to fix the Issue?
To fix the issue of not using a bridge adapter in VirtualBox for Ubuntu on WSL2, follow these steps:
- Shut down the VirtualBox Ubuntu instance
- Change the network adapter in VirtualBox to bridge mode
- Start the VirtualBox Ubuntu instance
- Configure the network settings in the VirtualBox Ubuntu instance to have a static IP address on the same network as the WSL2 Ubuntu instance
Step-by-Step Guide
Here is a step-by-step guide on how to fix the issue:
- In VirtualBox, select the VirtualBox Ubuntu instance and click on Settings
<VirtualBox window showing the Settings dialog box for the VirtualBox Ubuntu instance>
- In the Settings dialog box, click on Network and then on the Adapter 1 tab
<VirtualBox window showing the Network settings for the VirtualBox Ubuntu instance>
- Select the Attached to: option and choose Bridged Adapter
<VirtualBox window showing the Bridged Adapter option selected for the VirtualBox Ubuntu instance>
- Click on OK to save the settings and start the VirtualBox Ubuntu instance
<VirtualBox window showing the VirtualBox Ubuntu instance started in bridge mode>
- Configure the network settings in the VirtualBox Ubuntu instance to have a static IP address on the same network as the WSL2 Ubuntu instance.
$ sudo nano /etc/netplan/01-netcfg.yaml
Change the network configuration to have a static IP address on the same network as the WSL2 Ubuntu instance. Here is an example configuration:
network:
ethernets:
enp0s3:
addresses: [192.168.1.10/24]
routes:
- to: 0.0.0.0/0
via: 192.168.1.1
nameservers:
addresses: [8.8.8.8,8.8.4.4]
Save the configuration file and apply the changes:
$ sudo netplan apply
Not using a bridge adapter in VirtualBox for Ubuntu on WSL2 can cause issues when trying to connect the VirtualBox Ubuntu instance to the WSL2 Ubuntu instance. By using a bridge adapter and configuring the network settings in the VirtualBox Ubuntu instance, users can avoid this issue and ensure smooth communication between both instances.
References
-
Type: Article
Title: How to run GUI applications in WSL
URL: HTTPS://DEV.TO/ANUVRATTRIPATHI/HOW-TO-RUN-GUI-APPLICATIONS-IN-WSL-2BP1 -
Type: Article
Title: How to connect WSL to a virtual machine
URL: HTTPS://DEV.TO/SHADID/HOW-TO-CONNECT-WSL-TO-A-VIRTUAL-MACHINE-4OJM -
Type: Article
Title: How to set up WSL2 for Docker
URL: HTTPS://MEDIUM.COM/GEEKCULTURE/HOW-TO-SET-UP-WSL2-FOR-DOCKER-ON-WINDOWS-10-2BB92E2A9B7B