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:
Make sure your hosts file is in the correct location. On Android it is the directory:
So the hosts file will be at:
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.
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.
Double-check that Android hasn't overwritten your hosts file, especially after you've restarted your device.
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.
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.