How to check network speed between two linux box using command line nc

Netcat is described as being a “feature-rich network debugging and exploration tool”. How to check network speed between two linux box using command line nc. It can be obtained from Source Forge, or it may already be available in your distribution.
To check the netcat installation in your linux, Use below commands.

#which nc 
#/usr/bin/nc

To set up our test, we’ll use two machines, one to listen for a connection, and one to connect and send the data stream. In each test we’ll use a ten second session and we’ll test on three different LANs that differ in speed. The output file will be /dev/null in order to remove the disk from the equation.

Let’s Begin on a 100Mb network segment

On machine A, 192.168.0.8, start netcat as an ordinary user:

#nc -v -v -l -n -p 2222 >/dev/null 
#listening on [any] 2222 …

On machine B, send data to machine A, using the yes command over port 2222, using netcat – timing the session.

#time yes|nc -v -v -n 192.168.0.8 2222 >/dev/null 
#(UNKNOWN) [192.168.0.8] 2222 (?) open

On machine A, notice:

#connect to [192.168.0.8] from (UNKNOWN) [192.168.0.4] 34111


Stop after 10 seconds by typing ctl-c and jot down the time taken:

#sent 87478272, rcvd 0

real 0m9.993s 

user 0m2.075s 
sys 0m0.939s


On machine A, note the data sent (in bytes)

#sent 0, rcvd 87478392


Now multiply the bytes rcvd by 8 to get total bits, then divide by the time: Result is 70Mb/s

Next up – Gb ethernet segment

Machine A

#nc -v -v -l -p 2222 >/dev/null 
#listening on [any] 2222 …

Machine B
#yes|nc cfms5-p 2222 >/dev/null 
punt!
Machine A

#connect to [192.168.1.5] from cfms6-p [192.168.1.6] 33855 
#sent 0, rcvd 1155325952
Result is .9Gb/s

Lastly – a 10Mb ethernet segment




#nc -v -v -l -p 80 > /dev/null 
#listening on [any] 80 
.
.
.
. . . sent 0, rcvd 8437760

Result is 6.7Mb/s

Conclusion

We have seen a handy way to use netcat for testing ethernet throughput. At least we can show that the throughputs are somewhat consistent with their respective LAN segment speeds. I’d be interested in your comments, corrections or spam.

This entry was posted in Computer Networking and tagged . Bookmark the permalink.