是否可以通过 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,upPC2:
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?..
Update2:
当出现框架问题时我们尝试通过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一台PC:
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 使用但事实上任何其他解决方案都必须使用类似滑动的东西来组织串行线上的框架。例如,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
发布评论