Skip to content

Instantly share code, notes, and snippets.

@rajshrimohanks
Created May 25, 2022 07:50
Show Gist options
  • Save rajshrimohanks/afad5f14fda76f1beeb61b27b4c4d125 to your computer and use it in GitHub Desktop.
Save rajshrimohanks/afad5f14fda76f1beeb61b27b4c4d125 to your computer and use it in GitHub Desktop.
Prevents WSL2 from overwriting resolv.conf everytime and persists the resolv.conf file.
#!/usr/bin/env bash
sudo rm /etc/resolv.conf
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "[network]" > /etc/wsl.conf'
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
# Make resolv.conf immutable so that the OS can't change it.
# If you'd like to make changes to this file later, you've to
# make it mutable again by issuing the following command:
# sudo chattr -i /etc/resolv.conf
sudo chattr +i /etc/resolv.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment