Raspberry Pi Ad Blocking & Smokeping Network Monitor

Cromewell

Active Member
Administrator
Messages
249
#1
This is a quick setup guide on how to get PiHole and smokeping running on a raspberry pi. I'm going to assume you have a Pi up and running Raspbian. I used Raspbian Stretch which is based on Debian 9.

PiHole
The PiHole setup is pretty straight forward, and we'll run it first since it comes with a pre-configured lighttpd (webserver) install.

There's really nothing to this one, just run
Code:
curl -sSL https://install.pi-hole.net | bash
and follow the prompts. If you aren't sure on anything, the defaults won't really get you into trouble. Normally it's a bad idea to pipe a script from the internet into bash like this, but you can download the script first and give it a read through first if you are worried.
Code:
wget -O basic-install.sh https://install.pi-hole.net
less basic-install.sh
These commands are pretty straight forward. wget to download the file and save it to the file named in the -O option, and less to view the file. You could use vi, or any other editor if you prefer, or cat, or more, or etc...

If you are satisfied that it is safe, this command will start the installer
Code:
sudo bash basic-install.sh
Once the PiHole install is done, you will be presented with a password, which is what will control web access. If you prefer, you can remove this by running this command and providing a blank password. This is the same method to change the password, so you could set it to some other password that you prefer over the random characters you get by default.
Code:
pihole -a -p
To access the web ui open a broswer and go to http://<pi ip>/admin you should see something like this
1535161235759.png

For the ad-blocking effect of PiHole to work, you also need to configure your machines to use your raspberry pi as a DNS server. I've done this by configuring the DHCP service on my router. This is going to be router specific but in general you want to disable automatic assignment of DNS and enter the IP address of your Raspberry Pi as the primary server. You may want to set the secondary to 8.8.8.8 or OpenDNS if you prefer in the event that your Pi is down.

Smokeping
Again, the basic setup is pretty easy here since there is an apt package for it.

Code:
sudo apt-get install smokeping
This will provide a nearly functional install with a probe called fping. There are a lot of other probes which can be read about at https://oss.oetiker.ch/smokeping/probe/index.en.html. However, you will at a minimum need to configure the targets.

Open /etc/smokeping/config.d/Targets in a text editor. In this file, you will see a skeleton config with a few lines you can modify. A very basic monitoring setup could be
Code:
*** Targets ***
probe = FPing
menu = Top
title = Network Latency Grapher
remark = Welcome to the SmokePing website of xxx Company. \
         Here you will learn all about the latency of our network.
+ Local
menu = Local
title = Local Network

++ Gateway
menu = Local
title = My Gateway
host = 192.168.0.1

+ Internet
menu = Internet
title = Internet Hosts

++ Google
menu = Google DNS
host = 8.8.8.8
As I mentioned, this is very basic and smokeping allows you to do some neat things such as monitor for things like high roundtrip times, or packet loss and automatically send an email when it happens. You can even have it do so only if it persists for long enough. The available options are too numerous to go through and can be read in the full manual at https://oss.oetiker.ch/smokeping/doc/smokeping_config.en.html

Now that smoke ping is installed and configured, give it a restart.
Code:
sudo service smokeping restart
Smokeping suggests Apache as a webserver, but as I mentioned earlier we already have lighttpd installed, so rather than install a second webserver and have to configure one to run on some other port than 80 lets use lighttpd.

First things first, create a symlink in the html directory to the smokeping html install. If you prefer you could move the files, that may require some other edits I did not look into it.
Then we'll also want to use fastcgi, since regular cgi is quite slow and lighttpd has the fastcgi module already installed. To do this, we'll copy the example fcgi script and update it to work.
Code:
sudo ln -s  /usr/share/smokeping/www /var/www/html/smokeping
sudo cp /var/www/html/smokeping/smokeping.fcgi.dist /var/www/html/smokeping/smokeping.fcgi
Now open /var/www/html/smokeping/smokeping.fcgi in a text editor. We need to update the 2 paths to where our install actually is, at the end your file should look like this:
Code:
#!/bin/sh
exec /usr/lib/cgi-bin/smokeping.cgi /etc/smokeping/config
All we are doing here is getting the smokeping cgi script to work off the config file our smokeping install is using.

Now, there is only 1 change left to make. Open /etc/lighttpd/conf-enabled/10-fastcgi.conf in a text editor. We need to add a bit to the end to tell lighttpd how to run the code.
Code:
fastcgi.server += (
  "smokeping.fcgi" => ((
    "socket"   => "/var/run/lighttpd/fcgi.socket",
    "bin-path" => "/usr/share/smokeping/www/smokeping.fcgi"
  ))
)
To access the web ui of smokeping (which is far less pretty than PiHole) open a browser and go to http://<pi ip>/smokeping/smokeping.fcgi
1535161285872.png
 

Cromewell

Active Member
Administrator
Messages
249
#3
It black holes based on DNS names. In stream ads or things served by the site you are on but 3rd party stuff it does pretty well. The anti-ad blockers do nag, there are whitelist options and a global disable to trouble shoot.
 

Cromewell

Active Member
Administrator
Messages
249
#6
For smokeping, you can have it call an external program on alert as well. Just change your 'to' to email and/or start a program. The to item just needs to start with a pipe. Then your program gets called with 5 arguments: name-of-alert, target, loss-pattern, rtt-pattern, hostname. Note, I've not actually tried mixing the email address and script execution, I just use a script.

Code:
*** Alerts ***
 to = me@home.xy,|/usr/local/bin/tweet_my_isp_to_say_they_suck.py
 from = smokealert@company.xy

 +lossdetect
 type = loss
 # in percent
 pattern = ==0%,==0%,==0%,==0%,>20%,>20%,>20%
 comment = suddenly there is packet loss

 +miniloss
 type = loss
 # in percent
 pattern = >0%,*12*,>0%,*12*,>0%
 comment = detected loss 3 times over the last two hours

 +rttdetect
 type = rtt
 # in milliseconds
 pattern = <10,<10,<10,<10,<10,<100,>100,>100,>100
 comment = routing messed up again ?

 +rttbadstart
 type = rtt
 # in milliseconds
 pattern = ==S,==U
 comment = offline at startup
Pi's are pretty cheap. For this, you can use a first gen, no problem. A pi zero should work if you can stomach the wifi :p
 
Top