Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do you redirect (one way only) udp packets to another host using netcat?

nc -l -u 12345 | nc -u 12345

stops after successfully redirecting the first packet.

(Note: an iptables solution would also be useful.)



share|improve this question

For the iptables solution, you'll basically be doing an destination NAT on the packets. Something like:

iptables -t nat -I PREROUTING -p udp --dport 12345 -j DNAT --to

With netcat, hmm. You can use the -k option to keep the listen side up after you process the packets, but you'll need to do something to keep sending. Named pipes, maybe?

mknod /tmp/nc.pipe p
nc -l -k -u 12345 > /tmp/nc.pipe &

while [1]
  nc -u 12345 < /tmp/nc.pipe

Untested, clearly.

share|improve this answer
up vote 0 down vote accepted

So long as you don't receive more than one message per second, this will forward 99%+ of them.

(It's a really horrible fudge.)

while :
  bash -c "nc -l -u 12345 | nc -u 12345" &
  sleep 1
  kill $!
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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