News for hackers. Stuff that matters.
Re:Adblock via /etc/hosts by sergiotapia on Thursday February 11, 2016 @11:00PM (#11085204)
See, the thing is what if a website is broken due to host files, you can't easily re-enable ads for just this one website you need.

A situation we can all imagine ourselves in: You need to check the google analytics for your website/company site. You can't because it's blocked at Host level.

What solution would there be for this use case?

Re:Adblock via /etc/hosts by laumars on Friday February 12, 2016 @02:26AM (#11085788)
I've been using the hosts file method for years and have never had an issue with checking Google analytics. I use the "Someone who cares" link.

Aside Google sponsored links and the odd ad sponsored link on pseudo-news sites not working (due to them being tracking URLs), I can't see it ever gets in my way.

However to answer your question, these days I run dnsmasq on my home server and have my DHCP server assign that as my primary DNS. So every device (phone, laptop, smart TV, etc) gets their ads blocked as well - which is particularly good for my TV as it's bad enough having regular adverts on TV without LG pushing out sponsored content as well. So if there was a rare occasion that I needed to turn off my ad blocking, I'd just change the DNS to 8.8.8.8 (Google DNS) then switch back to my dnsmasq server once i was done (the only complication being that I sometimes need to close and reopen the browser due to that particular application caching the DNS lookup)

The nice thing about using dnsmasq is that you can import those hosts files verbatim. Which means your update script can be simple.

Re:Adblock via /etc/hosts by pbhjpbhj on Friday February 12, 2016 @04:06AM (#11086047)
I used to block various domains that served TV ads for UK Channel 4, but they hosted the client and that not detect ad loading. Seems you could probably truncate the video stream, maybe o using iptables, but their ad-load has reduced so I'm not motivated to try right now.
Re:Adblock via /etc/hosts by laumars on Friday February 12, 2016 @04:26AM (#11086107)
The weirdest side effect I've had was with the Sky HD box. If it was connected via ethernet then it wouldn't power up while my ad blocking was enabled. I was able to replicate this behavior by enabling and disabling my ad blocking, so my Sky box was definitely phoning home and failing to start if a specific domain was disabled. The weird thing is it would start up fine on WiFi or if the internet was disconnected completely. So I ended up just connecting it to WiFi as my wife was growing impatient by that point!

I did intend to reinvestigate the issue; throw wireshark on a promiscuous NIC and look for what domain Sky was trying to connect to and what data it was sending. I was thinking it might make an interesting article - depending on what I find. But in all honesty I had then forgotten about it until now.

Re:Adblock via /etc/hosts by camillomiller on Friday February 12, 2016 @04:45AM (#11086167)
If you're on a Mac I'd suggest Gasmask. It's a lightweight freeware that lets you switch between multiple hosts files right from the menubar. I have a productivity hosts file I switch on everytime I want to block social media, another one for development purposes and a standard one to revert too in case I don't want any hosts overhead and a clean default file. It's extremely useful.

https://github.com/2ndalpha/gasmask

Re:Adblock via /etc/hosts by flashman on Thursday February 11, 2016 @11:28PM (#11085313)
A situation I've found myself in before: asking our devs why the site is broken, only to find it's my overzealous script blocking.
Re:Adblock via /etc/hosts by iuyoynp on Friday February 12, 2016 @04:09AM (#11086061)
I bet your devs love you for this
Re:Adblock via /etc/hosts by knodi123 on Friday February 12, 2016 @10:31AM (#11087839)
That's not as bad as complaining about the speed of your site, only to realize you're running a torrent on your laptop.
Re:Adblock via /etc/hosts by jakeogh on Thursday February 11, 2016 @11:38PM (#11085346)
https://github.com/jakeogh/dnsgate has a whitelist command for this situation. It's really necessary if you use the block-at-psl[1] config option.

[1] strips domains to the top level that the public can register using https://publicsuffix.org/

It also can quickly "dnsgate disable/enable". (dnsmasq only, quick enable/disable for /etc/hosts is not supported yet, patches appreciated)

Re:Adblock via /etc/hosts by shinnok on Sunday February 14, 2016 @06:29AM (#11097879)
http://shinnok.com/rants/2015/04/05/blocking-ads-and-tracker...

I've been using this simple script on OS X for quite some time now. It works like a charm and is using git for that exact reason, to be able to quickly disable/enable and also keep track of exceptions, changes, etc.

Re:Adblock via /etc/hosts by blt on Friday February 12, 2016 @12:29AM (#11085495)
uMatrix chrome plugin is working well for me
Re:Adblock via /etc/hosts by Scarbutt on Thursday February 11, 2016 @11:20PM (#11085278)
$man mv
Re:Adblock via /etc/hosts by sergiotapia on Thursday February 11, 2016 @11:22PM (#11085287)
You're suggesting renaming the hosts file to something else temporarily? I guess that would work. How quick does the operating system pick up on this change, do I need to reboot my machine for it to reload the Hosts file?
Re:Adblock via /etc/hosts by singlow on Thursday February 11, 2016 @11:26PM (#11085302)
No reboot needed. I have updated my hosts file regularly in linux, windows and macosx without needing a reboot.

Generally your browser will pick it up quickly as well. It doesn't cache host file entries in the same way as dns lookups so the effect of adding or removing is pretty much instant. I use Chrome mostly, so I am not as sure about other browsers.

Re:Adblock via /etc/hosts by Scarbutt on Thursday February 11, 2016 @11:27PM (#11085308)
No need to reboot, as soon as you change the hosts file the OS should immediately start to use the new version, the hosts file is the first thing the OS checks when resolving names, this is what enables this approach to work.
Re:Adblock via /etc/hosts by vacri on Friday February 12, 2016 @12:12AM (#11085457)
It takes immediate effect. I often have a terminal open and toggle commenting out an entry when testing something. As soon as you save it, it's good to go.
Re:Adblock via /etc/hosts by generic_user on Thursday February 11, 2016 @11:51PM (#11085386)
$sudo nscd -i /etc/hosts

also

$man nscd

Re:Adblock via /etc/hosts by johnchristopher on Friday February 12, 2016 @01:20AM (#11085621)
Keep in mind that Firefox has its own DNS cache and that has confused me more than once.
Re:Adblock via /etc/hosts by derFunk on Friday February 12, 2016 @03:19AM (#11085913)
Soe does Chrome. You can clear the internal cache by visiting chrome://net-internals/#dns