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 &

3. Create a HTTP -> HTTPS proxy for certificate errors when unsupported.

# creates an http server at that proxies to https
socat TCP4-LISTEN:8008,reuseaddr,fork openssl:,verify=0


docu/csheet/net/relays/socat_usage.txt · Last modified: 2022/05/17 14:27 by admin