When trying to figure out why the internet is slow, it can be hard to learn exactly which device on the network is eating up all the bandwidth. Many solutions to this problem require software to be installed on every device to be monitored. Instead, I tried to build a custom Raspberry Pi network monitor.
This post will show you how to monitor all internet traffic for every device on your network, without buying any specialty hardware.This open-source solution has been used by readers of this site for monitoring family internet usage, LAN parties, and more.
This project came about when retrofitting our cabin in the woods to a smart-home. There internet providers out here advertise about 30 Mbps (down) and 2 Mbps (up). This isn’t much to work with. Plus, we have many home-made IOT devices scattered around the house. So… who knows where the traffic is going?
My goal was to not require any special software, yet monitor the internet traffic for every network device.Ideally, I also wanted to create a beautiful Grafana dashboard. This would let me see what sites the devices were contacting with the Raspberry Pi home network monitor.
It seemed like a couple others on Reddit were also interested in a solution to this problem, so I decided to give it a try. The result was an open-source Python script / Docker container, meant to be run on a Raspberry Pi, that exports data to Prometheus. While I used a Raspberry Pi, the code should run on any Linux distribution. There are Docker images for both
Skip to the end of this post for source code & installation.
But first, let’s consider the different ways to monitor traffic on a home network…
Internet Traffic Monitor: Approaches
Based upon experience and some research, these are the possibilities I came up with:
- Pi as a router
The obvious way to monitor network traffic. The Raspberry Pi sits between the devices to be tracked and the internet (e.g., acting as a router or access point). Unfortunately, this can slow down the network, which causes many to avoid the approach (see the next section).
- Router reporting
Some modern routers provide features along these lines. But generally custom firmware is required.
- Device reporting
The standard protocol for this is SNMP, which will rely upon device side installations to self-report. It integrates well with Prometheus/Grafana though.
- Packet sniffing
You could theoretically monitor the wireless traffic (if all you care about is WiFi). This is the same concept that allows attackers to sniff traffic on a WiFi network.
Each of these has its drawbacks. I did not want to buy a new router, so router reporting was not an option. I could not install the necessary software on all the IOT devices, which prevents device reporting. And packet sniffing is an interesting idea, but I wanted to be able to handle wired as well as wireless traffic.
This left only one approach: a Raspberry Pi network monitor.
Raspberry Pi Home Network Monitor
If all internet traffic is going to pass through a device, it is good to use caution.
The first concern is that of security. I won’t say too much about that here, except to mention that a firewall of some kind is a good idea. I went with Uncomplicated Fire Wall (
ufw) because it is, well, uncomplicated.
A less obvious concern is that of speed. When traffic passes through a router/switch, the primary bottleneck is the ethernet hardware. In other words, the CPU and RAM are not as important as in other cases. This was something of a problem with the Raspberry Pi 3B (and lower). However, the Raspberry Pi model 4 has an upgraded on-board 1000 Mbps
Make sure that the ethernet hardware meets the needs.Failure to do so could slow down the entire network!
With that in mind, here is the exact list of parts I used.
If you're new to Raspberry Pi, the popular CanaKits are a great place to start. I prefer to buy the Raspberry Pi 4, power adapter, micro SD cards, and heatsinks separately. Not only is this cheaper, but it reduces e-waste.
The following are affiliate links to other parts I used in this project. I never link to a product that I have not personally used.
With the parts in-hand, I drew up this Raspberry Pi 4 router design:
If you’re using the above parts list…
- The WiFi Router is the Orbi.
- The Switch is the NetGear.
eth1is the USB adapter.
eth0is the built-in interface on the Raspberry Pi 4.
- Short 1ft cat6 cables connect everything together.
Some important points:
- The WiFi router is in Bridge mode. This means that
eth0must act as the DHCP server (assign IP addresses to the network).
- Traffic between devices on the network will not flow through the Raspberry Pi. See the Performance Tests, below.
- This means that the Pi is only a bottleneck for internet traffic. With 1000 Mbps hardware and an ISP that only provides 30 Mbps, we won’t be hitting this limit any time soon.
There are many ways to set up the
eth0 connection. You could configure this using internet bonding software. This would let you add another internet connection (
eth2) to make the internet connection even faster. For a more complete DIY Raspbery Pi router solution: