socat:通过 TTY 隧道 IP

编程入门 行业动态 更新时间:2024-10-27 02:28:14
本文介绍了socat:通过 TTY 隧道 IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以使用 socat 实用程序在类似 ttyS0 的串行(调制解调器)设备上获得双向 IP 隧道?我尝试使用 TUN 选项,但仍然无法得到结果.

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.

欢迎任何建议:)

更新:

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 设备被破坏.有什么建议吗?..

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?..

更新2:

当我们尝试仅使用 socat 建立 TCP/IP 串行隧道时,会出现框架问题.socat 的开发者 Gerhard Rieger 告诉我:

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:

恐怕你是对的.屯通过数据报套接字工作,并且 - 通过运气 - 也超过管道.但是过串行线的数据包边界可能消失,这在发送时是致命的tun接口上的数据输出.

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.

我无法提供基于 socat 的解决方案现在,对不起.但是,我会尝试稍后整合一些框架第 2 版发布.

I cannot offer a socat based solution now, sorry. However, I will try to integrate some framing in a later version 2 release.

推荐答案

哈哈,我工作,但需要一些魔法:)

Ha-ha, I works but there needs to be some magic :)

所以,配置第一个节点:

So, configure the 1st peer with:

PC1: 1) slattach -L -s 57600 -p slip /dev/ttyUSB0 & 2) ifconfig sl0 up 3) socat TUN:192.168.1.1/24,up INTERFACE:sl0 &

...以及第二个对等点上的类似内容:

... and something like that on the 2nd peer:

PC2: 1) slattach -L -s 57600 -p slip /dev/ttyUSB0 & 2) ifconfig sl0 up 3) socat TUN:192.168.1.2/24,up INTERFACE:sl0 &

现在,您可以成功地从另一台 PC ping 通:

And now, you can successfully ping one PC from another:

PC1: 1) ping -c 5 192.168.1.2 PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data. 64 bytes from 192.168.1.2: icmp_req=1 ttl=64 time=348 ms 64 bytes from 192.168.1.2: icmp_req=2 ttl=64 time=551 ms 64 bytes from 192.168.1.2: icmp_req=3 ttl=64 time=557 ms 64 bytes from 192.168.1.2: icmp_req=4 ttl=64 time=549 ms 64 bytes from 192.168.1.2: icmp_req=5 ttl=64 time=348 ms --- 192.168.1.2 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4003ms rtt min/avg/max/mdev = 348.116/471.143/557.128/100.177 ms

由于 slattach 的使用,这有点棘手,但实际上任何其他解决方案都必须使用类似 slip 之类的东西来组织串行线路上的帧.例如,PPP 使用类似 HDLC 的帧.

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:通过 TTY 隧道 IP

本文发布于:2023-10-07 12:39:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469405.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:隧道   socat   TTY   IP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!