HowTo: Raspberry Pi ad-blocking, caching router and internet gateway

This past week, during a transition between internet accounts from the same provider ( gotta love monopolies! ), I setup a rasberrypi b+ as a temporary router using a 4g cellular hotspot as our primary internet connection.

The maximum data plan available through t-mobile provided only 21GB of data for $120 a month. At 4g LTE speeds, ~50Mbps, you can burn through 21GB in just about an hour.

Clearly, we needed to figure out ways to conserve bandwidth, particularly for an office of 6-8 people all sharing the same connection.

Enter Privoxy, Polipo, Dnsmasq, and some iptables magic.

So, first off, I’m assuming you’ve got the latest Raspbian installed. This was built on the 2014-12-24 release.

So, lets add the usb0 network interface and set it to get an ip address via DHCP.

Next, lets go get all the software we’ll need to get this done:

Avahi is just because I don’t like to type IP addresses…

Next up is /etc/dnsmasq.conf for providing dhcp service for our network:

Then Privoxy

Next, we’ve got polipo, our lightweight caching proxy: /etc/polipo/config

I’d reboot at this moment, to make sure everything comes up roses, plug in your android phone or hotspot setup to do USB tethering.

Then, finally, the iptables rules that do that magic:

Now, you should have your ethernet port serving up IP addresses to your lan, routing all traffic through privoxy and polipo to cache, and serving dns requests locally to your caching dns proxy.

Nota Bene: Should work with iPhones, but you’ll need to install some extra tools and configuration.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.