A common way to measure network latency to a remote host is by using ping utility which uses ICMP echo request and reply packets. In some cases, however, ICMP traffic is blocked by firewalls, which renders 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.
In order to install tcpping on Linux, you first need to install tcptraceroute, and then download tcpping script from the web.
To install tcptraceroute on Debian/Ubuntu:
To install tcptraceroute on CentOS/REHL, first set up RepoForge on your system, and then:
Finally, download tcpping from the web.
$ sudo wget http://www.vdberg.org/~richard/tcpping
$ sudo chmod 755 tcpping
To measure network latency by using tcpping, simply run it as follows.
seq 0: tcp response from 18.104.22.168 [open] 82.544 ms
seq 1: tcp response from 22.214.171.124 [open] 80.771 ms
seq 2: tcp response from 126.96.36.199 [open] 80.838 ms
seq 3: tcp response from 188.8.131.52 [open] 80.145 ms
seq 4: tcp response from 184.108.40.206 [open] 86.253 ms
Subscribe to Xmodulo
Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!