How to block web sites in Linux by using the hosts file

tip
Sep 10, 20131 min

Use the hosts file to block access to sites in Linux

Here’s how you can use the hosts file to block access to web sites in Linux.

1. Open a terminal window.

2. Type in the following command to back up your hosts file, then hit Enter:

sudo cp /etc/hosts /etc/hosts.bak

3. Type in the following command to block Facebook, for example:

sudo sh -c ‘echo “0.0.0.0 http://facebook.com” >> /etc/hosts’

4. If you prefer to use a different method, use this command:

sudo sh -c ‘echo “127.0.0.1 http://facebook.com” >> /etc/hosts’

To block a different site, just replace facebook.com in the command.

Read more: Linux G

jim_lynch

Jim Lynch is a technology analyst and online community manager.

Jim has written for many leading industry publications over the years, including ITworld, InfoWorld, CIO, PCMag, ExtremeTech, and numerous others.

Before becoming a writer, Jim started his career as an online community manager. He managed Ziff Davis’ forums on CompuServe and the web including the PCMag and ExtremeTech forums. He’s also done community management gigs with the Family Education Network, Popular Mechanics and MSN Games. Jim still has a passion for well-moderated discussion forums that offer helpful information without a lot of flames, rudeness and noise.

You can visit Jim’s personal blog, view his LinkedIn profile, or send him an email to share your thoughts.

The opinions expressed in this blog are those of Jim Lynch and do not necessarily represent those of IDG Communications, Inc., its parent, subsidiary or affiliated companies.

More from this author