Windows Subsistem for Linux (WSL) – Make /etc/resolv.conf changes permanent

Posted: November 16, 2022 in Linux

Even after creating /etc/wsl.conf

[network]
generateResolvConf = false

And specifying desired DNS server in /etc/resolv.conf, after WSL reboot, /etc/resolv.conf reverts it’s content.

Here is how to make changes in /etc/resolv.conf make permanent:

sudo rm /etc/resolv.conf
sudo bash -c 'echo "nameserver 1.1.1.1" > /etc/resolv.conf'
sudo bash -c 'echo "[network]" > /etc/wsl.conf'
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
sudo chattr +i /etc/resolv.conf

chattr +i command makes file immutable so /etc/resolv.conf file cannot be modified nor deleted.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s