Extremly small tool for UDP redirect


Sometimes you just need a simple tool that works. udp_redirect is a tiny utility for redirecting UDP packets to another destination and sending responses back to the original sender. No iptables, no FIFO files, no pipes, no additional dependencies – just a single C file and a working binary.

I used it to redirect OpenVPN UDP traffic in order to hide the real IP address, and it turned out to be one of the simplest and most reliable solutions for quick UDP forwarding.

The tool listens on a given IP and port, forwards incoming packets to a specified destination, and remembers the sender's address. When a response comes back, it is sent to the original sender. This behavior is very similar to how symmetric NAT works.

There is also an echo mode, where all received packets are sent back to the sender, which is useful for testing and debugging.

The utility was originally used to test VoIP tools by looping RTP ports, but it can be handy in many networking and testing scenarios.

Build


gcc -o udp_redirect udp_redirect.c

Usage


./udp_redirect our-ip our-port send-to-ip send-to-port

Echo mode:


./udp_redirect our-ip our-port

Redirect UDP port 53 to another host:


./udp_redirect 0.0.0.0 53 192.168.0.1 53

Run in echo mode (UDP echo service):


./udp_redirect 0.0.0.0 7

Source code:
https://github.com/justinb01981/tiny-webrtc-gw/blob/master/udp_redirect.c