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

Extra chars in /etc/hosts #9642

Closed
1 of 2 tasks
elsaco opened this issue Feb 16, 2023 · 6 comments
Closed
1 of 2 tasks

Extra chars in /etc/hosts #9642

elsaco opened this issue Feb 16, 2023 · 6 comments

Comments

@elsaco
Copy link

elsaco commented Feb 16, 2023

Version

Microsoft Windows [Version 10.0.19045.2604]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

5.15.90.1

Distro Version

AlmaLinux 9.1

Other Software

No response

Repro Steps

Check system logs for bad address at /etc/hosts kind of message (i.e. journalctl --grep "bad address")

Expected Behavior

No extra characters added to /etc/hosts

Actual Behavior

<feff> added to /etc/hosts. Top pane show Windows' hosts file content. The bottom is WSL, Use view to display as cat or bat won't show it. Notice line 6:

wsl_hosts

Diagnostic Logs

No response

@ghost
Copy link

ghost commented Feb 17, 2023

Thanks @elsaco, as a sanity check wsl --version are you on?

@ghost ghost added the needs-author-feedback label Mar 7, 2023
@ghost
Copy link

ghost commented Mar 7, 2023

None of us have been able to repro this. If you have any clues that'd be appreciated.

@elsaco
Copy link
Author

elsaco commented Mar 7, 2023

FEFF looks like a BOM signature. I can't tell where/how it was added to the /etc/hosts but it's gone now. Trying to setup dnsmasq would trigger invalid entry in host file error messages, otherwise I wouldn't notice it. Can't repro now.

@xanderificnl
Copy link

xanderificnl commented Mar 31, 2023

I'm seeing the same issue. You might be able to reproduce this issue by displaying non-printable characters, i.e. look for M-oM-;M-? by running cat -A /etc/hosts

Windows' host file starts with the offending character and it seems like it's being appended (albeit stripped from comments) to /etc/hosts - if I'm right, the solution is to remove the UTF-8 BOM from Windows' host file before appending to /etc/hosts

Get lines 6-9 from /etc/hosts and display non-printable characters

$ sed '6,9!d' /etc/hosts | cat -A
M-oM-;M-?$                                                                                      # <FEFF>
192.168.88.254^Ihost.docker.internal$
192.168.88.254^Igateway.docker.internal$
127.0.0.1^Ikubernetes.docker.internal$

Reformat Windows' host file

$ sed -f w32hosts.sed /mnt/c/Windows/System32/drivers/etc/hosts | cat -A
M-oM-;M-?$                                                                                      # <FEFF>
192.168.88.254^Ihost.docker.internal$
192.168.88.254^Igateway.docker.internal$
127.0.0.1^Ikubernetes.docker.internal$
w32hosts.sed
# Strip comments from
s/#.*//g
# Remove carriage returns
s/\r//g
# Remove empty lines
/^$/d
# Ensures spaces are tabulars
s/[[:space:]]/\t/g

@Tatsh
Copy link

Tatsh commented Feb 26, 2024

Is Docker Desktop to blame for this? I do not think the file normally has a BOM at all. None of the other text files in the Windows etc directory have it.

@AnixPasBesoin
Copy link

This issue is still prevalent, any fix?

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

No branches or pull requests

4 participants