Fix Android 'hosts' File Not Working
Jan 5, 2015MobileComments (4)
If your Android hosts file is not working as expected and you know it is written correctly, here are four things you should check:


File Location


Make sure your hosts file is in the correct location. On Android it is the directory:

/system/etc
So the hosts file will be at:

/system/etc/hosts

File Extension


Make sure that a file extension has not been added to the hosts file. The hosts file should have no extension. If you've created a new text file, your operating system may have added a .txt extension. Windows by default hides extensions, so this may not be obvious if you're using Windows. You can set Windows to show file extensions, which will make it easier.


Restart


If you haven't yet, restart your device. This shouldn't be necessary, but given the wide range of possible software that may be installed (some having root access), it's a good idea.


File Overwriting


Double-check that Android hasn't overwritten your hosts file, especially after you've restarted your device.


Incorrect Newline Characters


The Android hosts file should use Linux/UNIX style newlines, which are a single Line Feed LF character per new line. If your hosts file has been generated or manipulated on a Windows computer, chances are the newlines were changed to the Windows style, which consists of a Carriage Return & Line Feed [CR][LF] per new line. If these Windows style newlines exist in your hosts file, it will not be parsed properly by Android (Android is Linux based).

To determine what newline characters are in your hosts file, you'll need a better text editor than the default Windows one. Notepad++ is a good one. You can have it show the newline characters by going to View > Show Symbol > Show End of Line. You can then have it convert to the UNIX format by going to Edit > EOL Conversion.
Comments (4)
Add a Comment
Dan   Nov 12, 2019
not working on my android 5 i even added 0.0.0.0 youtube.com 0.0.0.0 www.youtube.com ping from terminal emulator resolve it to 127.0.0.1 but browsers still access youtube.com i change the line ending to linux i added a new line at the end of the file i rebooted the phone. still no success.
Vix   Jan 26, 2019
Finally, it works! thank you
Rick   Aug 23, 2018
Really this saved me because my host file was sortof working (the browser worked Ping did not nor any apps). Changed the CR/LF to LF boom everything works as expected
Hiver911   Aug 09, 2018
Thank you, this help me so much!