Having UDP messages sent from dynamic public IP periodically to public IP X:20000.
Need a proxy that listens in IP X:20000, then forwards duplicate/clone packets to X:20001 and a different machine located in IP Y:20000. Now, when application listening on X:20001, responds to a message to X:20001, I want that message to be forwarded back to PC A, from X:20000.
How could I achieve this functionality in Linux? (trying to avoid custom script)
Trying to have one application in a headless server responding to messages, and one computer with monitor to debug messages when needed in real time.
I think you could pull this off w/
iptables
and thesamplicator
tool if you're using a new enough kernel to support theraw
table.First, why
socat
won't work: Teeing a packet flow withsocat
is fairly easy. You'd just do this:That duplicates the traffic to
X.X.X.X:20001
andY.Y.Y.Y:20000
.That doesn't help you, though, because the service listening on X.X.X.X:20001 is going to "see" 127.0.0.1 as the source address. That's where
samplicator
can help out. Quoth thesamplicator
Google code page:That sounds like exactly what we need re: the source address. (Having said that, I haven't actually tested this tool. The box I'm testing on doesn't have compilers installed and I'm not going to spin up something right now just for Server Fault. >smile<)
The last thing you'd need is to take care of the traffic coming from
X.X.X.X:20001
, making it appear to come fromX.X.X.X:20000
.Then, to NAT the replies from
X.X.X.X:20001
to "come from"X.X.X.X:20000
:Beware: I haven't tested all of this together. I mocked it up with
socat
and it worked fine minus the source address "spoofing" thatsamplicator
provides.