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.
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.repoInstall the tools:
yum install hping3 nc -yTesting 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 4The 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 4The 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 37430When 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 37431If 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
