Thomas' Tech Tips

Poor man's iperf using netcat

10 December 2022 - Thomas Damgaard

Today we will learn how to measure network throughput between two Linux machines using netcat.

Normally, you would use iperf for this, but if iperf is not available, we can emulate it using netcat.

On the server, run:

$ nc -l 5000 > /dev/null

On the client, run:

$ head -c 1G /dev/zero | time nc 10.0.0.50 5000
nc 10.0.0.50 5000  3,45s user 17,03s system 52% cpu 39,225 total

So it took ~40 seconds to transfer 1 GB zeros. That comes to 1024 MB / 40 seconds = 25,6 MB/s.

If we have pv available, we can use that to do the calculation for us.

On the server, run:

$ nc -l 5000 > /dev/null

On the client run:

$ head -c 1G /dev/zero | pv | time nc 10.0.0.50 5000
1,00GiB 0:00:42 [24,2MiB/s]
nc 10.0.0.50 5000  2,69s user 16,63s system 45% cpu 42,382 total
Filed under: linux, netcat, network, tips

Back to article list