How to Fix Internet Connection Problems in WSL 2 Ubuntu Windows 11

Several factors can cause Internet connection problems in WSL 2, including network configuration, firewalls, or problems within the Linux distribution itself.

WSL 2 (Windows Subsystem for Linux 2) is a feature that allows you to run the Linux operating system inside Windows 11. This feature is very useful for developers, administrators, and users who want to use Linux tools without having to install dual boot or virtual machines.

However, there are some problems that you may face when using WSL 2, one of which is internet connection problems. Some users reported they could not access the internet from WSL 2, or that their connection was very slow or unstable.

This can interfere with your work, especially if you need to download packages, install software, or communicate with external servers.

wsl ubuntu

There are several causes of internet connection issues in WSL 2, such as

  • Incorrect network configuration
  • The conflict between Windows firewall and WSL 2
  • Bug or error in the version of WSL 2 or Windows 11 you are using
  • Interruption in DNS or DHCP services

To fix internet connection issues in WSL 2, you can try some of the following solutions:

1] Check your internet connection status

The first step you should do is check if your internet connection works properly on Windows 11. You can do this by opening a web browser and trying to visit some websites. If you can access the website with no problems, then your internet connection is not a problem.

However, if you cannot access the website or are getting error messages like “no internet connection” or “server not found”, then there is a possibility that your internet connection is problematic.

Here, you need to check your Windows 11 network settings, such as network card, TCP/IP protocol, default gateway, DNS server, and others. You can also try to restart your router or modem or contact your internet service provider for further assistance.

If your internet connection works fine on Windows 11, but not on WSL 2, then proceed to the next solution.

2] Update WSL 2 and Windows 11 to Latest Version

One cause of internet connection issues in WSL 2 is a bug or error in the version of WSL 2 or Windows 11 you are using. To resolve this, you can try to update WSL 2 and Windows 11 to the latest available versions.

To update WSL 2, you can run the following command in PowerShell as an administrator:

wsl --update

This command will download and install the latest version of the Linux kernel for WSL 2. Once done, you need to restart your computer for the changes to take effect.

To update Windows 11, you can open Settings > Update & Security > Windows Update and click Check for updates. If there’s an update available, follow the on-screen instructions to download and install it. Once done, you also need to restart your computer for the changes to take effect.

After updating WSL 2 and Windows 11 to the latest version, try checking again if your internet connection is normal on WSL 2. If you’re still having trouble, move on to the next solution.

3] Customize WSL 2 Network Configuration

Internet connection problems in WSL 2 can also be caused by incorrect or inappropriate network configurations. WSL 2 uses virtualization to run the Linux operating system inside Windows 11 and automatically creates a virtual network interface that connects to your on-premises network.

These virtual network interfaces have a different IP address than your Windows 11 IP address and are typically assigned by the DHCP service.

However, sometimes this WSL 2 network configuration can cause conflicts or problems with your on-premises network, such as:

  • WSL 2 IP address collides with another IP address on your on-premises network
  • The default gateway or DNS server of WSL 2 does not match the default gateway or DNS server of your local network
  • Windows firewall or other security software blocks or restricts WSL 2 internet access

To solve this, you can try to adjust the WSL 2 network configuration according to your needs. There are two ways to do this, namely:

  • Change WSL 2 network settings globally via /etc/wsl configuration file.conf
  • Change WSL 2 network settings specifically for each Linux distribution via /etc/resolv.conf configuration file

Changing WSL 2 Network Settings Globally

This allows you to change WSL 2 network settings globally for all Linux distributions you run on WSL 2. You can set several options, such as:

  • generateHosts : specifies whether /etc/hosts files will be created automatically by WSL 2 or not
  • generateResolvConf : specifies whether the /etc/resolv.conf file will be created automatically by WSL 2 or not
  • network: specifies specific network settings for the WSL 2 virtual network interface, such as IP address, default gateway, and DNS server

To change WSL 2 network settings globally, you need to create or edit the /etc/wsl.conf configuration file inside the Linux distribution you are using. This file must have the following format:

[network]
generateHosts = <true|false>
generateResolvConf = <true|false>
address = <IP address>
gateway = <IP address>
nameserver = <IP address>

You can fill in the above values according to your needs. For example, if you want to assign a static IP address to a WSL 2 virtual network interface, and use the same default gateway and DNS server as your Windows 11, then your /etc/wsl.conf configuration file could look like this:

[network]
generateHosts = false
generateResolvConf = false
address = 192.168.1.100
gateway = 192.168.1.1
nameserver = 8.8.8.8

