Ilya Matveychikov Ilya Matveychikov - 1 year ago 98
Linux Question

socat: tunnel IP through TTY

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 :)



socat /dev/ttyUSB0,raw,echo=0,b57600,clocal TUN:,up


socat /dev/ttyUSB0,raw,echo=0,b57600,clocal TUN:,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
process exits and it's tun0 device destroyed. Any suggestions?..


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.

Answer Source

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

So, configure the 1st peer with:

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

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

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

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

1) ping -c 5

PING ( 56(84) bytes of data.
64 bytes from icmp_req=1 ttl=64 time=348 ms
64 bytes from icmp_req=2 ttl=64 time=551 ms
64 bytes from icmp_req=3 ttl=64 time=557 ms
64 bytes from icmp_req=4 ttl=64 time=549 ms
64 bytes from icmp_req=5 ttl=64 time=348 ms

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

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download