User Tools

Site Tools


docu:csheet:net:relays:socat_usage

This is an old revision of the document!


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


1. **Connect a remote mysql UNIX socket to the localhost** (for development)

# 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 UDP logging** endpoint

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



Sources:

https://www.redhat.com/sysadmin/getting-started-socat

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