socat:如何通过UDP创建双向IP隧道
我想解决以下问题:假设我有两台计算机,A和B。
机器A从一个接口(我假设是一个“tun”接口”)获取所有IP数据包,将其发送到Java进程(这可能会修改数据),并使用 UDP 将其发送到机器 B。在机器 B 上,内容被再次提取并发送到接口。
例如,在机器 A 上,我会输入 ping B
命令, Java 进程(包括IP 标头),使用 UDP 发送到机器 B,发送到一个接口,然后通过同一隧道将回复发送回我不能只使用 socat
,因为我想做点什么。 数据
我尝试的是(假设在机器 A 上):
socat -u tun:123.123.123.123/24,iff-up,iff-no-pi udp:localhost:1234 &
socat -u udp-listen:1236 interface:tun0 &
所有流量(例如 ping 请求)都发送到端口 1234 上的本地 UDP 套接字。我的 Java 进程从该端口接收 ,并将其发送到机器B、上机到本地端口 1236。看起来 tun0 接口正确接收到 ping 问题是两台机器之间的数据包循环,可能是因为第二个 socat
命令将数据包发送到 tun0,然后是第一个命令。 turn 会将数据包发送回 Java 等。
您是否知道如何通过 Java 在 UDP 中建立 IP 隧道而不出现此问题?
I would like to solve the following problem: Assume I have two computers, A and B.
Machine A takes all IP packets from an interface (I assume a "tun" interface"), sends it to a Java process (which may modify the data), and which sends it to machine B using UDP. On machine B, the content is extracted again and sent to an interface.
For example, on machine A, I would type a ping B
command, the ping request would then be received the the Java process (inclusive IP headers), sent to machine B using UDP, sent to an interface, which would then send the reply back through the same tunnel. I can't just only use socat
, because I want to do something with the data in the Java process.
What I tried is (assume on machine A):
socat -u tun:123.123.123.123/24,iff-up,iff-no-pi udp:localhost:1234 &
socat -u udp-listen:1236 interface:tun0 &
All traffic (e.g. the ping request) is sent to a local UDP socket on port 1234. My Java process receives from that port, sends it to machine B, and on the machine to the local port 1236. It seems that the tun0 interface correctly receives the ping. The problem is the packet loops between the two machines, presumably because the second socat
command sends the packet to tun0, and then the first command in turn will send the packet back to Java etc.
Do you have any idea how to tunnel IP in UDP over Java without this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论