User Tools

Site Tools


docu:csheet:net:relays:socat_usage

Curated practical uses for socat, a whole TCP/UDP/UNIXSOCK relay tool


1. Connect a remote mysql UNIX socket to the localhost

# 192.168.100.5 => remote mysql server
# anyIPreachable => your host
 
# first, on remote server, run
socat TCP-LISTEN:3307,reuseaddr,fork UNIX-CONNECT:/var/lib/mysql/mysql.sock &
 
# optionally, on your localhost, run an ssh tunnel
# (to add encryption to the communication)
ssh -L 3307:127.0.0.1:3307 192.168.100.5
 
# then on your localhost, run this:
# (use 127.0.0.1 if ssh tunnel, 192.168.100.5 (the remote server IP) otherwise)
socat UNIX-LISTEN:/var/lib/mysql/mysql.sock,fork,reuseaddr,unlink-early,user=mysql,group=mysql,mode=777 TCP:192.168.100.5:3307 &
 
## now you can do `mysql` client on localhost and run sql commands :)


2. Create a **simple network-based TCP logging** endpoint

socat -u TCP4-LISTEN:3334,reuseaddr,fork OPEN:/tmp/test.log,creat,append &



Sources:

docu/csheet/net/relays/socat_usage.txt · Last modified: 2020/09/10 08:50 by admin