I noticed a strange behaviour working with netcat and UDP. I start an instance (instance 1) of netcat that listens on a UDP port:
nc -lu -p 10000
So i launch another instance of netcat (instance 2) and try to send datagrams to my process:
nc -u 127.0.0.1 10000
I see the datagrams. But if i close instance 2 and relaunch again netcat (instance 3):
nc -u 127.0.0.1 10000
i can't see datagrams on instance 1's terminal. Obsiously the operating system assigns a different UDP source port at the instance 3 respect to instance 2 and the problem is there: if i use the same instance'2 source port (example 50000):
nc -u -p 50000 127.0.0.1 10000
again the instance 1 of netcat receives the datagrams. UDP is a connection less protocol so, why? Is this a standard netcat behaviour?
nc
should listen on. And you can't use-l
(listen) and-p
(specify source port) together. If you're listening, you can't control the source. – Tacyenc -lu 10000
won't run. – Eton-p
? Or does it use it as the port it listens on? – Tacyenetstat -an | grep 10000
:udp 0 0 0.0.0.0:10000 0.0.0.0:*
– Etonnc
implementations (Wikipedia), including Hobbit's Netcat (netcat-traditional
in Debian;-p
required when listening), OpenBSD Netcat (netcat-openbsd
in Debian;-p
optional when listening) and GNU Netcat (not in Debian; without-p
, listen port is random). Usenc -h
to identify which one you're using. – Colettecoleus