Mon coin de toile - A piece of Web

Using Instead of in /etc/hosts

Posted: Nov 22, 2023
Using Instead of in /etc/hosts

TL;DR: The /etc/hosts file in Unix-like systems maps hostnames to IP addresses for manual overrides or blocking websites. Using for blocking is more efficient than, as it leads to immediate connection failure without involving a round-trip to the local machine.

The /etc/hosts file in Unix and Unix-like operating systems, like Linux and macOS, is used to map hostnames to IP addresses.

Prior to the widespread adoption of domain name systems (DNS), it was the primary method for mapping hostnames to their corresponding IP addresses. In modern usage, it often complements DNS, allowing for manual overrides, local domain definitions, or for blocking unwanted sites by redirecting them to addresses like or

While both and achieves the same result (blocking the website), they have in fact specific uses:

Using in your /etc/hosts file for blocking unwanted domains can be faster compared to using

Indeed when you map a domain to, it effectively tells your system that the address is invalid. This results in an immediate failure of any network requests to that domain, as the system recognizes that it’s an invalid address and rejects the connection immediately. There’s no attempt to establish a connection.

This bypasses the potential delay caused by the network stack trying to establish a connection to Indeed if there’s a server running on your machine that listens to the requested port, it will respond – typically with an error if the request doesn’t correspond to an actual service. This can take slightly longer because it involves a round-trip to your own machine and waiting for a response.

In practical terms, the speed difference is usually minimal, but is slightly more efficient for blocking domains and a such this is what I use when I need it.