shayne / go-wsl2-host

Automatically update your Windows hosts file with the WSL2 VM IP address
1.65k stars 140 forks source link

Creates too many comments #66

Open taythebot opened 2 years ago

taythebot commented 2 years ago

So I have Glasswire installed and it tells me whenever the hosts file is changed. Every hour I will get a notification that it has been modified by this program. The IP addresses don't seem to change at all, but it's commenting out the old entries and creating new ones. At the end of each day, I'll have around 20-30 commented out lines.

Is there some way to prevent this behavior?

OgulcanCelik commented 2 years ago

I'm having exactly the same problem, hosts get filled up with the same IP and hostname over and over again, hundreds of times.

OgulcanCelik commented 2 years ago

image here is the example

stephanesoares commented 2 years ago

Anyone have a fix for this?

Rragen commented 2 years ago

I had the same problem, and it was because the service is looking for your hosts in the /etc/hosts file on the vm, not on the Windows file. And for some reason, my VM /etc/hosts file wasn't updated automatically, so it was adding again and again new lines.

I had to create / add content to this file on the VM : /etc/wsl.conf

[network]
generateHosts = true

You have to restart your linux instance after adding the fil. In powershell : Restart-Service LxssManager

It did the trick for me.

Edit : Well no, I still have duplicate entries coming :(

OgulcanCelik commented 2 years ago

Yes I tried it but it's still happening :/

mverkerk-godaddy commented 1 year ago

same problem here, numerous entries in my hosts file except mine looks like this:

 wsl.local    # alias: Ubuntu; managed by wsl2-host
 custom.domain    # alias: Ubuntu; managed by wsl2-host
 wsl.local    # alias: Ubuntu; managed by wsl2-host
 custom.domain    # alias: Ubuntu; managed by wsl2-host
 wsl.local    # alias: Ubuntu; managed by wsl2-host
 custom.domain    # alias: Ubuntu; managed by wsl2-host
 wsl.local    # alias: Ubuntu; managed by wsl2-host
 custom.domain    # alias: Ubuntu; managed by wsl2-host
 wsl.local    # alias: Ubuntu; managed by wsl2-host
 custom.domain    # alias: Ubuntu; managed by wsl2-host
 ... and so on ...

Also, it's not consistent in adding entries from the ~/.wsl2hosts file (like "custom.domain" in my example above) - sometimes it's there, next time it's commented out ...

I'm running Windows 11 with WSL2 (Kernel version: 5.10.102.1) In Event Viewer I see the following:

I have two different Ubuntu distros & Ubuntu-22.04 is the default - not sure if that messes things up lmk if you need more troubleshooting data...