Author Topic: How can socat forward Ethernet packets to Serial port and vice versa?  (Read 300 times)

0 Members and 1 Guest are viewing this topic.

Offline nohemon

  • Jr. Member
  • **
  • Posts: 2
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
I'm on a Raspberry Pi and I'm trying to route Ethernet traffic to Serial port and vice versa.
The big picture is:
PC sends data over Ethernet to RPi, then those data will be forwarded to Serial port, then be sent through UART to a second RPi, and finally will be forwarded from Serial to Ethernet again and sent to another network device.

I've searched a lot and I've been told to use PPP but I haven't figured out how to configure it. Then someone told me about socat. Reading the manual I saw that it creates a byte stream from address to address which can be an arbitrary virtual port or device.
Can anyone help me with that?

Thanks

Offline Mad Penguin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1475
  • Karma: 10024
  • Gender: Male
    • View Profile
    • Awards
Re: How can socat forward Ethernet packets to Serial port and vice versa?
« Reply #1 on: October 26, 2020, 06:09:17 pm »
Hi, I'm not sure whether you can make socat do what you want, but I think the "proper" way to achieve what you want is via PPP. To make this work you will need to run a "pppd" server on one of the machines, and a"ppp" client on the other. Each end needs to be configured with the device name of the serial port on that machine, and some basic details like line speed etc. (there are a lots of "howto's" re; configuring ppp knocking around) When set up, the client can be told to "dial" the server, then the server will issue an IP pair the end result is that you will have a new network interface on each machine (typically called "ppp0") connected via a point-to-point TCP/IP link.

Let's say for the sake of argument your local broadband router has a local IP of 192.168.0.1/24. If you tell your PPP link to use 192.168.1.1/24 and 192.168.1.2/24, you will end up with an address of 192.168.1.1/24 on ppp0 on the machine connected to your local network, and 192.168.1.2/24 on the other machine connected via the serial link. If we then assume the other machine connects to the onward ethernet port to another local network on say 192.168.2.1/24, you would then need to add two static routes to get full internet connectivity on the second machine.
(see the "ip" command, specifically "ip route" for adding routes)

On the machine connected to the broadband router, you would need to route 192.168.2.0/24 "via" 192.168.1.1, and on the other end of the serial link you would need to add a default gateway down the serial port, so 0.0.0.0/0 "via" 192.168.1.2. If you then wanted to provide Internet connectivity to machine on the second internal network, then you would need to make sure the default route of machines in 192.168.2.0/24 is pointed to the second "pi" on 192.16.2.1.

On the one hand pppd is not completely straightforward, however, once upon a time it used to be the only way to get a connection to the Internet as a Linux home user, so it's something many people have been able to get to grips with in the past, and something is relatively robust when you get into it ...

hth  :)

The Linux Community Forum

Re: How can socat forward Ethernet packets to Serial port and vice versa?
« Reply #1 on: October 26, 2020, 06:09:17 pm »

Offline nohemon

  • Jr. Member
  • **
  • Posts: 2
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
Re: How can socat forward Ethernet packets to Serial port and vice versa?
« Reply #2 on: October 26, 2020, 08:25:34 pm »
Hi, I'm not sure whether you can make socat do what you want, but I think the "proper" way to achieve what you want is via PPP. To make this work you will need to run a "pppd" server on one of the machines, and a"ppp" client on the other. Each end needs to be configured with the device name of the serial port on that machine, and some basic details like line speed etc. (there are a lots of "howto's" re; configuring ppp knocking around) When set up, the client can be told to "dial" the server, then the server will issue an IP pair the end result is that you will have a new network interface on each machine (typically called "ppp0") connected via a point-to-point TCP/IP link.

Let's say for the sake of argument your local broadband router has a local IP of 192.168.0.1/24. If you tell your PPP link to use 192.168.1.1/24 and 192.168.1.2/24, you will end up with an address of 192.168.1.1/24 on ppp0 on the machine connected to your local network, and 192.168.1.2/24 on the other machine connected via the serial link. If we then assume the other machine connects to the onward ethernet port to another local network on say 192.168.2.1/24, you would then need to add two static routes to get full internet connectivity on the second machine.
(see the "ip" command, specifically "ip route" for adding routes)

On the machine connected to the broadband router, you would need to route 192.168.2.0/24 "via" 192.168.1.1, and on the other end of the serial link you would need to add a default gateway down the serial port, so 0.0.0.0/0 "via" 192.168.1.2. If you then wanted to provide Internet connectivity to machine on the second internal network, then you would need to make sure the default route of machines in 192.168.2.0/24 is pointed to the second "pi" on 192.16.2.1.

On the one hand pppd is not completely straightforward, however, once upon a time it used to be the only way to get a connection to the Internet as a Linux home user, so it's something many people have been able to get to grips with in the past, and something is relatively robust when you get into it ...

hth  :)

Interesting.
I have 1 question though:

Let's say I want to bring the Ethernet packets to the Serial port and then send them over Lora (with Lora hat) to the other RPi where they will arrive to Serial port and be forwarded to Ethernet again. Can PPP create a link between Ethernet and Serial on each RPi or it needs them to be connected over UART?

Offline Mad Penguin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1475
  • Karma: 10024
  • Gender: Male
    • View Profile
    • Awards
Re: How can socat forward Ethernet packets to Serial port and vice versa?
« Reply #3 on: October 27, 2020, 05:49:18 pm »
Mmm, no, PPP is a generic tool and will create a link over a number of transports, including raw serial and ethernet. It's also used in some VPN's to create encrypted P2P tunnels ... but I think the point is that if you're using PPP, you don't need any other software to connect via serial ports .. Lora, socat or such like ..
« Last Edit: October 27, 2020, 05:53:15 pm by Mad Penguin »

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal