大网数据广告活动
服务器运维问答

Need to capture UDP packets on a Linux router, modify them and send them to the original destination

· 52CE 我爱测

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)…

问题原文

原帖链接 · 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).

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-02-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。