TCP Ping – How to Ping a TCP Port
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 22.214.171.124): S set, 40 headers + 0 data bytes len=44 ip=126.96.36.199 ttl=47 id=10442 sport=80 flags=SA seq=0 win=5720 rtt=97.7 ms len=44 ip=188.8.131.52 ttl=47 id=40838 sport=80 flags=SA seq=1 win=5720 rtt=97.7 ms len=44 ip=184.108.40.206 ttl=47 id=64607 sport=80 flags=SA seq=2 win=5720 rtt=97.7 ms len=44 ip=220.127.116.11 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).
The hping utility is available on a wide variety of unix and windows operating systems.
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