Benchmarking LAN Network Connectivity in Linux

Mon, Jan 13, 2014

Tweet this!

Netcat between two machines. Image courtesy Kai Hendry.

Occasionally it’s useful to determine the maximum speed of the network connection between two machines. I’ve used the following method on several occasions, generally as a method of troubleshooting. This quick howto will demonstrate a method to test the speed of a connection between two computers, using a very simple mechanism — netcat.

What is netcat?

netcat is a very simple, but incredibly useful, utility that can be used to send or receive data over a network. When executed with the -l

flag, netcat enters listening mode, and can be used to receive data on a specified port. Without the -l flag, netcat will send data to a specified host and port.

Using netcat is simple. If you have two Linux machines, you’ll want to setup one of them to listen, and the other to send. On the machine where you want to listen, execute something like the following:

nc -l 20000

This tells netcat to open port 20,000 and listen for connections. If executed successfully, it will simply sit on the command line and do nothing.

On your second machine, tell it to connect to the machine that is setup to listen. If the first machine has an IP address of, for example, you’d use the following, assuming you set netcat to listen on port 20,000:

nc 20000

If it has connected successfully, it will simply wait on the command line and do nothing. You can test whether or not the connection is working by typing some data into the sending machine, and pressing enter. The text you’ve entered will pop up on the receiving machine. Press control+c to quit netcat.

This simple demonstration shows why netcat can be such a useful tool; all it is actually doing is taking the standard input from one machine and transferring it to the standard output on another. You can use netcat in this way to transfer all sorts of data (although other protocols are more useful for things like typical file transfers).

Testing network throughput with netcat

Once you’ve got the basics down, you can begin testing your network bandwidth with netcat. To do this, we’ll want to have a source of input data that is known to be faster than the network, to make sure we aren’t bottlenecked on the input. The simplest way to guarantee that your input isn’t the bottleneck is to use /dev/zero as the input, which will create data as fast as your processor can stand. We’ll want to make sure the same is true on the receiving end, so we’ll use /dev/null as a destination target. In this way, we can make sure that the only bottleneck in the test is the network.

To get the data into and out of netcat, we’ll use the dd command. Put all together, the listening server should look like this:

nc -l 20000 > /dev/null

And the sending server should look like this:

dd if=/dev/zero | nc 20000

Of course, replace the IP addresses and ports to match your network.

While the test is running, you won’t be able to see any statistics or data transferring. And, as written, the test will run forever; you can limit the amount of data sent by specifying a block size and count for dd, like so:

dd if=/dev/zero bs=1M count=30 | nc 20000

This command will transfer 30MB of data over the network (a blocksize of 1MB, and 30 blocks, is 30MB). Once all data is transferred, you’ll get the output from the dd command, showing throughput:

pi@raspberrypi ~ $ dd if=/dev/zero bs=1M count=30 | nc 20000
30+0 records in
30+0 records out
31457280 bytes (31 MB) copied, 5.40742 s, 5.8 MB/s

Another option for measuring the results is to use a traffic monitoring application such as iftop. You may wish to read How To Monitor Network Traffic in Linux, which provides a nice overview of iftop and similar applications, to learn more about monitoring network traffic.


You can use netcat to easily transfer data over a network, which makes it an incredibly powerful tool. Testing network throughput is just one of its many uses; I encourage you to read more about netcat, as once you know how to use it, you’re certain to find occasion to take advantage of it.

Like this post?

3 Responses to “Benchmarking LAN Network Connectivity in Linux”

  1. lspiehler says:

    This only takes into account the data transferred using dd. It is an interesting method, but doesn’t consider all the data transferred from tcp overhead, not to mention additional overhead from layer 2 and other protocols. The measurement will always reflect a slower speed than you’re actually getting.

  2. meekatron says:

    Thanks for the info. Very good post. I have never used netcat before. I will be bookmarking this page. Could come in useful some day.


  1. Links 16/1/2014: Instructionals | Techrights - 16. Jan, 2014

    […] Benchmarking LAN Network Connectivity in Linux […]

Leave a Reply

Weekly Poll

What's the best Linux distribution for desktops?

View Results

Loading ... Loading ...

Related Posts

Search TechThrob