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 &


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

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



Sources:

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