So I can use this netcat command to check if a UDP port is open:

$  nc -vz -u 53
Connection to 53 port [udp/domain] succeeded!

Unlike TCP, UDP is connectionless (fire and forget). So at a high level does anyone know how netcat knows the UDP port is open? Does it ask for a reply or something like that?

4 Answers 4


In fact, it doesn't. You can check by doing:

$ nc -vz -u 53 
Connection to 53 port [udp/domain] succeeded!
$ nc -vz -u 54
Connection to 54 port [udp/*] succeeded!
$ nc -vz -u 59
Connection to 59 port [udp/*] succeeded!

So with UDP, it's not something you can really check unless it will give you information back.


Judging by the specific output Connection to Connection to 53 port [udp/domain] succeeded! you are using openbsd-netcat.

Looking at the code for that the test is to bind to the UDP socket, i.e. there is an open connection:

              if (vflag || zflag) {
                            /* For UDP, make sure we are connected. */
                            if (uflag) {
                                    if (udptest(s) == -1) {
                                            ret = 1;

                            /* Don't look up port if -n. */
                            if (nflag)
                                    sv = NULL;
                            else {
                                    sv = getservbyport(
                                        uflag ? "udp" : "tcp");

                                "Connection to %s %s port [%s/%s] "
                                "succeeded!\n", host, portlist[i],
                                uflag ? "udp" : "tcp",
                                sv ? sv->s_name : "*");

udptest issues around 3 writes to the open socket. There is a note that this doesn't work for IPv6 and fails after around 100 ports checked.

So while the other suggestion may be valid, I don't think that's happening in this particular case.

  • so udptest is the function I am looking for and it answers my question. From the link you provided "* udptest() * Do a few writes to see if the UDP port is there" Oct 13, 2015 at 15:11
  • Yes, I just checked that and saw the writes as well. Revised answer.
    – rocky
    Oct 13, 2015 at 15:13
  • 2
    @PatrickMcMahon - if this answers your question, then accept it by clicking on the large tick.
    – cas
    Oct 14, 2015 at 0:29

Well I have different opinion:

a:~# nc -luk 667 // listen on UDP port 667
b:~# nc -uv 667  // check if port is open 
nc: ( 667 [667] open
I love stackexchange // send a message
a:~# nc -luk 667
I love stackexchange // receive the message.

So based on that, you can check if the connection between a and b on that udp port is possible. Later on you can continue checking using tcpdump.

  • 1
    Ah yes I like this. Its a good way to test if you have access to both nodes. I guess when I was asking the question I was steering towards "how to test a black box" or probing an external node. The results of doing just that, netcat cannot guarantee. Jun 14, 2017 at 15:58
  • Could you please expand on the IP address ? Why is it used on both computers? Jun 18, 2018 at 17:22
  • -k option is not necessary when you are dealing with UDP
    – YON
    Nov 13, 2019 at 6:27

There is an ICMP message to signalize that a port, even an UDP one, is closed. So if a host sends this message then the port can be assumed to be closed.


  • 4
    Note that because UDP is connectionless, you cannot reliably distinguish an open port from a firewalled port from a lost packet.
    – Mark
    Oct 13, 2015 at 23:06
  • Very true. And theoretically it would also be possible that you get the packet and the port is not really closed.
    – phk
    Oct 13, 2015 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.