# To create a classic TCP listening daemon, similar to netcat -l, use a variation of the following command.
socat TCP-LISTEN:8080 stdout
# use remotly a command shell
socat TCP4-LISTEN:1234,reuseaddr,fork 'SYSTEM:/bin/cat /home/infos.txt'
# SSLfy a server
socat OPENSSL-LISTEN:443,reuse‐addr,pf=ip4,fork,cert=server.pem,cafile=client.crt TCP4-CONNECT:localhost:80
# remote logger on server
socat TCP-LISTEN:5555,reuseaddr,fork SYSTEM:"tail -f /var/log/cassandra/system.log",pty
# client
socat -u TCP:88.190.48.140:5555 STDIO
# make a tunnel
socat TCP4-LISTEN:1022,reuseaddr,fork TCP4:host.foo.com:22
# make a tunnel via with a proxy
socat TCP4-LISTEN:2022,reuseaddr,fork PROXY:proxy:machine.toto.fr:22,proxyport=3128,proxyauth=user:pass
# Installs a simple TCP port forwarder. With TCP4-LISTEN it listens on local port "www" until a connection comes in, accepts it,
# The service running on 172.16.245.11:5432 is forward to 172.16.251.139:5666
socat -d -d -lmlocal2 TCP4-LISTEN:5666,bind=172.16.251.139,su=nobody,fork,reuseaddr TCP4:172.16.245.11:5432
# using socat as an VPN with TUN address
LOCAL_TUN_ADDRESS=10.0.0.0/24
REMOTE_TUN_ADDRESS=10.0.1.0/24
REMOTE_HOSTNAME=server-name.intranet
sudo socat -d TUN:"$LOCAL_TUN_ADDRESS",up 'EXEC:ssh -i '"$HOME/.ssh/id_rsa"' '"$USER"'@'"$REMOTE_HOSTNAME"' "sudo socat - TUN:'"$REMOTE_TUN_ADDRESS"',up"'