Skip to content

Instantly share code, notes, and snippets.

@draobrehtom
Last active September 21, 2019 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save draobrehtom/8bb6e4c1e8015db196960f6fde88c7b0 to your computer and use it in GitHub Desktop.
Save draobrehtom/8bb6e4c1e8015db196960f6fde88c7b0 to your computer and use it in GitHub Desktop.
TCP and UDP ports redirection

UDP redirection:

https://unix.stackexchange.com/questions/205959/how-can-i-redirect-all-udp-traffic-from-one-port-to-another-on-bsd-os-x/207595#207595?newreg=fed9c03544f84687a9299f26752b21e2

TCP redirection:

https://serverfault.com/questions/238563/can-i-use-ufw-to-setup-a-port-forward

@draobrehtom
Copy link
Author

Download a very small c program source file called: udp_redirect (click here to download it)
Compile it with gcc -w udp_redirect.c -o udp_redirect
Run it in background sudo ./udp_redirect 127.0.0.1 20 127.0.0.1 29 &
Set up a listener on port 29 to test it sudo nc -ul 29
On a second terminal, test it with echo “this is a test” | sudo nc -4u -w1 localhost 20

@draobrehtom
Copy link
Author

tcpdump -i lo udp port 8125 -w data.pcap
echo -n "blah:36|c" | nc -w 1 -u -4 localhost 8125

@draobrehtom
Copy link
Author

Replaying:
tcpreplay -i lo -K --mbps 10000 data.pcap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment