TCP Ping โ€“ How to Ping a TCP Port

Tags: , , , , , , , , ,

Overview

Ping is an extremely useful utility for troubleshooting network connectivity. However, on todayโ€™s networks, icmp pings are often discarded. And with the prevalence of firewalls and load balancers it is often necessary to test the availability and response time of a particular port anyway. In this article we will use the hping utility to perform a tcp ping (ping a tcp port).

Running the TCP Ping

Hping is a network packet crafting utility. It is extremely flexible. This article only scratches the surface of what it can do.

In this example we will tcp ping a web server on tcp port 80 (-p 80) by sending it a SYN (-S) packet.

$ hping -S -p 80 google.com
HPING google.com (eth0 66.249.92.104): S set, 40 headers + 0 data bytes
len=44 ip=66.249.92.104 ttl=47 id=10442 sport=80 flags=SA seq=0 win=5720 rtt=97.7 ms
len=44 ip=66.249.92.104 ttl=47 id=40838 sport=80 flags=SA seq=1 win=5720 rtt=97.7 ms
len=44 ip=66.249.92.104 ttl=47 id=64607 sport=80 flags=SA seq=2 win=5720 rtt=97.7 ms
len=44 ip=66.249.92.104 ttl=47 id=10443 sport=80 flags=SA seq=3 win=5720 rtt=97.7 ms
^C
--- google.com hping statistic ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 97.7/97.7/97.7 ms

Look familiar? The output is formatted very similarly to ping. In fact hping can perform traditional icmp echo pings as well by using the โ€œ-1โ€ switch.

This utility has been immensely helpful in troubleshooting and documenting performance problems and testing the capabilities of firewalls. Itโ€™s also very useful for detecting when sshd comes back up after a system reboot (hint: -p 22).

More information

The hping utility is available on a wide variety of unix and windows operating systems.

Hping on Mac OSX is available using homebrew: http://brewformulas.org/Hping

Hping on RedHat compatible Linux distributions is available from EPEL

Hping on debian/ubuntu is available through apt.

Hping on windows is available from the hping download site http://www.hping.org/download.html