问题原文
原帖链接 · jpo234 · CC BY-SA 4.0
I'm dealing with a legacy application that can't be touched. It sends UDP packets to addresses calculated from a client ID (yes, really: its basically something like 192.168.0.x, where x is the client ID, just a bit more complex).
I have a Linux machine running, that forwards the packets from the legacy app to their final destinations. I need to capture these packets in an application, do something (read: encrypt them) and then send the newly encrypted packets to their original destinations. What I have in mind is some kind of iptables magic that changes the destination address of incoming packets so that they get locally delivered, but doesn't touch the outgoing packets. I don't need the original dest address, I can recreate it from the content of the packet. Any suggestions how to do this?
已采纳解答
原帖链接 · Khaled · CC BY-SA 4.0
If all what you need is to redirect the received packets to the local machine, you can add a rule like the following in NAT table:
iptables -t nat -A PREROUTING -s 1.2.3.4 -d 5.6.7.8 -p udp --dport 3333 -j REDIRECT
These numbers (IPs, and port) are just examples. You need to specify your own values, or you can omit them when not needed.
This rule will redirect all received UDP packets originated from IP 1.2.3.4 destined to 5.6.7.8 to port 3333.
You need to have an application listening on this port number to do your processing and then send them to destination (you said you have a way to figure out the destination).
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
