Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

It was noted in another thread that it should be possible to build up a white list for an android device using the /etc/hosts file. I would like to experiment with this idea. Does anyone have any guidance to offer as to how to go about it?

It has been many years since I played with that area of networking, but from what I remember the host file allows you to specify an IP for an URL which overrides the published DNS settings. With that it is fairly easy to build a list of content that I want to have accessible, or explicitly blocked, but I am not sure how that helps prevent access to other content. I am not aware of, and so far google has not showed me, any way to tell the host file to intercept all other requests. Does android support some form of wild card in the hosts file? Or is there some way to disable DNS regardless of the active network connection?

Should note that the devices I am worried about at the moment are wi-fi only tables running android 2.3.3. I am willing to root them if necessary.

share|improve this question

3 Answers 3

up vote 5 down vote accepted

/etc/hosts doesn't allow wildcards (see here: http://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:

share|improve this answer

/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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.