User Tools

Site Tools


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

1. Connect a remote mysql UNIX socket to the localhost

# => 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:
# then on your localhost, run this:
# (use if ssh tunnel, (the remote server IP) otherwise)
socat UNIX-LISTEN:/var/lib/mysql/mysql.sock,fork,reuseaddr,unlink-early,user=mysql,group=mysql,mode=777 TCP: &
## 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 &


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