
Show HN: Hostsctl – Control /etc/hosts easily, block ads, social networks, etc - 0xl3vi
https://github.com/0xl3vi/hostsctl
======
whacker
I think (on linux, at least), its better to implement this as a nss- module
(/etc/nsswitch.conf). You can do things like lookup a hashtable, automatically
update databases, etc without having to rewrite system config files.

Also this does not protect you from programs that perform their own dns
lookups, and ignore /etc/hosts and /etc/resolv.conf entirely!

~~~
StavrosK
What's the advantage of that? How does it protect you against programs that
perform their own lookups?

~~~
whacker
oh nss modules wouldn't either. Perhaps intercepting and rewriting every dns
request would be needed.

------
colemannugent
I would reccomend PiHole [1] for something like this.

Not only is it more robust, it acts as a DNS/HTTP server that blocks this kind
of stuff on a whole network.

1: [https://github.com/pi-hole/pi-hole](https://github.com/pi-hole/pi-hole)

~~~
StreamBright
This is pretty cool, I was not aware of this project, thanks for sharing.

------
git-pull
I like this and could use something like it, but you should use POSIX sh
(/bin/sh) and not rely on Bash in the shebang as well as non-portable
functionality it introduces.

This wouldn't work out of the box on FreeBSD.

I recommend this tool:
[https://www.shellcheck.net/](https://www.shellcheck.net/)

------
matheweis
Related discussion from several years ago:
[https://news.ycombinator.com/item?id=5264405](https://news.ycombinator.com/item?id=5264405)

------
tyingq
Interesting in the demo that pings to 127.0.0.1 fail. Is that a common setup
for some distribution to block icmp on the localhost if?

~~~
pwdisswordfish
Why resolve blocked domains to 127.0.0.1 anyway? Wouldn't 0.0.0.1 work better?

~~~
HenryBemis
My thought exactly. I send to 0.0.0.0 instead of 127.0.0.1.

Also, my go to site for hosts is:
[http://someonewhocares.org/hosts/](http://someonewhocares.org/hosts/)

and I am more than happy to share that on Windows/Firefox I use a combo of
AdBlock+ and NoScript so I only allow FB, and the other "socials" to run their
crap ONLY on their own websites and not on others (e.g. the -tracking- "like"
buttons on CNN)

~~~
simplehuman
0.0.0.0 is not a valid host ip

------
herbst
How about the performance? Big host files AFAIK perform rather bad

~~~
0xl3vi
With AWK? did you tesed this? we are not using sed(1).

~~~
herbst
no with the host file in general. I did this once (a while ago) and i did
notice a difference in website loading speed when i put 1000 lines into that
thing

------
theamk
One caveat: all your custom enabled/disabled hosts disappear after "update"
command.

~~~
0xl3vi
WIP

------
nopit
Use dnsmasq and then you can wildcard the subdomains

------
gbraad
Hostctl => as sinkholectl

