Skip to content

Restricting website access using /etc/hosts

I've been adding websites that I don't want to have access to to my /etc/hosts file by writing

0.0.0.0 www.websiteIwanttoblock.com. 

For some reason I'm still able to access this particular website. Any help is appreciated thanks.

Edited 15 Aug 2020. We only hold this version.

1 points17 comments
Open on Reddit
About this post
Posted
Archived
Edited
Score
1 · 100% up
Kind
Text
ID
hkccca

Author

7
posts
12
comments
0
media
View profile

18 comments

This is not an appropriate way to restrict access since you're just trying to keep some DNS lookups from being sent up the "chain". I guess you are doing this for parental control reasons? I think you might have a look at your router UI. Most of them got some parental control settings.

4 points

Perhaos a silly question, but are you trying to access exactly what you set to block? E.g. FQDNs with and without "www" are technically different, etc.

3 points
unknown author

Deleted before we saved it.

3 points

If you're using Firefox (perhaps other browsers too), it will cache the DNS lookup. So if you visited that site, then added it to /etc/hosts, then try to visit it again, you'll get there. If you restart Firefox that will solve the problem (if this is your cause).

2 points

Firefox (and some other browsers) are now using DoH (DNS over HTTPS), which bypasses the hosts file, entirely. This is my major complaint about DoH (and others have other valid complaints). By bypassing local security measures, DoH prevents us from configuring our network access the way we want it.

3 points

That's a perfect pain in the arse.

Happily my Firefox is using my own local nameserver which I block Facebook etc with rather than /etc/hosts. Though after checking I can see that I've got DoH disabled; whether I did that myself or it's a default I don't know.

1 points

This not the best way to block sites.

Not all programs will check hosts file.

Better to block on router or a service such as opendns.

1 points

Not all programs will check hosts file.

Technically correct, but irrelevant. Programs use OS-provided mechanisms for looking up IP addresses (e.g. getaddrinfo(3), which invokes glibc's address resolution component, which will take /etc/hosts into account by default).

In the context of simply resolving names to IP addresses, an /etc/hosts entry can be considered a DNS record.

--edit: I shall stand corrected. See the other comment about Firefox using DNS-over-HTTP, which would in fact bypass the local OS's DNS resolution mechanisms.

1 points

As /u/arch_maniac mentioned, Firefox's DNS over HTTPS would override this. Assuming you're using Firefox, check your preferences - it's under Network Settings. Presumably other browsers also have a way to turn this off?

1 points

You could also setup some simple iptable rules like:

iptables -A OUTPUT -d <IPv4 address> -j DROP

And you can find a site's IPv4 address by running ping <website>

0 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.