I want to generate UDP packet to test a program, something equivalent to using telnet to test TCP port (Can telnet generate UDP packet?)

How can I do this?

5 Answers 5


One word: Netcat

Netcat is the go-to tool for this sort of thing.

You can thrash whatever port you choose with UDP packets with something like:

nc -u host.example.com 53 < /dev/random

(53 is your port number)

Or you can send an actual file, or tell it to bind that port and listen as a service, or whatever you like.


If you want to merely send one UDP packet with some specified data, as opposed to Satanicpuppy's answer which continuously sends random data, you can do:

echo "foo" | nc -w1 -u 111.22.333.4 20000
  • For some reason, it sends a few "X" packets before sending "foo". Using /dev/udp avoid this.
    – OrangeDog
    Jul 21, 2017 at 16:14

This one is good if you are trying to work with large packets. netcat uses 1024 bytes in UDP mode.

nping --udp -p 2090 111.22.333.4 --data-length 1550

UDP mode, to port 2090 at address, with a packet length of 1550 bytes.

This is from the nmap package, or is sometimes packaged as nping separately.

Further info is at https://nmap.org/book/nping-man-general-operation.html


If you're using Bash, you can use its /dev/udp virtual filesystem, like this:

echo -n "hello" >/dev/udp/localhost/8000

Shamelessly re-used from this answer to "How to send only one UDP packet with netcat?"

  • /dev/udp doesn't exist on my Ubuntu 20.04 Kernel 5.4.0-66-generic
    – Alex
    Mar 11, 2021 at 13:45
  • @Alex It's not a real file. It's a trick of Bash. It won't show up with ls or any other program.
    – 9072997
    Jan 18, 2022 at 1:14

You can always use UDP terminal programs. Most of them can also send/receive TCP also. For example Docklight scripting terminal has that possibility. And then you send data same way as you would send it to serial port..

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .