SmoothDenis / wsl2-dns-fix-config

One-liner Shell script to setup your WSL to use CloudFlare DNS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WSL2 DNS Fix/Config

shell

One-liner shell script that will setup your WSL2 image to use custom nameserver 8.8.8.8 from Google.

Usage

Clone and run the shell:

sudo sh ./run.sh

Restart WSL:

wsl --shutdown

All done. Make sure you read what it does.


ℹ️ GitHub DNS not resolving?

You can try curl --resolve with one of GitHub's IP addresses to force DNS resolution:

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

tar -xf wsl2-dnsfix.tar.gz

sudo sh wsl2-dns-fix-config-1.0.0/run.sh

This will work in distros like Ubuntu 22.04 which are not recognizing github.com out of the box.

Yet another way is to get the archive form the releases:

curl -L 'https://github.com/SmoothDenis/wsl2-dns-fix-config/archive/refs/tags/v1.0.0.tar.gz' -o wsl2-dnsfix.tar.gz

What it does

The run.sh script will perform these tasks:

  1. Delete the following files: /etc/wsl.conf and /etc/resolv.conf

  2. Create the new ".conf" files (pre-created in the dist folder) setting Google DNS for name resolution and preventing WSL from overriding it:

    # /etc/wsl.conf
    [network]
    generateResolvConf = false
    # /etc/resolv.conf
    nameserver 8.8.8.8
  3. Make /etc/resolv.conf immutable

Contributing

Feel free to open an issue/discussion or send a pull request.

Tested on:

  • Ubuntu 20.04
  • Ubuntu 22.04

Source / Credits

https://gist.github.com/coltenkrauter/608cfe02319ce60facd76373249b8ca6

About

One-liner Shell script to setup your WSL to use CloudFlare DNS.

License:MIT License


Languages

Language:Shell 100.0%