What the Windows 'hosts' file encoding is? Is it UTF-8? Or ASCII + system codepage? How IDN (international domain names with umlauts etc.) entries should be added and can they be added at all?
It should be ANSI or UTF-8 without BOM. I just dealt with a server that had the hosts file encoding set to UCS-2 Little Endian, and that led to the file being ignored.
There is a wealth of information here: https://serverfault.com/questions/452268/hosts-file-ignored-how-to-troubleshoot
The simple answer is ANSI or UTF-8 WITH BOM.
(UTF-8 without BOM is NOT valid).
Details:
As far as I have tried, the encoding of the hosts file on Windows should be
ANSI or UTF-8 with BOM.
I know this question is many years old, but a colleague made the mistake of looking at this post and the ServerFault post, so I decided to add an answer.
Works.
Without any multi-byte characters, This is equivalent to ANSI, also equivalent to UTF-8 without BOM.
Works.
note: There are Japanese characters but this is valid ANSI encoding in windows.
In Japanese editions of Windows, this code page
cp932
is referred to as "ANSI",https://en.wikipedia.org/wiki/Code_page_932_(Microsoft_Windows)
Works.
note: BOM 付き
means with BOM
.
DOES NOT work.
If you use emoji instead of Japanese, the result will be the same.
Use emoji and save as UTF8 without BOM
does not work.
(However, other lines not include emoji may be worked correctly.)
Use emoji and save as UTF8 with BOM
can resolve host correctly.
note: If you use Notepad to check it yourself, be sure to put double quotes in the file name when you save it, or Notepad will be create hosts.txt
.
Appended: (Asked in comment) The hosts file supports inline comments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With