UDP services exchange individual messages without establishing a connection. Netcat can send a short UDP datagram to a chosen address and port when a listener needs a test payload.

The OpenBSD Netcat implementation available on Ubuntu reads the payload from standard input. A short line is enough to test message delivery, but an application such as a metrics collector may require its own message format before it accepts the data.

UDP provides no delivery acknowledgement, so a sender that exits without an error does not prove that a datagram arrived. A local listener makes the received payload visible, while a remote service needs confirmation from its own logs or response.

Steps to send a UDP datagram with Netcat:

  1. Start a UDP listener on loopback port 53000 in the first terminal.

    The loopback address keeps this temporary listener accessible only from the same host. UDP payloads are unencrypted, so sensitive data does not belong in a network test.

    $ nc -u -l 127.0.0.1 53000

    The listener stays open with no output until data arrives. An occupied port produces an error instead; another unused port must match at both ends.
    Related: How to create a UDP listener with Netcat

  2. Send the payload from a second terminal on the same host.
    $ printf 'metric=42\n' | nc -u -w 1 127.0.0.1 53000

    The pipe supplies the payload to nc, -u selects UDP, and -w 1 returns the sender to the shell after one second of inactivity. No sender output is expected. For an existing receiver, the address, port, and payload must match that service.

  3. Confirm that the first terminal displays the exact payload sent by the second terminal.
    metric=42

    The received line confirms delivery to the local listener. An empty receiver does not confirm delivery, even if the sender reported no error; nc -uz is also insufficient to prove that a UDP service is listening. Ctrl-C stops the temporary listener when the test is finished.

Share this guide