Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
2
votes
2
answers
2270
views
How to create a socket forwarder as a server?
I'm looking for a tool that starts a socket server, and forwards incoming requests on that socket port to another internal one. I found `socat` is able to forward socket ports in general: socat tcp-l:8080,fork,reuseaddr tcp:127.0.0.1:12345 This forwards the "official" port `8080` to internal socket...
I'm looking for a tool that starts a socket server, and forwards incoming requests on that socket port to another internal one.
I found
socat
is able to forward socket ports in general:
socat tcp-l:8080,fork,reuseaddr tcp:127.0.0.1:12345
This forwards the "official" port 8080
to internal socket port 12345
successfully.
BUT: my problem is that clients should be able to connect to port 8080
*even* if internal port 12345
is currently unavailable.
The problem with socat is that it does not seem to create a real socket server, but justs remapps the port, and just puts the port on LISTENING.
I'm looking for a tool that tells the client "You connected successfully, please send me your input". And if my local port 12345
is not available, the clients should get an error when trying to send data.
So in case my local application is down, clients should still be able to establish a connection to that official ort.
Is that possible without having to write my own tool?
membersound
(490 rep)
Jul 8, 2019, 11:22 AM
• Last activity: Aug 6, 2025, 07:06 AM
2
votes
1
answers
38
views
socat filter and replace character for modbus ascii
The goal is to get modbus ascii working with a Wallbox from ABL. So I placed a RS485 to TCP converter in the box, created a pseudo tty for my application and got the wrong frame. The answer starts with `>` and should start with `:`. So my approach is the following: ``` Terminal1: sudo socat -d -d -d...
The goal is to get modbus ascii working with a Wallbox from ABL.
So I placed a RS485 to TCP converter in the box, created a pseudo tty for my application and got the wrong frame.
The answer starts with
>
and should start with :
.
So my approach is the following:
Terminal1: sudo socat -d -d -d pty,link=/dev/ttyVA00,echo=0,perm=0777 pty,link=/dev/ttyVB00,echo=0,perm=0777
Terminal2: sudo socat -d -d -d pty,link=/dev/ttyV0,perm=0777 tcp:10.10.49.249:502
Terminal3: cat /dev/ttyVB00 > /dev/ttyV0
Terminal4: cat /:/g' > /dev/ttyVB00
Terminal5: ./modpoll -m ascii /dev/ttyVA00 -b 38400 -d 8 -p even -t4 -c 2 -0
And this works!
Could you give advice on how to simplify the socat solution and how to get it to autostart?
martin
(21 rep)
Jul 31, 2025, 10:49 AM
• Last activity: Aug 1, 2025, 08:57 AM
0
votes
1
answers
1986
views
socat - multiple connection attempts fail to pass through serial
I'm using socat to route serial input over a network to allow me to control an Arduino device over a virtual COM port setup. My command to start socat is: socat /dev/serial0,b500000,raw,echo=0 TCP-LISTEN:9876,nodelay,fork& This works the first time a device connects to the :9876 port perfectly fine....
I'm using socat to route serial input over a network to allow me to control an Arduino device over a virtual COM port setup.
My command to start socat is:
socat /dev/serial0,b500000,raw,echo=0 TCP-LISTEN:9876,nodelay,fork&
This works the first time a device connects to the :9876 port perfectly fine. However, if the connection is dropped from the other end (which is using com2tcp on Windows), any further connections will send serial up the network to the RasPi hosting socat and out the serial device, but data will not be received in from /dev/serial0. I have to kill the original socat process, wait for the port to be released, and then re-run socat. Given the RasPi operates headless, this is an annoyance I'd rather avoid.
Is there any way to allow multiple, non-simultaneous connections to work in this manner? I'm assuming there's some sort of setting to put in after the
echo=0
, but I can't figure out which one.
(Further notes: the 500000 baud rate is required, as this is the rate required for the software I'm using, called GIMX. The purpose of this setup is to allow me to connect to a game console with devices in another room, using the remote play functionality to play the game. I have this command set in /etc/rc.local
to start socat on boot, as the RasPi is also used as a media player using Volumio; this is simply running in the background.)
----------------------------------------------------
EDIT: I ended up abandoning the socat/com2tcp route, and implementing an RFC2247-compliant connection. This meant that I didn't have to worry about manually setting the baud rate as necessary, and seems to work in a more stable manner to boot. I based it on the information from https://robosavvy.com/forum/viewtopic.php?t=7578 which basically gives a full overview of setting it up. Although a couple of the links are dead, it has the information needed to get a connection going.
I believe the command I was looking for was "end-close", however I did not test this before having committed to the new setup.
DragRedSim
(1 rep)
Jan 9, 2020, 05:43 AM
• Last activity: Jul 16, 2025, 01:07 PM
2
votes
1
answers
140
views
socat pty,echo=0 terminal option does not work
I'd use `socat` to redirect the `STDIN/STDOUT` of the process executing `docker run -it ubuntu bash` command to a `tcp` socket in listening on port `32000`. root@eve-ng:~# socat -d -d -d EXEC:'docker run -it ubuntu bash',pty,echo=0 TCP4-LISTEN:32000 From another terminal root@eve-ng:~# nc -v 127.0.0...
I'd use
socat
to redirect the STDIN/STDOUT
of the process executing docker run -it ubuntu bash
command to a tcp
socket in listening on port 32000
.
root@eve-ng:~# socat -d -d -d EXEC:'docker run -it ubuntu bash',pty,echo=0 TCP4-LISTEN:32000
From another terminal
root@eve-ng:~# nc -v 127.0.0.1 32000
Connection to 127.0.0.1 32000 port [tcp/*] succeeded!
root@ada2551fd122:/# ls /usr
ls /usr
bin games include lib lib64 libexec local sbin share src
root@ada2551fd122:/#
As you can see, the connection takes place and the command ls /usr
executed within the container. The problem I'm facing to is that ls /usr
like any other command entered is echoed back *twice*. As far as I can tell, the option echo=0
is there to prevent this behavior, however it doesn't seem to work as expected.
What is actually going on ? Thanks.
CarloC
(385 rep)
Jun 23, 2025, 05:53 AM
• Last activity: Jun 23, 2025, 07:20 AM
1
votes
0
answers
87
views
Using socat to redirect docker attach's STDIN/STDOUT to a TCP socket
I'd like to use `socat` to redirect the `STDIN/STDOUT` of the process executing `docker attach ` to a listening `TCP` socket on my Linux system. root@eve-ng:/opt/unetlab# tty /dev/pts/2 root@eve-ng:/opt/unetlab# root@eve-ng:/opt/unetlab# socat EXEC:'/usr/bin/docker attach afe29573-0030-4a69-8b3e-c04...
I'd like to use
socat
to redirect the STDIN/STDOUT
of the process executing docker attach
to a listening TCP
socket on my Linux system.
root@eve-ng:/opt/unetlab# tty
/dev/pts/2
root@eve-ng:/opt/unetlab#
root@eve-ng:/opt/unetlab# socat EXEC:'/usr/bin/docker attach afe29573-0030-4a69-8b3e-c04ededa8db7-0-4',pty TCP4-LISTEN:32000 &
1275378
root@eve-ng:/opt/unetlab#
The options for socat
are the following:
- EXEC:,pty
to say socat
to start a process executing ` allocating a pseudo-terminal
pty attached to its
STDIN/STDOUT (
socat actually opens the master side multiplexer
/dev/ptmx and then the
fd for the pseudo-terminal pair's master
ptm`)
- TCP4-LISTEN:32000
to say socat
to open a tcp
socket listening on port 32000
Indeed, in another terminal you can check:
root@eve-ng:~# tty
/dev/pts/5
root@eve-ng:~#
root@eve-ng:~# ps -ef | grep attach
root 1275378 1210230 0 08:43 pts/2 00:00:00 socat EXEC:/usr/bin/docker attach afe29573-0030-4a69-8b3e-c04ededa8db7-0-4,pty TCP4-LISTEN:32000
root 1275379 1275378 0 08:43 pts/2 00:00:00 /usr/bin/docker attach afe29573-0030-4a69-8b3e-c04ededa8db7-0-4
root@eve-ng:~#
docker attach
actually attaches to a process running inside the container executing the exec
executable, by the way you can see pts/1
is allocated to it (the container indeed was created using docker create -it
)
root@eve-ng:~# ps -ef | grep exec
root 1284441 731051 2 08:52 pts/1 00:00:00 exec
root 1284583 1222614 0 08:53 pts/5 00:00:00 grep --color=auto exec
root@eve-ng:~#
The problem I'm facing to is that connecting to the tcp socket 127.0.0.1:32000
from a telnet
client, the login process inside the container (exec
) doesn't work as expected. It seems the username typed in (carlo
) is repeated again not allowing to successfully login into the container.
Username: carlo
carlo
Password:
RP/0/RP0/CPU0:Jun 20 09:00:59.739 UTC: exec: %SECURITY-LOGIN-4-AUTHEN_FAILED : Failed authentication attempt by user '' from 'console' on 'con0_RP0_CPU0'
User Access Verification
Username:
Can you help me in understanding why ? Thanks.
P.s. digging into it using strace
I noticed that socat
actually reads from the relevant fd
(of type tcp socket
) twice instead of just once.
CarloC
(385 rep)
Jun 20, 2025, 09:05 AM
• Last activity: Jun 22, 2025, 07:17 PM
2
votes
2
answers
3365
views
How to run multiple `socat` and forwarding both TCP and UDP traffic?
I want to forward Microsoft Remote Desktop on a Linux Server, assume that the remote Windows host is `192.168.1.100`, I want to run: ``` socat TCP4-LISTEN:3389,fork TCP4:192.168.1.100:3389 socat UDP4-LISTEN:3389,fork UDP4:192.168.1.100:3389 ``` It works fine when I start the service by hand in the s...
I want to forward Microsoft Remote Desktop on a Linux Server, assume that the remote Windows host is
192.168.1.100
, I want to run:
socat TCP4-LISTEN:3389,fork TCP4:192.168.1.100:3389
socat UDP4-LISTEN:3389,fork UDP4:192.168.1.100:3389
It works fine when I start the service by hand in the shell, but I want to start it with systemd
, and log into /var/log/socat-rdp.log
.
After some trials I can run the service like this:
[Unit]
Description=Socat RDP Forwarding Service
After=network.target
[Service]
Type=forking
User=root
ExecStart=/bin/sh -c "/usr/bin/socat TCP4-LISTEN:3389,fork TCP4:192.168.3.153:3389 > /var/log/socat-rdp.log 2>&1 & /usr/bin/socat UDP4-LISTEN:3389,fork UDP4:192.168.3.153:3389 > /var/log/socat-rdp.log 2>&1 &"
ExecStop=/bin/kill $MAINPID
[Install]
WantedBy=multi-user.target
This configuration starts and runs normally, but when I stop the service with systemctl stop socat-rdp
it returns error code 1, although socat
process is killed as normal.
Are there any better solutions?
ricky9w
(21 rep)
May 4, 2023, 03:08 PM
• Last activity: Jun 19, 2025, 07:04 AM
0
votes
0
answers
13
views
how to bridge (tcp & perhaps udp) the 2nd netns in order to use services that run on default netns
I have 2x internet connections on a linux box (running slackware btw). The ascii schematic is the following ``` +------------------+ | eth1| --- modem #1 --- internet conn #1 intranet --- |eth0 server | | eth2| --- modem #2 --- internet conn #2 +------------------+ eth0 ip : 192.168.1.1/24 eth1 ip :...
I have 2x internet connections on a linux box (running slackware btw). The ascii schematic is the following
+------------------+
| eth1| --- modem #1 --- internet conn #1
intranet --- |eth0 server |
| eth2| --- modem #2 --- internet conn #2
+------------------+
eth0 ip : 192.168.1.1/24
eth1 ip : 192.168.123.2/29 (def.GW has metric 1), modem1 ip : 192.168.123.1/29
eth2 ip : 192.168.124.2/29 (def.GW has metric 0), modem2 ip : 192.168.124.1/29
NOTE: (I could create a *bond* link but the 2 connections are vastly different and I find it'll be more of a headache. Lets not delve in this path for the duration of this thread).
So the 2 internet connections are both -uselessly- in the default netw. namespace where an SSH daemon runs listening on all interfaces. For eth0 and eth2 this works fine. But I cannot ssh to this machine from "inet ip #1".
The reason is that while the ssh request ingresses the server normally, in the egress direction the default GW of eth2 is used, so somewhere down the line the connection is not completed and I don't get a password prompt.
To circumvent this issue, I decided to split the 2 internet connections in 2 different netns
.
**Q1 : do you have a better suggestion as to how to ?**
using
ip netns add fbns
ip link add link eth1 eth1_ns netns fbns type ipvlan mode l2
ip -n fbns link set lo up
ip -n fbns link set eth1_ns up
ip -n fbns addr add 192.168.123.2/24 dev eth1_ns
ip -n fbns route add default via 192.168.123.1 dev eth1_ns
so far so good , I can nslookup
on the internet side from inet conn #1.
root@sk:~# ip netns exec fbns nslookup google.com 8.8.8.8
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: google.com
Address: 142.250.187.174
Name: google.com
Address: 2a00:1450:4017:80f::200e
but the local DNS server (bind
) which runs in the default netns cannot be accessed:
root@sk:~# ip netns exec fbns nslookup google.com
;; connection timed out; no servers could be reached
from default netns it works fine
root@sk:~# nslookup google.com
Server: 127.0.0.1
Address: 127.0.0.1#53
Non-authoritative answer:
Name: google.com
Address: 216.58.212.14
Name: google.com
Address: 2a00:1450:4017:800::200e
NOTE2: the dns is not extremely necessary as I only want to be able to access the server from the internet side, but it essential that I can access modem's #1 webpage for configuration.
There are 2 solution that I attempted, in order to circumvent this issue but none of the 2 worked:
Solution 1. use socat
---------------------
no sure exactly how to use this correctly but internet suggested:
ip netns exec fbns socat UDP4-RECVFROM:53,fork exec:'socat STDIO "UDP4-SENDTO:localhost:53"',nofork
I also tried the opposite, and both at the same time
socat UDP4-RECVFROM:53,fork exec:'ip netns exec fbns socat STDIO "UDP4-SENDTO:localhost:53"',nofork
but neither worked
Solution 2. use ipvlan on eth0
----------------------
here I simply added the eth0 in the same manner in the netns and added a subnet forwarding towards the default netns. I probably didn't do it properly but I am not sure if ipvlan is even the right construct here.
ip link add link eth0 eth0_ns netns fbns type ipvlan mode l2
ip -n fbns link set eth0_ns up
ip -n fbns addr add 192.168.1.2/24 dev eth0_ns
ip -n fbns route add default via 192.168.1.1 dev eth1_ns
so I am not sure how to achieve a tcp and (perhaps) udp bridge.
**Q2: can you please point me in the right direction?**
Thank you!
nass
(1508 rep)
Jun 18, 2025, 03:52 PM
1
votes
1
answers
4807
views
Posting to socket using curl
I'm struggling to get `curl` and `socat` to play nicely together. The situation is the following: 1. I post XML to log in to a system. 2. The returned message contains an authentication token. 3. I post subsequent requests with the token. Caveat: if the connection is broken, the token expires, so I...
I'm struggling to get
curl
and socat
to play nicely together.
The situation is the following:
1. I post XML to log in to a system.
2. The returned message contains an authentication token.
3. I post subsequent requests with the token.
Caveat: if the connection is broken, the token expires, so I can't use plain curl
.
I need this to run in Linux. Since I need the connection to persist, I decided to use socat
.
If I run this to POST the XML:
curl http://$target_ip -d @./xml/login.xml
... I get a proper answer from the system, but the connection is closed, so I can't reuse the token.
However, if I try this (of course, after socat
):
curl --unix-socket /tmp/$target_ip.sock -d @./xml/login.xml
Curl complains that I don't have the URL set.
Shiunbird
(63 rep)
Jan 15, 2018, 03:34 PM
• Last activity: Jun 5, 2025, 07:05 AM
7
votes
1
answers
4165
views
socat gives error (read(6, 0xf97acc0, 8192): Permission denied)
I'm trying to use `socat` as a port mapper to map IPv4 connections to my OpenVPN server running behind a DS-Lite IPv6 cable connection. //edit I tried with a non root user and `root`. But I get the same result with both users. //edit Goal is to be able to connect from my mobile phone via OpenVPN to...
I'm trying to use
socat
as a port mapper to map IPv4 connections to my OpenVPN server running behind a DS-Lite IPv6 cable connection.
//edit
I tried with a non root user and root
. But I get the same result with both users.
//edit
Goal is to be able to connect from my mobile phone via OpenVPN to my (IPv4) smart home devices.
From the server running socat
I can ping6
my router at home. IPv6 port forwarding is enabled as well and forwards 1194/udp to the raspberry running the OpenVPN server at home.
Problem is now that I'm seeing an error from socat
as I try to connect OpenVPN from my mobile.
root@scw-31f6c8:~/bin# socat -d -d UDP4-LISTEN:63530,fork UDP6:xxx.dynv6.net:1194
2017/12/27 13:53:01 socat N listening on UDP AF=2 0.0.0.0:63530
2017/12/27 13:53:07 socat N accepting UDP connection from AF=2 xx.xxx.xxx.xx:1319
2017/12/27 13:53:07 socat N forked off child process 15429
2017/12/27 13:53:07 socat N listening on UDP AF=2 0.0.0.0:63530
2017/12/27 13:53:07 socat N opening connection to AF=10 [2a02:810c:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx]:1194
2017/12/27 13:53:07 socat N successfully connected from local address AF=10 [2001:0bc8:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx]:41641
2017/12/27 13:53:07 socat N starting data transfer loop with FDs [5,5] and [6,6]
2017/12/27 13:53:07 socat E read(6, 0xf97acc0, 8192): Permission denied
2017/12/27 13:53:07 socat N exit(1)
2017/12/27 13:53:07 socat N childdied(): handling signal 17
2017/12/27 13:53:07 socat W waitpid(): child 15429 exited with status 1
On first sight everything looks good until it hits read(6, 0xf97acc0, 8192): Permission denied
.
Currently I cannot identify if this is a socat
error on the server running it, or if it is related to a communication issue from socat
to my IPv6 endpoint at home.
Any pointer on how to find out what's wrong?
**//edit**
I tried it as well on different machines (uberspace, scaleway) To be sure it is not related to a bad server side configuration. Might be an indicator that something is wrong on my end. But currently I don't see it.
devployment
(181 rep)
Dec 27, 2017, 02:13 PM
• Last activity: May 1, 2025, 07:05 AM
0
votes
1
answers
56
views
Link wifi to serial port by socat problem (MacOS)
I use Lightburn app to control CNC. The CNC controller has WIFI but the Lighburn can work only trough serial ports. So I found that I need to use socat to link cnc server from wifi to serial port. What Im doing (192.168.1.28:80 is a cnc server): `socat PTY,link=~/dev/ttyS0 TCP:192.168.1.28:80` But g...
I use Lightburn app to control CNC. The CNC controller has WIFI but the Lighburn can work only trough serial ports.
So I found that I need to use socat to link cnc server from wifi to serial port.
What Im doing (192.168.1.28:80 is a cnc server):
socat PTY,link=~/dev/ttyS0 TCP:192.168.1.28:80
But get error:
socat E symlink("/dev/ttys001", "~/dev/ttyS0"): No such file or directory
And really, there is no /dev/ttys001
in /dev
folder.
What I'm doing wrong?
Artem
(101 rep)
Apr 26, 2025, 10:09 AM
• Last activity: Apr 27, 2025, 07:28 PM
1
votes
0
answers
66
views
How to send files over WebSocket with websocat tool?
I brought a `wss://` server up using `websocat`: ``` websocat -E -t -v --pkcs12-der=q.pkcs12 wss-listen:0.0.0.0:8443 mirror: ``` And on the client I am running this command to establish a secure WebSocket connection: ``` websocat wss:// :8443 ``` I can send text using this setup and whatever I send...
I brought a
wss://
server up using websocat
:
websocat -E -t -v --pkcs12-der=q.pkcs12 wss-listen:0.0.0.0:8443 mirror:
And on the client I am running this command to establish a secure WebSocket connection:
websocat wss://:8443
I can send text using this setup and whatever I send gets echoed back. But now I want to send files on the wss://
connection. How do I do that?
This is how I am sending files using ws://
and it's working fine.
Server:
websocat -s -v 0.0.0.0:8765 > received.txt
Client:
websocat -b ws://:8765 < testfile.txt
I tried something like this:
Server:
websocat -E -t -v --pkcs12-der=q.pkcs12 wss-listen:0.0.0.0:8443 writefile:received.txt
Client:
websocat -E -t wss://echo.websocket.org:8443 < testfile.txt
But I am getting this error:
websocat: WebSocketError: I/O failure
websocat: error running
Any help regarding how do I do it with wss://
connection will really help. Thanks.
If it's not achievable using websocat, then what other tool I can use to bring up a wss://
server and send files to it?
Aashish Aggarwal
(11 rep)
Apr 23, 2025, 02:36 AM
• Last activity: Apr 23, 2025, 07:26 AM
4
votes
1
answers
678
views
How comes a socat listener knows that the process that connected to it has been KILLed?
As far as I understand, once a TCP connection is established, there's no actual flow of data unless one of the two ends actually sends a message, they are both blocked on a call to receive a message. As in, it's not like either end is sending periodic messages to the other one saying "just to let yo...
As far as I understand, once a TCP connection is established, there's no actual flow of data unless one of the two ends actually sends a message, they are both blocked on a call to receive a message. As in, it's not like either end is sending periodic messages to the other one saying "just to let you know, I'm still alive".
If that's the case, then I would expect that if either end of the communication channel was _abruptly_ shut down (e.g.
kill -KILL it
, but also just unplug the power cable of the whole machine), then the other end would not know.
Going to a concrete example, I can establish a connection between two terminals via socat
:
- listen from one terminal and take note of the PID
$ socat -d4 TCP-LISTEN:12345 -
$ # ctrl-z
$ jobs -l
+ 958602 Stopped socat -d4 TCP-LISTEN:12345 -
$ fg
- connect from the other terminal and take note of that PID too
$ socat -d4 TCP-CONNECT:localhost:12345 -
$ # ctrl-z
$ jobs -l
+ 958730 Stopped socat -d4 TCP-CONNECT:localhost:12345 -
$ fg
(Both socat
commands spit out quite a bit of output because of the -d4
debug messages.)
Now, if I open a third terminal end issue
$ kill -KILL 958730
I see Killed
being printed in the _second_ terminal, with no more debug lines from socat
than those that were printed before, but in the _first_ terminal I do see more output:
2025/02/10 18:04:42 socat D select -> (, 0x0, 0x0, 0x0, NULL/0.000000), 1
2025/02/10 18:04:42 socat D read(122, 0x61dbb1b48000, 8192)
2025/02/10 18:04:42 socat D read -> 0
2025/02/10 18:04:42 socat N socket 1 (fd 122) is at EOF
2025/02/10 18:04:42 socat D data loop: sock1->eof=3, sock2->eof=0, closing=1, wasaction=1, total_to={0.1000000}
2025/02/10 18:04:42 socat D select(1, &0x1, &0x0, &0x0, &0.500000)
2025/02/10 18:04:43 socat D select -> (, 0x0, 0x0, 0x0, &0.000000), 0
2025/02/10 18:04:43 socat I poll timed out (no data within 0.500000 seconds)
2025/02/10 18:04:43 socat I shutdown(122, 2)
2025/02/10 18:04:43 socat D shutdown() -> 0
2025/02/10 18:04:43 socat D tcsetattr(0, 0, {00006506,00000005,000000bf,00008a3b, 15,15, 03,1c,7f,15,04,00,01,00,11,13,1a,00,12,0f,17,16,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00})
2025/02/10 18:04:43 socat D tcsetattr() -> 0
2025/02/10 18:04:43 socat D tcsetattr(1, 0, {00006506,00000005,000000bf,00008a3b, 15,15, 03,1c,7f,15,04,00,01,00,11,13,1a,00,12,0f,17,16,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00})
2025/02/10 18:04:43 socat D tcsetattr() -> 0
2025/02/10 18:04:43 socat N exiting with status 0
2025/02/10 18:04:43 socat D exit(0)
2025/02/10 18:04:43 socat D starting xioexit()
2025/02/10 18:04:43 socat D finished xioexit()
But I don't understand, if [SIGKILL
can't be caught/handled in user code because it's handled directly by the kernel](https://stackoverflow.com/a/35570675/5825294) , then 958730
should have no chance of doing anything like sending a message to say "sorry, I'm dying", and therefore 958602
should never know about it.
Where's the flaw in my reasoning?
Enlico
(2258 rep)
Feb 10, 2025, 06:14 PM
• Last activity: Feb 10, 2025, 06:38 PM
0
votes
0
answers
156
views
Use socat to bridge CanFD messages
Is it possible to bridge to can interfaces via socat? My setup looks something like this: ``` HOST A Host B vcan0 vcan0 ``` Where i have 2 hosts with a can interface and i want to bridge them ideally via socat. I got as far as sending can messages which the following config. But CanFD messages are j...
Is it possible to bridge to can interfaces via socat?
My setup looks something like this:
HOST A Host B
vcan0 vcan0
Where i have 2 hosts with a can interface and i want to bridge them ideally via socat.
I got as far as sending can messages which the following config.
But CanFD messages are just silently dropped and are not forwarded to the remote vcan interface. (I would like to avoid using something like cannelloni.)
Server
sudo socat INTERFACE:vcan0,pf=29,type=3,prototype=1 TCP-LISTEN:2000,fork,reuseaddr,nodelay
Client
sudo socat INTERFACE:vcan0,pf=29,type=3,prototype=1 TCP:SERVERIP:2000,nodelay
Is forwarding CanFD even possible with socat?
### More debugging
Running socat with -d -d -d
shows that the socat process doesn't even register CanFD frames.
For a can frame these 2 messages are produced:
2024/12/13 09:26:12 socat N local address: AF=29 AF=29 0x0000060000000400000000000000
2024/12/13 09:26:12 socat I transferred 16 bytes from 7 to 5
And nothing for CanFD.
Sir l33tname
(459 rep)
Dec 12, 2024, 05:10 PM
• Last activity: Jan 16, 2025, 06:08 AM
0
votes
1
answers
2885
views
SOCAT (only) reverse tunnel
I have a situation where we are trying to get data from one network to another - specifically access to a private maven repo on a different network. Network 1 contains a maven repo. And network is protected by a couple SSH hops where port forwarding is disabled on `sshd`. - [Laptop], running a Docke...
I have a situation where we are trying to get data from one network to another - specifically access to a private maven repo on a different network.
Network 1 contains a maven repo. And network is protected by a couple SSH hops where port forwarding is disabled on
sshd
.
- [Laptop], running a Docker Container with VPN into other network laptop
- Docker Container vpn
- [Jumpbox] jumpbox.vpn.network.org
- [Server] server.vpn.network.org
We have successfully run vscode-server on **server** and connect via:
socat tcp-listen:8080,fork EXEC:"ssh server.vpn.network.org nc localhost 8081"
This lets laptop hit localhost:8080
and it tunnels traffic into our server.vpn
which then goes into netcat and sends the traffic into vscode server
I figure it should be possible to do the opposite I'm just getting stuck.
The goal would be to run a Socks5
proxy on laptop via something like
ssh -f -N -D 54321 localhost
And then make a socat call into server.vpn.network.org
and then using the socks env vars I could run maven and have it proxy back through the connection etc.
The approach I took was trying this:
socat -v TCP:localhost:54321 EXEC:"ssh server.vpn.network.org nc -lkv localhost 54321"
It was "sort" of working but kept dropping connection.
I then tried a combo of fork
and reuseaddr
and they didn't seem to solve the issue.
My next approach was to consider unix sockets or something funky - but I'm wondering if somebody knows how to make this work.
Thanks.
Jeef
(157 rep)
Jan 11, 2022, 08:51 PM
• Last activity: Dec 23, 2024, 01:00 AM
1
votes
2
answers
133
views
How to get socat exit code when piping stdin to it?
I am executing commands against a docker container using socat and I want to get the exit code of the code executed in the container. This is what I've tried: ``` $ docker run --rm -itd --name test123 ubuntu $ echo "ls" | socat EXEC:"docker attach test123",pty - &> /dev/null $ echo $? 0 $ echo "foob...
I am executing commands against a docker container using socat and I want to get the exit code of the code executed in the container.
This is what I've tried:
$ docker run --rm -itd --name test123 ubuntu
$ echo "ls" | socat EXEC:"docker attach test123",pty - &> /dev/null
$ echo $?
0
$ echo "foobar" | socat EXEC:"docker attach test123",pty - &> /dev/null
$ echo $?
0
as you can see this is not working properly because the exit code for the foobar
command should obviously be non-zero.
$ socat -V
socat version 1.8.0.1 on
running on Darwin version
Foo
(242 rep)
Dec 3, 2024, 07:02 PM
• Last activity: Dec 5, 2024, 08:36 PM
1
votes
0
answers
43
views
Socat error inside Linux Network Namespaces
I'm trying to run `socat` forward `ttyACM0` into `UDP`. It works with command. ```bash socat UDP-LISTEN:14550,fork,reuseaddr FILE:/dev/ttyACM0,b57600,raw ``` Problem is, I need to access `socat` via ip address, which is inside `netns`. I tried to enter this command: ```bash ip netns exec int socat U...
I'm trying to run
socat
forward ttyACM0
into UDP
. It works with command.
socat UDP-LISTEN:14550,fork,reuseaddr FILE:/dev/ttyACM0,b57600,raw
Problem is, I need to access socat
via ip address, which is inside netns
. I tried to enter this command:
ip netns exec int socat UDP-LISTEN:14550,fork,reuseaddr FILE:/dev/ttyACM0,b57600,raw
, which displays error:
2024/10/10 14:14:37 socat E read(5, 0x1d54000, 8192): Connection refused
2024/10/10 14:14:38 socat E read(5, 0x1d54000, 8192): Connection refused
2024/10/10 14:14:39 socat E read(5, 0x1d54000, 8192): Connection refused
2024/10/10 14:14:40 socat E read(5, 0x1d54000, 8192): Connection refused
2024/10/10 14:14:41 socat E read(5, 0x1d54000, 8192): Connection refused
2024/10/10 14:14:42 socat E read(5, 0x1d54000, 8192): Connection refused
2024/10/10 14:14:43 socat E read(5, 0x1d54000, 8192): Connection refused
2024/10/10 14:14:44 socat E write(5, 0x1d54000, 44): Connection refused
2024/10/10 14:14:45 socat E read(5, 0x1d54000, 8192): Connection refused
2024/10/10 14:14:46 socat E read(5, 0x1d54000, 8192): Connection refused
2024/10/10 14:14:47 socat E read(5, 0x1d54000, 8192): Connection refused
2024/10/10 14:14:48 socat E write(5, 0x1d54000, 40): Connection refused
2024/10/10 14:14:49 socat E read(5, 0x1d54000, 8192): Connection refused
2024/10/10 14:14:50 socat E read(5, 0x1d54000, 8192): Connection refused
How to properly run socat inside netns?
eXulW0lf
(21 rep)
Oct 10, 2024, 02:20 PM
1
votes
1
answers
38
views
How to Stop Script from Overwriting Symlink to a File
long time reader, but first questioner here. (Feedback on my question is welcome) I'm using a Raspberry Pi CM4 with a custom PCB. The board includes a USB Hub to allow for 2-3 peripherals. Hardware works great, no issues there. Two of the USB connections are permanently integrated into the board and...
long time reader, but first questioner here.
(Feedback on my question is welcome)
I'm using a Raspberry Pi CM4 with a custom PCB. The board includes a USB Hub to allow for 2-3 peripherals. Hardware works great, no issues there.
Two of the USB connections are permanently integrated into the board and are randomly assigned device names each startup. (ie. the 4G modem could be assign ttyUSB0-3 or ttyUSB1-4). The 4G Module can also be swapped out to a few different brands.
There are services that I run to check on the 4G modem after starting up (to get serial numbers and manufacturers etc.) and periodically, to get things such us signal strength.
I've done this using a shell script that sends AT-Commands to the module via socat. e.g:
echo "AT+GSN" | socat - ${MODEM_LOCATION}
Where MODEM_LOCATION points towards the device path.
I had been manually checking the device path and starting the services but wanted to automate that process.
Following some advice I read online, I developed some udev rules to create a symlink to the Modem, so it can autonomously start the scripts.
SUBSYSTEMS=="usb", ENV{ID_USB_INTERFACE_NUM}="$attr{bInterfaceNumber}"
SUBSYSTEM=="tty", ATTRS{idProduct}=="0125", ATTRS{idVendor}=="2c7c", MODE="0777", ENV{ID_USB_INTERFACE_NUM}=="00", SYMLINK+="ttyUSB_EC25_1"
SUBSYSTEMS=="usb", ENV{ID_USB_INTERFACE_NUM}="$attr{bInterfaceNumber}"
SUBSYSTEM=="tty", ATTRS{idProduct}=="0125", ATTRS{idVendor}=="2c7c", MODE="0777", ENV{ID_USB_INTERFACE_NUM}=="01", SYMLINK+="ttyUSB_EC25_2"
SUBSYSTEMS=="usb", ENV{ID_USB_INTERFACE_NUM}="$attr{bInterfaceNumber}"
SUBSYSTEM=="tty", ATTRS{idProduct}=="0125", ATTRS{idVendor}=="2c7c", MODE="0777", ENV{ID_USB_INTERFACE_NUM}=="02", SYMLINK+="ttyUSB_EC25_3"
SUBSYSTEMS=="usb", ENV{ID_USB_INTERFACE_NUM}="$attr{bInterfaceNumber}"
SUBSYSTEM=="tty", ATTRS{idProduct}=="0125", ATTRS{idVendor}=="2c7c", MODE="0777", ENV{ID_USB_INTERFACE_NUM}=="03", SYMLINK+="ttyUSB_EC25_4"
At first it worked a charm while I was manually running the scripts, but when I started getting the service to run it, it began 'breaking' the symlink.
What I mean by breaking it, is that it's no longer a symlink path. Instead it becomes a file that's storing text - the commands and responses from the AT-Commands.
In the screenshot below you can see it's changed the file type.
Additionally, I can run nano /dev/ttyUSB_EC25_4 and it opens an unwritable file full of the communications with the module:
I've tried to debug it from the point of view the socat was the issues - no luck.
I've tried to debug the script I was running.
I've tried to run the scripts manually now as well but it's still happening. (Unsure why it seemed to be working originally)
I've spent about 3 weeks on this issue now and would very much appreciate any advice, solutions, recommendations etc.
If I remove the file and restart the rules it re-creates a symlink correctly, but after running the scripts again, even if it works the first or second time, by the third time it's been changed back to some kind of file.


Oliver Munro
(11 rep)
Aug 22, 2024, 01:07 AM
• Last activity: Sep 2, 2024, 03:41 AM
0
votes
0
answers
102
views
Check if a port is blocked with socat
- How to check if a port is blocked with `socat`? - How to check with IPv6? I heard a saying that machines behind NAT can still be directly connected via IPv6, is that true? Anyway, say I have a machine behind very complicated setup, and I want to verify if a certain port can be reached, by either I...
- How to check if a port is blocked with
socat
?
- How to check with IPv6?
I heard a saying that machines behind NAT can still be directly connected via IPv6, is that true?
Anyway, say I have a machine behind very complicated setup, and I want to verify if a certain port can be reached, by either IPv4 or IPv6, how to do that with socat
?
Basically I need to start socat
on the machine to listen, then try to conect to it via socat
from other machines. I've read https://copyconstruct.medium.com/socat-29453e9fc8a6 , and found it a bit complicated, but I cannot just use netcat
because my netcat version does not support IPv6, as per https://unix.stackexchange.com/questions/457670/netcat-how-to-listen-on-a-tcp-port-using-ipv6-address .
xpt
(1858 rep)
Aug 7, 2024, 04:12 PM
3
votes
2
answers
12936
views
Intercept communications on physical serial port using socat
I'm no Linux expert so please go easy ;). Ok, the situation is that I have a single board computer running Debian Wheezy. I know its old/risky etc etc but its not actually "my" equipment and therefore I have no control over this. There is some software running on it, written in c# and ran through mo...
I'm no Linux expert so please go easy ;).
Ok, the situation is that I have a single board computer running Debian Wheezy. I know its old/risky etc etc but its not actually "my" equipment and therefore I have no control over this.
There is some software running on it, written in c# and ran through mono. Again, this is not my software and I have zero control over it or the ability to alter the code.
The software sends AT commands down a physical serial port (
/dev/ttyS1
) to a modem which returns the appropriate responses to the commands.
The modems are no longer available and therefore I need to develop some alternative. Therefore I thought I could run a simple python script on the SBC that would "intercept" the AT commands, send back the appropriate responses to the c# software and then I can use the python script to talk to another device however I need to.
Having had a good "google", socat
seemed to be the best option for doing this. However, I have tried I dont know how many combinations and cannot get it to work the way I need it to.
The physical setup is that I currently have the serial port plugged into my laptop so I can see the AT commands coming up the pipe (on ttyS1) I then ssh into the SBC and fire up minicom to view the new "virtual ports" created by socat
.
Existing Setup
**C# ttyS1 Old Modem**
Desired Setup
**C# socat python -> New Modem**
Below is just two of the variations I've tried:
socat -x /dev/ttyS1,raw,echo=0,crnl PTY,link=/dev/ttyV1,raw,echo=0,crnl
... also tried the other way around in case I misunderstood ...
socat -x PTY,link=/dev/ttyV1,raw,echo=0,crnl /dev/ttyS1,raw,echo=0,crnl
I've also tried **many** different variations, pushing to files, "teeing" off to files, different command switches, configuring the ports using stty etc etc
Every time I have the same issue that I cannot actually see the AT commands being sent **from** the c# software?!
I can type into minicom on the SBC and see the output turning up on the serial port reader on my laptop, likewise I can type into the serial port reader on my laptop and see the input in minicom on the SBC, however what I cannot seem to intercept is the actual AT commands being sent from the c# software even though the software is configured to use ttyS1.
The one bit of control I do have over the software is which port it uses to talk to the modem on. Therefore I have also tried changing this to a virtual port e.g. /dev/ttyV1
and running socat
to create the virtual port during startup and before the c# program starts so that the virtual port is actually available. Again I have exactly the same issue where I still cannot see the AT commands being sent by c# software.
Hope someone can help as I've been at this two full days now and cannot get it to work. I'm pretty sure socat is the tool to use and hopefully I've just fundamentally misunderstood how it works.
RobF
(31 rep)
Jul 29, 2022, 09:44 AM
• Last activity: Jul 24, 2024, 03:04 AM
2
votes
1
answers
585
views
Proxy between UNIX socket with socat
I used socal to create a proxy server between 2 UNIX sockets: /var/a.sock , /var/b.sock `client -> /var/a.sock -> MY_COMMAND -> /var/b.sock -> MY_COMMAND -> /var/a.sock ->client`. The following commands works fine just for `client -> /var/a.sock -> /var/b.sock -> /var/a.sock -> client`. `socat UNIX-...
I used socal to create a proxy server between 2 UNIX sockets: /var/a.sock , /var/b.sock
client -> /var/a.sock -> MY_COMMAND -> /var/b.sock -> MY_COMMAND -> /var/a.sock ->client
.
The following commands works fine just for
client -> /var/a.sock -> /var/b.sock -> /var/a.sock -> client
.
socat UNIX-LISTEN:/var/a.sock,fork 'UNIX-CONNECT:/var/b.sock
I need one more thing.
To replace AAAA with BBBB before send
How can I do that please ?
Polo1990
(25 rep)
Jun 20, 2024, 01:53 PM
• Last activity: Jun 25, 2024, 05:58 AM
Showing page 1 of 20 total questions