socat:通过 TTY 建立隧道 IP
是否可以使用 socat 实用程序通过类似 ttyS0 的串行(调制解调器)设备获得双向 IP 隧道?我尝试使用 TUN 选项但仍然无法得到结果。
欢迎提出任何建议:)
更新:
PC1:
socat /dev/ttyUSB0,raw,echo=0,b57600,clocal TUN:192.168.1.1/24,up
PC2:
socat /dev/ttyUSB0,raw,echo=0,b57600,clocal TUN:192.168.1.2/24,up
之后,我看到 tun0 接口两端都有正确的地址,但我无法从另一个接口 ping 通。相反,当我使用 ping -c 1 192.168.1.1
发送数据时,远程 socat
进程退出,并且 tun0 设备被破坏。有什么建议吗?..
更新2:
当我们尝试仅使用 socat 通过串行建立 TCP/IP 隧道时,存在帧问题。 socat 的开发者 Gerhard Rieger 对我说:
恐怕你是对的。屯 通过数据报套接字工作,并且 - 通过 运气 - 也超过管道。但超过 串行线数据包边界可能 消失,这在发送时是致命的 tun接口上的数据输出。
我无法提供基于 socat 的解决方案 现在,抱歉。不过,我会尽力 稍后整合一些框架 版本 2 发布。
Is it possible to get an bidirectional IP-tunnel over ttyS0-like serial (modem) devices with the socat utility? I tried to use TUN option but still can't get the result.
Any suggestions are welcome :)
Update:
PC1:
socat /dev/ttyUSB0,raw,echo=0,b57600,clocal TUN:192.168.1.1/24,up
PC2:
socat /dev/ttyUSB0,raw,echo=0,b57600,clocal TUN:192.168.1.2/24,up
After that, I have seen tun0 interfaces with proper addresses on both ends but I can't ping one from other. Instead of that, when I send data with ping -c 1 192.168.1.1
remote socat
process exits and it's tun0 device destroyed. Any suggestions?..
Update2:
There is a framing problem when we try to make TCP/IP tunnel over serial with only socat. Gerhard Rieger, the socat's developer, says me that:
I am afraid that you are right. tun
over datagram socket works, and - by
luck - also over pipes. But over the
serial line the packet boundaries may
vanish and this is fatal when sending
the data out on the tun interface.I cannot offer a socat based solution
now, sorry. However, I will try to
integrate some framing in a later
version 2 release.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
哈哈,我可以工作,但需要一些魔法:)
所以,配置第一个对等点:
...在第二个对等点上配置类似的东西:
现在,你可以成功地从另一台电脑上 ping 通一台电脑:
这有点由于使用了 slattach,所以有点棘手,但实际上任何其他解决方案都必须使用 slip 之类的东西来组织串行线路上的帧。例如,PPP 使用类似 HDLC 的帧。
Ha-ha, I works but there needs to be some magic :)
So, configure the 1st peer with:
... and something like that on the 2nd peer:
And now, you can successfully ping one PC from another:
It's a little bit tricky because of
slattach
use but in fact any other solution must use something like slip to organize framing over the serial line. For example, PPP use HDLC-like frames.根据我的尝试,您不需要 socat 来建立隧道。
您可以执行以下操作:
设置后,我可以从 PC1 ping PC2,反之亦然。
还有另一个前提条件:你的 Linux 内核必须加载 slip 模块。
based on what I have tried, you don't need socat to establish a tunnel.
you can just do the following:
After the setup, I can ping PC2 from PC1, and vice versa.
There is another pre-condition: your Linux kernel must have slip module loaded.