Today I Learned

A Hashrocket project

Blocking ip6 addresses with /etc/hosts

Like many developers, I need to eliminate distractions to be able to focus. To do that, I block non-development sites using /etc/hosts entries, like this:

Today I learned that this doesn’t block sites that use ip6. I have in my /etc/hosts file but it is not blocked in the browser.

To prove this is an ip6 issue I can use ping and ping6

> ping
PING ( 56 data bytes
64 bytes from icmp_seq=0 ttl=64 time=0.024 ms

> ping6
PING6(56=40+8+8 bytes) 2601:240:c503:87e3:fdee:8b0b:dadf:278e --> 2a04:4e42:200::323
16 bytes from 2a04:4e42:200::323, icmp_seq=0 hlim=57 time=9.288 ms

So for ip4 requests is pinging localhost and not getting a response, which is what I want. For ip6 addresses is hitting an address that is definitely not my machine.

Let’s add another entry to /etc/hosts:


::1 is the simplification of the ip6 loopback address 0:0:0:0:0:0:0:1.

Now, does pinging with ip6 hit my machine?

> ping6
PING6(56=40+8+8 bytes) ::1 --> ::1
16 bytes from ::1, icmp_seq=0 hlim=64 time=0.044 ms

Distractions eliminated.