H3XED

Fix Android 'hosts' File Not Working

Jan 5, 2015   Mobile   Nick Vogt   Comments (2)
Please note that this post is over a year old and may contain outdated information.
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.
Share This Post
Twitter

Comments (2)

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!
Share This Post
Twitter
H3XED © Nick Vogt   RSS   Policies   Twitter