Operations 5 min read

How to Detect Open UDP Ports with hping3 and netcat (nc)

This guide walks through setting up a Linux server and client, installing hping3 and netcat, and using them to reliably detect whether specific UDP ports are open or closed, including command examples, expected outputs, and troubleshooting tips.

Open Source Linux
Open Source Linux
Open Source Linux
How to Detect Open UDP Ports with hping3 and netcat (nc)

Test Environment

Server OS: Ubuntu 20.04.6; Client OS: CentOS 7; Test tools: hping3 and nc. If the server firewall is enabled, open the required ports or temporarily disable the firewall.

Server Configuration

Check which UDP ports are listening using netstat -ulnp. The server has ports 5353, 37430, and 631 open.

Client Configuration

Install hping3 and nc on the client.

Configure YUM repository from Alibaba:

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

Install the tools:

yum install hping3 nc -y

Testing UDP Ports

Using hping3

Detecting open UDP ports

hping3 --udp 192.168.211.201 -p 5353 -c 4
hping3 --udp 192.168.211.201 -p 37430 -c 4

The client shows 100% packet loss.

Detecting closed UDP ports

hping3 --udp 192.168.211.201 -p 5354 -c 4
hping3 --udp 192.168.211.201 -p 37431 -c 4

The client reports 100% packet loss and an ICMP "Port Unreachable" message.

Summary: If a UDP port responds, there is no message; if it does not, an ICMP Port Unreachable is shown.

Using nc (netcat)

Detecting open UDP ports

nc -vuz 192.168.211.201 5353
nc -vuz 192.168.211.201 37430

When the port is open, nc prints "UDP packet sent successfully".

Detecting closed UDP ports

nc -vuz 192.168.211.201 5354
nc -vuz 192.168.211.201 37431

If the port is not open, nc reports "Connection refused".

Additional one‑liner to check status:

nc -vuz 192.168.211.201 5353 < /dev/null &> /dev/null && echo "online" || echo "offline"
nc -vuz 192.168.211.201 5354 < /dev/null &> /dev/null && echo "online" || echo "offline"

Conclusion

Now you understand how to detect whether a UDP port is open or closed using hping3 and nc; feel free to try these commands yourself.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

network troubleshootingLinuxUDPnetcathping3
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.