Everytime I want to start mij viktor app, I need to change the ‘nameserver’ for it to work.
I do this by:
sudo nano /etc/resolv.conf
Then typing the following in the file:
Then I save (CTRL+S) and exit.
Howevery, the next time (after shutting down my laptop) the
resolv.conf is empty again. How can I fix this?
This is a known issue in WSL2 where DNS resolution is not working. Microsoft is tracking the problem in this issue.
Your solution is indeed the way to go by configuring WSL2 to use Google’s public DNS server located at IP address 188.8.131.52. However, I believe an additional step is needed where you disable the automatic generation of a new
resolv.conf. You can do this by:
- Creating a WSL configuration file:
- Disable generating
resolv.conf by adding to the wsl.conf:
generateResolvConf = false
Hope this helps!
Unfortunately this does not work. I already tried this before, but I still have the same issue.
Hm that is unfortunate:(
How about running a script on startup to do these manual steps for you?
- In your home folder create a script to remove the old
resolv.conf and create a new one with the other nameserver. Call this script
fix_dns.sh and add the following lines:
# remove existing resolv.conf
rm -rf /etc/resolv.conf
# create a new resolv.conf and append the nameserver setting
echo "nameserver 184.108.40.206" | tee /etc/resolv.conf
- Make sure the script can be executed by typing the following command in the terminal
chmod +x fix_dns.sh
- Use crontab to add a task that executes the script on (re)boot:
sudo crontab -e
Choose nano to edit the file and add the following line:
@reboot /home/[insert username here]/fix_dns.sh
Please note that you need to provide the full path to the script. You can find the path of your home folder by using the command
echo $HOME. Use Ctrl+x, y and Enter to save the file. Reboot and check whether the files has been updated with:
Let me know if this fixes the problem!