/etc/hosts being recreated each time I restart.
Hi
I want to add the names of my machines and ip addr to the hosts file in /etc but after a reboot the file is recreated thus wiping the changes I added.
I tried adding the IP addr and names to the windows hosts file in windows/system32/drivers/etc/hosts
But it doesn't then pick up the IP addr in the bash shell.
Is this possible as I don't want to have to keep typing in the ip addr to use ssh?
Thanks
i-frost, doesn't it get imported on bash.exe startup by the C:\Windows\System32\etc\hosts file? Microsoft said that they're trying to have the base environment make use of Windows resources as much as possible, and likely this includes /etc/hosts.
I tried adding the details to the Windows hosts file but bash does not pick them up. On May 19, 2016 6:22 PM, "fpqc" [email protected] wrote:
i-frost, doesn't it get provided by the C:\Windows\System32\etc\hosts file?
— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/Microsoft/BashOnWindows/issues/398#issuecomment-220393416
Could you do the following workaround until they fix it: Add the line to .bashrc echo $hostslineyouwantedtoadd | sudo tee -a /etc/hosts
Hey
I tried adding it to .bashrc but I just get permission denied when i start the bash shell.
I then tried adding my user name to sudoers and setting NOPASSWD but this cant get it to write it into the hosts file.
I thought this would save my bacon as I cannot get this laptop to work with its track-pad in Linux but can in windows:-(
Thanks
On Thu, May 19, 2016 at 6:27 PM, fpqc [email protected] wrote:
Could you do the following workaround until they fix it: Add the line to .bashrc sudo echo $hostslineyouwantedtoadd >> /etc/hosts
— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/Microsoft/BashOnWindows/issues/398#issuecomment-220394846
You tried the original thing I wrote (which was wrong), or the corrected one?
The thing I think will work in bash.rc is actually echo $hostslineyouwantedtoadd | sudo tee -a /etc/hosts. piping to tee -a does the same thing as >> but it is a linux program and so you can run it with sudo (instead of running all of bash with privileges). The original thing I wrote was wrong.
I'm taking a look at a way to work around this. My current thinking is to add a header to the top of /etc/hosts that says something like:
# This file was automatically generated by WSL. To prevent automatic generation of this file, remove this line.
That way if you don't want WSL to automatically generate this file you'll be able to remove the header. If you want WSL to regenerate the file you can either delete the file or add back the header.
@i-frost @fpqc Does this sound like a decent solution to you?
Sounds good to me:-)
Thanks Ben!
@benhillis I guess! Wouldn't a good solution also be to have it just read the Windows HOSTS file as a device called like /dev/hosts (or a process called /proc/hosts) and then make /etc/hosts a symlink?
That's how you guys are doing it for outputting memory management info, at least. I think that's a good idea. The more you rely on Windows-provided stuff, the fewer weird problems you'll have where you have to configure things twice, once for Windows and once for WSL.
@fpqc - I'm not sure that will work because the hosts files are different formats. Linux host files are tab separated and Windows are space separated, for example.
@benhillis I don't doubt the abilities of you guys at Microsoft to parse and reformat the HOSTS file =), but it's up to you!
On Fri, May 20, 2016 at 11:09 AM, Ben Hillis [email protected] wrote:
I'm taking a look at a way to work around this. My current thinking is to add a header to the top of /etc/hosts that says something like:
This file was automatically generated by WSL. To prevent the contents of
this file from being overwritten, remove this line.
That way if you don't want WSL to automatically generate this file you'll be able to remove the header. If you want WSL to regenerate the file you can either delete the file or add back the header.
@i-frost https://github.com/i-frost @fpqc https://github.com/fpqc Does this sound like a decent solution to you?
It is half the answer. Once the file has been modified there needs a way to allow WSL to install a fresh one.
Better to have a line with instructions to change Yes (default) to No:
WSL Update etc/hosts Yes
WSL Update etc/hosts No
Deletion of the comment defaults to Yes. Comments are almost free. In an ideal world the old file should be renamed to /etc/hosts.old and a new version not installed be /etc/hosts.new
The hosts file is one way to abuse internet connections.
— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/Microsoft/BashOnWindows/issues/398#issuecomment-220678512
T o m M i t c h e l l
@niftyhacking If the /etc/hosts file is deleted, a new one will be auto-generated (with the comment). I've checked in a fix for this and it will be making its way to the Windows Insider fast ring in a future build (a few weeks out likely).
@niftyhacking https://github.com/niftyhacking If the /etc/hosts file is delete, a new one will be auto-generated (with the comment). I've checked in a fix for this and it will be making its way to the Windows Insider fast ring in a future build (a few weeks out likely).
Thank you.
T o m M i t c h e l l
Ben's fix made it into build 14361.
Thank you so much:-) On Jun 8, 2016 9:36 PM, "Russ Alexander" [email protected] wrote:
Ben's fix made it into build 14361 https://msdn.microsoft.com/en-us/commandline/wsl/release_notes.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/BashOnWindows/issues/398#issuecomment-224719143, or mute the thread https://github.com/notifications/unsubscribe/AQGoWK3GHmB0n0qPjqY3NZltQNmp6QKUks5qJyergaJpZM4IiRT6 .
@benhillis , this solutions feels wrong to me. It seems that if you add something to your hosts file, you would want it to work both Windows side, and in WSL. I often use localhost IP's over ssh tunnels and prefer having aliases for each. I have this in my hosts:
127.0.0.2 myserver.home
127.0.0.3 myotherserver.home
Then have an ssh tunnel:
ssh mybastion.my.domain -n -N -C \
-L myserver.home:13389:myserver.home:3389 \
-L myserver.home:13389:myserver.home:3389 \
&
Allowing me to access remote desktop to myserver.home:13389 and myotherserver.home:13389. Your approach would require i come up with a way to synchronize the 2 hosts files to make this work...
Am I missing something? Perhaps you could add a second option to use windows hosts?
Currently using:
PS C:\Users\ltheisen> [System.Environment]::OSVersion.Version
Major Minor Build Revision
----- ----- ----- --------
10 0 14393 0
PS C:\Users\ltheisen> (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId
1607
Looks like #2059 states:
The functionality of adding windows hosts to /etc/hosts is currently only available in Insider builds
(if anyone else finds this thread on google like me, adding windows hosts to /etc/hosts is now in the regular builds)
Hello,
I'm running build 16299 and the comment I have in /etc/hosts is diferent:
cat /etc/hosts
# This file is automatically generated by WSL based on the Windows hosts file:
# %WINDIR%\System32\drivers\etc\hosts. Modifications to this file will be overwritten.
127.0.0.1 localhost
[...]
In my use case, I don't want to modify Windows's hosts file, just the WSL one ! So adding the entries in Windows's hosts file is not an option for me !
Ideally a "diff" mechanism between Windows and WSL whould be IMHO the best approach..
Regards,
PS: I'm running Debian in my WSL
This is configurable via the wsl.conf setting 'generateHosts'.