How to install tcpping on Linux

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.

Install tcpping on Linux

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.

Prerequisite #1: tcptraceroute

To install tcptraceroute on Ubuntu or Debian:

$ sudo apt-get install tcptraceroute

To install tcptraceroute on CentOS or RHEL, first set up RepoForge on your system, and then run:

$ sudo yum install tcptraceroute

Prerequisite #2: bc

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 yourself.

To install bc on Debian based Linux:

$ sudo apt-get install bc

To install bc on Red Hat based Linux:

$ sudo yum install bc

Installation of tcpping

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

Use tcpping to Measure Latency

To measure network latency by using tcpping, you can use the following format.

tcpping [-d] [-c] [-r sec] [-x count] ipaddress [port]

Note that you need root privilege to run tcpping as it needs to invoke the privileged tcptraceroute command.

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 157.166.240.13 [open]  82.544 ms
seq 1: tcp response from 157.166.241.10 [open]  80.771 ms
seq 2: tcp response from 157.166.241.11 [open]  80.838 ms
seq 3: tcp response from 157.166.241.10 [open]  80.145 ms
seq 4: tcp response from 157.166.240.11 [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>

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal (Credit Card) or Bitcoin (1M161JGAkz3oaHNvTiPFjNYkeABox8rb4g).

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.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean