top of page

WSL2 DNS Fix/Config

May 9, 2022
2 min read

Windows Subsystem For Linux (WSL) is a tool provided by Microsoft to run Linux natively on Windows. It’s designed to be a seamless experience, essentially providing a full Linux shell that can interact with your Windows filesystem.


Basically, WSL allows you to install a full Linux distribution as an app from the app store. You can simply download Ubuntu (or the distro of your choice), install it, and have it available as a app you can launch, or a profile in your terminal to run alongside CMD or Powershell.


I was facing an issue with my WSL that when I start it I can't make a DNS request.

Ping an IP address directly and it works fine. And here's the resolution.



Tested on:

  • WSL - Ubuntu 20.04 (LTS);

  • Windows 11 (21H2).


✖ The problem:

root@DRM:/etc/DRM# apt update
Err:1 http://archive.ubuntu.com/ubuntu focal InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:2 http://security.ubuntu.com/ubuntu focal-security InRelease
  Temporary failure resolving 'security.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease
  Temporary failure resolving 'archive.ubuntu.com'

✔ Ping OK:

root@DRM:/etc/DRM# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=9.98 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=118 time=8.21 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=118 time=8.78 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=118 time=8.82 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=118 time=10.1 ms
64 bytes from 8.8.8.8: icmp_seq=6 ttl=118 time=9.79 ms
64 bytes from 8.8.8.8: icmp_seq=7 ttl=118 time=9.46 ms
64 bytes from 8.8.8.8: icmp_seq=8 ttl=118 time=10.1 ms
64 bytes from 8.8.8.8: icmp_seq=9 ttl=118 time=10.3 ms

┊┋ How to solve this issue? ┋┊



#1) Download the .gz file using this URL:

curl --resolve 'codeload.github.com:443:20.201.28.149' \
  'https://codeload.github.com/epomatti/wsl2-dns-fix-config/tar.gz/refs/tags/v1.0.0' \
  -o wsl2-dnsfix.tar.gz

#2) Type the command below:

root@DRM:/etc/DRM# tar -xf wsl2-dnsfix.tar.gz

#3) Run the shell and restart WSL:

root@DRM:/etc/DRM/wsl2-dns-fix-config-1.0.0# sudo sh ./run.sh
root@DRM:/etc/DRM/wsl2-dns-fix-config-1.0.0# wsl --shutdown

#4) Check if the files below are the same as in the example:

root@DRM:/etc# more wsl.conf
[network]
generateResolvConf = false

root@DRM:/etc# more resolv.conf
nameserver 8.8.8.8

#5) Now check if everything is OK:

root@DRM:/home/stenge# apt update
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Reading package lists... Done


Recent Posts

See All
Ed25519: A Modern Approach to SSH Authentication

SSH keys are one of the most effective ways to secure remote access to Linux servers. While RSA has been widely used for decades, Ed25519 has become an excellent choice for modern SSH environments. Wh

 
 
 
Portable AI

Have you ever imagined carrying your own AI assistant in your pocket, for free? With today's open-source AI models, it's entirely possible. By storing the required software and models on a USB flash d

 
 
 
Homebrew on macOS

If you use Homebrew to manage your development tools on macOS, keeping it updated is an important part of maintaining a reliable development environment. A simple maintenance routine helps keep packag

 
 
 

Comments


STENGE.info | Built with curiosity. Secured by knowledge.

bottom of page