After creating or editing the /etc/wsl.conf configuration file, you need to restart your Linux distribution for the changes to take effect. You can do this by running the following command in PowerShell as an administrator:

wsl --shutdown
wsl -d <distro name>

The first command will shut down all Linux distributions running on WSL 2, and the second command will rerun the Linux distribution you want. Replace <distro name> with the name of the Linux distribution you’re using, for example, Ubuntu.

After restarting your Linux distribution, try checking again if your internet connection is normal in WSL 2. If you’re still having trouble, continue to the next method.

Changing WSL 2 network settings specifically

This allows you to change WSL 2 network settings specifically for each Linux distribution you run on WSL 2. You can set the DNS server settings used by WSL 2 to resolve domain names to IP addresses.

To change WSL 2 network settings specifically, you need to create or edit the /etc/resolv.conf configuration file inside the Linux distribution you are using. This file must have the following format:

nameserver <IP address>

You can fill in the <IP address> value with the IP address of the DNS server you want. For example, if you want to use Google’s DNS servers, then your /etc/resolv.conf configuration file could look like this:

nameserver 8.8.8.8
nameserver 8.8.4.4

You can add more than one line nameserver if you want to use more than one DNS server.

After creating or editing the /etc/resolv.conf configuration file, you need to ensure that this file will not be overwritten by WSL 2 automatically. You can do this by running the following command inside your Linux distribution:

sudo chattr +i /etc/resolv.conf

This command will make the /etc/resolv.conf file unchangeable or deleted by anyone, including WSL 2.

After changing the WSL 2 network settings specifically, try checking again if your internet connection is normal on WSL 2. If you’re still having trouble, move on to the next solution.

4] Turn Off Windows Firewall or Other Security Software

Windows firewalls or other security software that blocks or restricts WSL 2 internet access can also cause Internet connection problems in WSL 2. Windows Firewall is a feature that aims to protect your computer from unauthorized network attacks, but sometimes it can also interfere with legitimate internet connections.

To fix this, you can try to turn off the Windows firewall or other security software you are using temporarily, and see if your internet connection is up and running in WSL 2. If yes, then you need to add an exception for WSL 2 on the Windows firewall or other security software to avoid being blocked again.

To turn off the Windows firewall, you can go to Control Panel > System and Security > Windows Defender Firewall and click Turn Windows Defender Firewall on or off. Then, select the Turn off Windows Defender Firewall (not recommended) option for each existing network profile.

To add an exception for WSL 2 on the Windows firewall, you can go to Control Panel > System and Security > Windows Defender Firewall and click Allow an app or feature through Windows Defender Firewall. Then, click Change settings and check the WSL box on the list of existing apps and features.

To turn off or add exceptions for other security software you use, please follow the instructions of that software provider.

After turning off the Windows firewall or other security software, or adding exceptions for WSL 2, try checking again that your internet connection is normal in WSL 2. If you’re still having trouble, move on to the next solution.

5] Reset WSL 2 Network Settings

If the previous solutions did not work to fix the internet connection problem in WSL 2, then the last step you can try is to reset the WSL 2 network settings to the initial state. This will remove any network configurations you’ve created or changed before, and create WSL 2 using the default network settings set by Windows 11.

To reset WSL 2 network settings, you need to run the following command in PowerShell as an administrator:

wsl –shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns

These commands will shut down all Linux distributions running on WSL 2, and reset Windows 11 network settings. Once done, you need to restart your computer for the changes to take effect.

After restarting your computer, try checking again if your internet connection is normal in WSL 2. If yes, then congratulations, you have successfully fixed the internet connection issue in WSL 2. If not, then there may be other issues that cannot be solved by the above means, and you need to seek further help from the WSL 2 or Microsoft community.

Conclusion

Internet connection issues in WSL 2 Ubuntu Windows 11 are one of the problems often experienced by WSL 2 users. This issue can be caused by various factors, such as incorrect or inappropriate network configurations, conflicts between Windows firewalls and WSL 2, bugs or errors in the version of WSL 2 or Windows 11 used, or interference with DNS or DHCP services.

To fix this problem, you can try some of the solutions we have described above, namely:

  • Check the status of your internet connection
  • Update WSL 2 and Windows 11 to the latest version
  • Customize WSL 2 network configuration globally or specifically
  • Turn off the Windows firewall or other security software
  • Reset WSL 2 network settings

We hope this article can help you solve internet connection issues on WSL 2 Ubuntu Windows 11. Thank you for reading this article.

Latest Articles