Fun with Hosts

FAIL (the browser should render some flash content, not this).

How to edit your hosts file to redirect urls, which is a fun way to play pranks at work or keep your kids off myspace!

Download in .ogv format


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I am getting a

Anonymous's picture

I am getting a su:authentication failure , and how to do it using a sudo cmd. ty for the article :)

hackers know....

hoizonE's picture

hackers know that subverting the hosts file and dns's is as simple as using the ``host'' command and/or typing the url as
[http[s]?://] ip1.ip2.ip3.ip4 [:<80|8080|443>]

and when i say "hackers," what i mean is "kids trying their damnedest to access myspace"

they also happen to know that googling for will take them to a site that allows the finding of any dns/registrant info from a remote machine (ie. one that is not affected by the /etc/hosts or local dns changes). many other sites share this site ability (including most search tools, themselves).

and why not introduce this specific ability (changing expected hosts) from, say, iptables? that way, not only can you change the destination of, but you can also log access attempts and log successful bypasses of the rule...

linux is not the only OS that has this nice little trick (M$, Sol, HPUX, BSD, et al., also have a hosts file to abide to).

microsoft doesn't exist!

Anonymous's picture

awesome. Now I can block websites on Linux without squid!

Oh, and I can make =


RE: Better ways...

Joe Tole's picture

Oh and djbdns keeps logs of all requests if you are really concerned about your kids going to I know I would be. :O

Better ways...

Joe Tole's picture

When looking up a host name, you can use the command host or dig instead of ping. Ping sends extra data to the host when all you need is an IP address.

host -t a has address has address has address

Also, DNS can be even more effective then a host file since DNS can do wildcards and afaik a host file cannot. djbdns is easy to setup for a cache (using dnscache) and tinydns as a resolver. You can tell dnscache to use a host of your choosing to resolve a domain name by creating a file named /etc/dnscache/root/servers/domain.tld with the IP. In this case you can run dnscache on your external IP and tinydns on your loopback. Create a file named /etc/dnscache/root/servers/ which contains the IP address "" where tinydns is listening and then create these entries in /etc/tinydns/root/data:

This will redirect all requests to to the google IP address including, and even Wildcards FTW! ;)