Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/etc/hosts does not update #2059

Closed
chx opened this issue May 5, 2017 · 12 comments
Closed

/etc/hosts does not update #2059

chx opened this issue May 5, 2017 · 12 comments

Comments

@chx
Copy link

chx commented May 5, 2017

I changed C:\Windows\System32\drivers\etc\hosts, verified in an already open powershell window that the change is picked up. Then closed my bash window (no other bash windows are open) and upon restart, the new entry was not added. I have # This file was automatically generated by WSL. To stop automatic generation of this file, remove this line. in my /etc/hosts.. I read #890 (comment) but it didn't help.

@benhillis
Copy link
Member

Please fill out the issue template. It looks like you are running a build that does not add windows hosts to the /etc/hosts file.

@chx
Copy link
Author

chx commented May 5, 2017

Sorry, it's Ubuntu 16.04.2 LTS / Microsoft Windows [Version 10.0.15063]

@benhillis
Copy link
Member

No worries. The functionality of adding windows hosts to /etc/hosts is currently only available in Insider builds.

@chx
Copy link
Author

chx commented May 5, 2017

Oh. That was a 2016 comment and since I am on Creator's Update I thought it's already in. Nevermind then!

Any workarounds? (cp when bash starts :) ? )

@lucastheisen
Copy link

@chx , your suggestion works for me... I'm doing this (in my .bashrc):

sudo cp /mnt/c/Windows/System32/drivers/etc/hosts /etc/hosts

Just have to log out/in after any changes.

@AsharLohmar
Copy link

For whoever ends up on this page for having the issue on the recent versions of windows.

I 'm on Ubuntu 18.04 on

Microsoft Windows [Version 10.0.18362.295]

and I have

[network]
generateHosts = true
generateResolvConf = true

in /etc/wsl.conf, but the files was not being regenerated when I was closing all the session.
My solution, in order to avoid a doing a restart, was to go in the services tool (services.msc) and restart the LxssManager* services.

@benhillis
Copy link
Member

@AsharLohmar - The files are updated when the session is launched, not when it exits.

@AsharLohmar
Copy link

AFAIK, the file is regenerated when the first session is started (might be wrong), that's why I mentioned that I was was closing all the sessions. The check it self was to fire up a new shell/session and cat the file.

@benhillis
Copy link
Member

@AsharLohmar - To ensure a new session is created you must terminate any running ones (wsl.exe --terminae )

@AsharLohmar
Copy link

Didn't know that, thanks, I usually use kill -9 -1 and brutally kill everything.

@yaronmirowebpals
Copy link

yaronmirowebpals commented Aug 31, 2021

There is also the option to open the Windows Power Shell and run one of the following commands (no need to restart windows)
wsl --shutdown or wsl.exe --shutdown will regenerate the Linux hosts file according to the widows 10 hosts file.
Note: if the WSL CLI is opened it will close it for you and when you reopen it will have the most updated hosts file.

@treysis
Copy link

treysis commented Apr 20, 2022

The generated file seems to not be an exact copy of the Windows hosts file, but also includes some lines added by the distro, in my case Ubuntu. Can anybody tell me how these additional entries are generated/where they are stored? I want to add ::1 localhost to the /etc/hosts which for some weird reason has been removed by Ubuntu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants