How to manually trigger an update of /etc/hosts in WSL? [closed]

When I start the first WSL terminal (ubuntu 20.04 bash in my case), WSL generates the /etc/hosts file based on the host file of my windows system %WINDIR%\System32\drivers\etc\hosts.

If I now change the %WINDIR%\System32\drivers\etc\hosts, e.g. add some entries, the /etc/hosts in my WSL is not updated. Even if I close all WSL terminals and open a new one. Only reboot of my windows system helps.

Is there a way I can manually trigger the update of the /etc/hosts so that I do not have to reboot?


Solution 1:

As long as this

[network]
generateHosts = true
generateResolvConf = true

is in your /etc/wsl.conf a restart of the LxssManager* services should do the trick.

Restart-Service LxssManager*

But: Restarting Lxss* will terminate all your running WSL Instances.