How to check whether UDP connection is open or not?

UDP is being a connectionless protocol, you can t reliably say that the port is open or not. Below two commands are the only way of checking the same. When you send a packet to the open port, there need not be any acknowledgment saying that the port is open.

Theoretically, UDP should give a ICMP REJECT message saying “port unreachable”, but it can also drop the message as if its a black hole.

nmap -sU -p UN4500 xx.xx.xx.xx 

nc -vz -u xx.xx.xx.xx 53

Using nmap and netcat tool would be of help, but let me repeat that this is not reliable. However, if you want to check whether the port is blocked at a hardware level either at client end or the server end, what you can probably do is to open a UDP port at the server end like below: # nc -u -l 4500

And then at the client side, open the communication using nc as below and write some message and check whether it is reaching at the server end. # nc -u 4500

On a quick note, to check whether a port is open, programmatically/script, use the below command:

nc 22 &> /dev/null; echo $?

If $? is 0, the port is open and if 1, the port is closed.

Powered by BetterDocs