Let's say a website does not have a domain name like www.google.com and the only way to connect to it is to use an IP address like If I add an entry in /etc/hosts that looks likes, will it block connections to that website? Would a web browser be blocked from visiting it too?

Additionally, would this also apply to local addresses like


No. The hosts file doesn't affect any routing. It only affects name lookups. Since is an IP address, the system won't look it up in the hosts table.

Read here for more info on the hosts file: http://manpages.ubuntu.com/manpages/trusty/man5/hosts.5.html

If you want to block connections to an IP address from your system, there are a couple of ways to do that, like:

  1. Blackhole traffic using the route command:

    route add gw lo
  2. Reject traffic using the route command:

    route add -host reject
  3. Null route using the ip command:

    ip route add blackhole

Now, if you want to block traffic to a system by name, you can add a fake entry to your hosts file pointing that name to the loopback address:    badactor.evil.com

Then any traffic trying to get to that host from your system will be faked out – as long as your system is set to use the hosts file lookup prior to DNS. Any specifically DNS based lookups will still work, although you could use a DNSMASQ server like a Pi Hole to block even DNS lookups.

Make sure you read the man pages for the route and ip commands, so you'll understand how to make these commands persistent across reboots if you need them to be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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