How to Install and Use hping3 in Linux for Advanced Network Testing, Port Scanning, and Firewall Auditing

Standard network diagnostic utilities like ping rely exclusively on ICMP echo requests, which modern firewalls and enterprise cloud security groups frequently drop by default. When validating network routing, firewall packet filtering rules, or diagnosing maximum transmission unit (MTU) fragmentation, security engineers and system administrators turn to hping3. As a command-line TCP/IP packet assembler and analyser, hping3 allows you to craft custom TCP, UDP, and RAW-IP packets with granular control over flags, ports, and payload sizes.

Why Use hping3 Over Standard Diagnostic Tools?

Unlike basic ping utilities, hping3 provides total control over every field in the IP and TCP headers. You can test whether a remote firewall correctly blocks incoming SYN packets while permitting established sessions (ACK mode), identify hidden ports across stateful firewalls, measure network latency across specific TCP application ports (such as 443 or 80), and trace network paths through firewalls using custom TCP traceroute modes.

Installation Instructions

On Ubuntu and Debian

sudo apt update
sudo apt install hping3

On Fedora, RHEL, and Rocky Linux

sudo dnf install epel-release -y
sudo dnf install hping3 -y

On Arch Linux

sudo pacman -S hping3

Step-by-Step Practical Examples

Step 1: Testing Connectivity with Custom TCP SYN Packets

To test whether a remote web server is accepting connections on HTTPS (port 443) when ICMP ping is blocked:

sudo hping3 -S -p 443 -c 4 example.com
  • -S: Sets the TCP SYN flag.
  • -p 443: Targets destination TCP port 443.
  • -c 4: Sends exactly 4 packets and exits.

A responding server returns flags=SA (SYN-ACK), proving the port is open and reachable.

Step 2: Performing a TCP Traceroute Through Firewalls

Standard traceroute uses UDP or ICMP, which are often dropped at perimeter routers. To route packets to port 80 using TCP SYN flags while incrementing TTL (Time to Live):

sudo hping3 -S -p 80 --traceroute -V example.com

Step 3: Auditing Firewall Rules with ACK Packets

To test whether a firewall is stateful or stateless, send raw TCP ACK packets without prior handshake:

sudo hping3 -A -p 80 -c 3 example.com

A stateful firewall will silently drop the unsolicited ACK, whereas an unprotected host or stateless filter will return an RST (Reset) packet.

Step 4: Discovering Path MTU Without Fragmentation

To determine the exact maximum packet size a network path can support without IP fragmentation, set the Don’t Fragment (DF) flag and test payload sizes:

sudo hping3 -1 --df -d 1472 -c 2 example.com
  • -1: Specifies ICMP mode.
  • --df: Sets the Don’t Fragment bit in the IP header.
  • -d 1472: Sets the data payload size (1472 bytes + 28 bytes header = 1500 byte standard MTU).

hping3 Operational Flags Comparison

Flag Protocol / Behaviour Network Layer Target TCP Flags Security Testing Application
-0 RAW IP Network Layer None Testing custom IP protocol headers
-1 ICMP Network Layer None Subnet ping sweeps and MTU discovery
-2 UDP Transport Layer None Testing DNS and VoIP gateway reachability
-S TCP SYN Transport Layer SYN Testing open service ports and TCP handshakes
-A TCP ACK Transport Layer ACK Auditing stateful firewall rule enforcement
-F -P -U XMAS Scan Transport Layer FIN, PSH, URG Testing RFC 793 compliance in firewalls and IDS

Security Considerations and Best Practices

  • Elevated Privileges: Assembling raw IP sockets requires superuser permissions. Always run hping3 using sudo.
  • Authorised Networks Only: Using packet manipulation utilities against networks you do not own or possess explicit testing authorization for can trigger intrusion detection systems (IDS) and violate terms of service.
  • Flooding Safeguards: hping3 includes high-speed flood modes (--flood). Never execute flood flags in production environments, as they can saturate network interfaces and cause unintended service denial.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.