Last updated on January 13, 2021 by Dan Nanni
A common way to measure network latency to a remote host is by using
ping utility. The
ping tool relies on ICMP ECHO request and reply packets to measure round-trip delay for a remote host. In some cases, however, ICMP traffic can be blocked by firewalls, which renders the
ping utility useless with hosts behind restrictive firewalls. In such case, you will need to rely on layer-3 measurement tools that use TCP/UDP packets since these layer-3 packets are more likely to bypass common firewall rules.
One such layer-3 measurement tool is
tcpping. To measure latency,
tcpping takes advantage of so-called half-open connection technique, based on TCP three-way handshake. That is, it sends a TCP SYN packet to a remote host on a port number (80 by default). If the remote host is listening on the port, it will respond with TCP ACK packet. Otherwise, it will respond with TCP RST packet. Either way,
tcpping can measure round-trip-time (RTT) delay of a remote host, by timing outgoing SYN packet and incoming ACK (or RST) packet.
The same half-open connection technique is already implemented by
tcptraceroute tool. So
tcpping simply relies on
tcptraceroute to perform latency measurement.
tcpping is implemented as a shell script, and this script replies on external tools to perform and report RTT measurements. Thus, in order to install
tcpping, you first need to install these prerequisites first.
tcptraceroute on Ubuntu or Debian:
$ sudo apt-get install tcptraceroute
tcptraceroute on CentOS or RHEL, first set up RepoForge on your system, and then run:
$ sudo yum install tcptraceroute
Another tool used by
tcpping is GNU
bc, which comes pre-installed on all major Linux distributions. However, if you are running
tcpping in a minimal Linux runtime environment (e.g., Docker container, AWS minimal image AMI),
bc may not be pre-installed. In such case, you need to install
bc on Debian based Linux:
$ sudo apt-get install bc
bc on Red Hat based Linux:
$ sudo yum install bc
After installing these prerequisite tools, finally go ahead and download
tcpping from the official source.
$ wget http://www.vdberg.org/~richard/tcpping $ sudo cp tcpping /usr/bin $ sudo chmod 755 tcpping
tcppingto Measure Latency
To measure network latency by using
tcpping, you can use the following format.
tcpping [-d] [-c] [-r sec] [-x count] ipaddress [port]
-d: print timestamp before each result.
-c: use columned output for easy parsing.
-r: interval in seconds between consecutive probes (1 second by default).
-x: repeat n times (unlimited by default).
[port]: target port (80 by default).
Note that you need root privilege to run
tcpping as it needs to invoke the privileged
For any target web server where port 80 is open, you can measure its RTT delay with
tcpping as follows.
$ sudo tcpping www.cnn.com seq 0: tcp response from 220.127.116.11 [open] 82.544 ms seq 1: tcp response from 18.104.22.168 [open] 80.771 ms seq 2: tcp response from 22.214.171.124 [open] 80.838 ms seq 3: tcp response from 126.96.36.199 [open] 80.145 ms seq 4: tcp response from 188.8.131.52 [open] 86.253 ms
For any arbitrary remote host, you need to make sure port 80 (or any other port) is open before running
tcpping. To check if a remote TCP port is open, you can use
nc command as follows.
$ nc -vn <ip-address> <port-number>
This website is made possible by minimal ads and your gracious donation via PayPal or credit card
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.