Measuring network speed with iperf3

Radu Zaharia

--

Photo by Maico Amorim on Unsplash

We looked earlier at diagnosing network connectivity and exploring network connections. Today we will continue to put our network under the microscope, this time looking at transfer speeds.

When talking about network speed we have to consider two things: internal network speed and Internet speed. The internal network speed is what you get when transferring files from your home server to your laptop: for example when you listen to local music or browse files on your network shares. The Internet speed is the speed with which you transfer files from the Internet.

Why are these two different? Your home network has speed restrictions linked to the network hardware you have in place. Usually the WiFi router is the main offender here, but the laptop may drag the speed down if it’s older and even the network cables if they are incompatible with higher speeds. Then of course, there’s WiFi. It’s no use to have a 10 Gbit/s router, a 10 Gbit/s supporting laptop and 10 Gbit/s network cables if you are using 300 Mbit/s WiFi. And that’s not all: the WiFi coverage also counts. It’s no use to have a 600 Mbit/s WiFi router and 600 Mbit/s supporting laptop if the WiFi signal is barely reaching.

The Internet speed restriction is the one you pay for in your Internet contract. Of course there will be variations of the advertised speed but there’s not much you can do about it. I find measuring Internet speed less profitable this way. Yes, it’s nice to know that you can use the advertised Internet speed but it is well known that you only get a fraction of it. The least you can do is arrange your network in such a way to get all that your ISP gives you: get a better router, provide better WiFi coverage or even go back to plain UTP cables.

Getting a fair measure of your Internet speed

Photo by Chris Liverani on Unsplash

We can measure the Internet speed using iperf3. We just install it and run:

#iperf3 -c speed.as208196.net

The given URL is for a public iperf3 server: you can find more online, even straight at the iperf3 web site, and the -c parameter configures iperf3 to run as a client, meaning we run it to check the network speed on the current device. So basically we are testing the Internet speed on our current device, using speed.as208196.net as a test server. We will transfer information from there to our device and back. The result? Useless:

Output of our iperf3 test

The test result shows 19 Mbit/s download and 16 Mbit/s upload. Why such slow speeds? Well what you don’t see here is that my WiFi signal is very poor, so the benchmark here is not really about the Internet, but about my network. So how do we measure the actual Internet speed? First of all, I should have better WiFi coverage:

Speed result with better WiFi coverage

Ok, 200 Mbit/s this time, but is this right? No, because what I am measuring again is really the WiFi speed, the internal network performance. And my WiFi connection runs at 300 Mbit/s. So how do we measure the Internet speed then? WiFi is not the best medium to do this test. Let’s switch to cable:

Different PC, linked straight to router

That’s better. This is close to what my ISP advertises. So as a lesson, when benchmarking the Internet speed, always go as close as possible to the ISP’s router and always use cable. Otherwise you will simply test bottlenecks in your internal network.

Of course, in the end the bottlenecks matter most because they give your final, net speed. Even though your ISP gives you optical fiber Internet with gigabyte per second speeds, if your home network is slow, so will be the final Internet speed. But to make a proper diagnosis of your network speed, you have to get the numbers right. You have to rule out offenders. And in my case, the ISP is not the offender, my poor WiFi is.

Measuring internal network speed

Photo by Scott Webb on Unsplash

We already had a glimpse into the home network speed, but we want to be more accurate. To see the speed at which your local network is running, you need a test server. In my case, I have my Raspberry PI home server which is wired to a router, so I will use that.

We login to the home server and install iperf3. Now we have two options: run iperf3 as a server for a single test, or install iperf3 as a service to make speed tests whenever we want. For the fist option, we simply run:

#iperf3 -s

And leave iperf3 running. Next, on another network device we run:

#iperf3 -c 192.168.68.116

The IP this time is for our Raspberry PI home server. And here is the result:

Measuring local network speed

You can see in the screenshot above the two terminal tabs: one is my SSH session to my local Raspberry PI server, and the active tab is for the client showing the test results: almost 400 Mbit/s. Not bad for WiFi.

Of course, I could test this speed on multiple devices in my network but to be fair, in WiFi scenarios the only limiting factor is the signal strength. You will usually cap at around 300 Mbit/s.

If you want to make iperf3 a service so you have it running on the home server all the time, you need to make a systemd unit:

#sudo nano /etc/systemd/system/iperf3.service

And copy the following (available on github):

[Unit]
Description=Network speed test server
After=syslog.target network.target auditd.service
[Service]
ExecStart=/usr/bin/iperf3 -s
[Install]
WantedBy=multi-user.target

Save it and then run:

#sudo systemctl enable iperf3
#sudo systemctl start iperf3

And you are done, you have your own network speed test server you can call whenever you want.

Automating speed tests

Photo by Eric Rothermel on Unsplash

If you want to run network speed tests automatically, you will need an iperf3 service always running on your home server, as configured above. Then, on all the clients you wish to participate in the network speed test, you need to create a systemd timer that will run iperf3 on a given schedule. A systemd timer has two components: a service specifying what to run and a timer specifying when to run it. Let’s create the service first. Again, you should do this on all participating clients:

#sudo nano /etc/systemd/system/iperf3-client.service

And then paste this inside (available on github):

[Unit]
Description=Automated network speed test client
After=syslog.target network.target auditd.service
[Service]
ExecStart=/usr/bin/iperf3 -c 192.168.68.116
[Install]
WantedBy=multi-user.target

Note the IP address to match your iperf3 server. You can also use a public Internet iperf3 server if you wish to test the Internet speed.

Next, we will create the systemd timer:

#sudo nano /etc/systemd/system/iperf3-client.timer

And we will paste this (available on github):

[Unit]
Description=Run iperf3-client.service weekly and on boot

[Timer]
OnBootSec=15min
OnUnitActiveSec=1w

[Install]
WantedBy=timers.target

The above will configure a timer that will run iperf3 every time you boot your device after 15 minutes. It will also run it weekly if no reboot is happening. Now we simply enable the timer:

#sudo systemctl enable iperf3-client.timer
#sudo systemctl start iperf3-client.timer

Speed tests provide another useful metric for your network and it should become a habit to do them from time to time. You can even automate this test and since iperf3 logs the results, you can compare them and see changes in time. Combined with ss and mtr, this will allow you to know your network better and give precise diagnostics when something goes wrong.

In the future we will talk about fail2ban which is able to read logs automatically and act upon strange discoveries. Until then, see you in the next article!

--

--

No responses yet

Write a response