Not having to change the nameserver every time before viktor-cli start

Hi,
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:
nameserver ‘8.8.8.8’
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?

Hi Marlies,

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 8.8.8.8. However, I believe an additional step is needed where you disable the automatic generation of a new resolv.conf. You can do this by:

  1. Creating a WSL configuration file: touch /etc/wsl.conf
  2. Disable generating resolv.conf by adding to the wsl.conf:
[network]
generateResolvConf = false

Hope this helps!

Hi Raoul,

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?

  1. 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:
#!/bin/bash
 
# remove existing resolv.conf
rm -rf /etc/resolv.conf

# create a new resolv.conf and append the nameserver setting
echo "nameserver 8.8.8.8" | tee /etc/resolv.conf
  1. Make sure the script can be executed by typing the following command in the terminal
chmod +x fix_dns.sh
  1. 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:

cat /etc/resolv.conf

Let me know if this fixes the problem!