Android - Guide to editing /etc/hosts

/etc/hosts doesn't allow wildcards (see here: https://serverfault.com/questions/118378/in-my-etc-hosts-file-on-linux-osx-how-do-i-do-a-wildcard-subdomain).

Two more links about /etc/hosts:

  • HOWTO Configure your hosts file: http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:Ch03:_Linux_Networking#Configuring_Your_.2Fetc.2Fhosts_File
  • Large example file with nice intro header: http://someonewhocares.org/hosts/
  • Small Android app that allows you to add an entry to the hosts file (requires root): https://market.android.com/details?id=com.pof.Add2Hosts

/etc/hosts is in this context is really only good for blacklisting.

For whitelisting, you'd be best off using a proxy server and then setting your device to use it in your device's network settings.

You can subscribe to an existing proxy server service, or set up your own at home. That should be enough info to get you googling to the answers you need. I've added a little more detail to this answer on your original thread.

FYI, using a proxy server does not require rooting.


The hosts file acts sort of like a local DNS, it will check the hosts file for the domain and see if there is an assigned IP address in it. If there is, that is the IP address used for the domain. You can't set a white list, but you could do more of a black list. The file looks something like this:

somebaddomain.com 127.0.0.1
someotherdomain.com 127.0.0.1

this would make any request to either of those domains resolve to localhost. If the domain is not in the file, it will then hit the external DNS to attempt to get the IP address.

There is a catch to this, you will need root to modify the hosts file.

Tags:

Settings

Wi Fi