0

I am trying to block certain sites from my computer (namely, reddit) in order to get some work done. However, modifying the /etc/hosts file seems to have no effect. I am working under Ubuntu 18.04

Here is the content of my /etc/hosts

127.0.0.1       localhost
127.0.1.1       MY_COMPUTER_NAME
127.0.0.1 reddit.com 
127.0.0.1 www.reddit.com
127.0.0.1 np.reddit.com

The following lines are desirable for IPv6 capable hosts

::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters

I would expect this file to block all my connection attempts to www.reddit.com But even after rebooting the computer/browser, my browser can still access reddit normally when I type www.reddit.com in the address bar.

It seems I cannot manage to make the /etc/hosts file work. There is no website that I have managed to block yet (it's not just a reddit thing)

How can I block access to a website from my computer using /etc/hosts ? How can I assert if my /etc/hosts file is working properly ?

When I try to ping the website, here is what happens :

ping -c5 www.reddit.com
PING www.reddit.com (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.034 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.042 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.054 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.043 ms
64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.054 ms

I am using Firefox, it turns out it was the problem : Firefox does NOT use /etc/hosts by default.

WNG
  • 340

1 Answers1

0

Thanks to Karnil's comment, I was able to find the relevant comment [here] (https://unix.stackexchange.com/questions/499792/how-do-etc-hosts-and-dns-work-together-to-resolve-hostnames-to-ip-addresses)

Namely, the following comment :

Beware that many Web browsers implement their own DNS servers and DNS cache and do not consult any name-lookup mechanisms that have been configured on the system. In other words, some Web browsers completely ignore /etc/hosts and the locally-defined name servers. It's quite confusing to witness the first time around. (Looking at you, Chromium-based browsers!)

It's the case of Firefox. I used the response provided here, which is to change the network.dns.offline-localhost to false in about:config

Additionnally, the procedure described here (disable "DNS over https") was necessary for my Firefox to honor the /etc/hosts file. It seems to be a rather recent evolution from Firefox

WNG
  • 340