是否有可能通过socat实用程序在类似ttyS0的串行(调制解调器)设备上获得双向IP隧道?我试图使用TUN选项但仍无法获得结果.
欢迎任何建议:)
更新:
PC1:
socat /dev/ttyUSB0,raw,echo=0,b57600,clocal TUN:192.168.1.1/24,up
PC2:
socat /dev/ttyUSB0,clocal TUN:192.168.1.2/24,up
之后,我看到tun0接口两端都有正确的地址,但我不能ping其他地址.而不是那样,当我使用ping -c 1 192.168.1.1发送数据远程socat进程退出并且它的tun0设备被销毁.有什么建议?..
UPDATE2:
当我们尝试使用socat进行串行TCP / IP隧道时,会出现帧错误. socat的开发人员Gerhard Rieger告诉我:
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.
解决方法
哈哈,我的作品,但需要有一些魔力:)
因此,配置第一个对等体:
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 &
…和第二个同行那样的东西:
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:
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的帧.