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