How do you test the network speed between two boxes?
I use iperf
. It's a client server arrangement in that you run it in server mode at one end and connect to its from another computer on the other side of the network.
One both machines run:
sudo apt-get install iperf
We'll start an iperf
server on one of the machines:
iperf -s
And then on the other computer, tell iperf
to connect as a client:
iperf -c <address of other computer>
On the client machine, you'll see something like this:
oli@bert:~$ iperf -c tim
------------------------------------------------------------
Client connecting to tim, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.0.4 port 37248 connected with 192.168.0.5 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 1.04 GBytes 893 Mbits/sec
Of course, if you're running a firewall on the server machine, you'll need to allow connections on port 5001 or change the port with the -p
flag.
You can do pretty much the same thing with plain old nc
(netcat) if you're that way inclined. On the server machine:
nc -vvlnp 12345 >/dev/null
And the client can pipe a gigabyte of zeros through dd
over the nc
tunnel.
dd if=/dev/zero bs=1M count=1K | nc -vvn 10.10.0.2 12345
As demod:
$ dd if=/dev/zero bs=1M count=1K | nc -vvn 10.10.0.2 12345
Connection to 10.10.0.2 12345 port [tcp/*] succeeded!
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 9.11995 s, 118 MB/s
The timing there is given by dd
but it should be accurate enough as it can only output as fast the pipe will take it. If you're unhappy with that you could wrap the whole thing up in a time
call.
Remember that the result is in megabytes so multiply it by 8 to get a megabits-per-second speed. The demo above is running at 944mbps.
Same as Oli's recommendation for iperf. Just want to add several points:
- There are also windows clients that enables testing across platforms.
-t <seconds>
changes the test length.-P <n>
changes the number of simultaneous connections. For example,iperf -c [target IP] -P 10 -t 30
tests 10 connections together for 30 seconds and gives aggregated results along with 10 separate connection speeds.- You don't need sudo. You can simply download the binary at http://iperf.fr/. It should work. Download it with
wget
, make it executable withchmod
, and you can directly run the binary. It works perfectly.
I found that, using default settings, the single connection speed fluctuates quite a bit. However, with 3+ parallel connections, the results are more consistent on my gigabyte switch. (consistently @ 910-920Mbps)
The command below does not require additional packages but SSH access:
ssh [email protected] 'dd if=/dev/zero bs=1GB count=3 2>/dev/null' | dd of=/dev/null status=progress
Example output:
2992238080 bytes (3.0 GB) copied, 27.010250 s, 111 MB/s
5859375+0 records in
5859375+0 records out
3000000000 bytes (3.0 GB) copied, 27.1943 s, 110 MB/s
The command prints a 3GB (1000^3 bytes) dummy file full of zeros to stdout on the remote server, which is printed (transferred) via SSH to stdout of the local server and then locally piped to /dev/null
(i.e. ignored). You can even see the progress of the test while executing it.
Certainly not as precise as other tools but my use case was to debug a backup process where I wanted to test if network speed was the issue without installing additional packages.