socat(1)
socat is a relay for bidirectional data transfer between two independent data channels.
Synopsis
socat [options] <address> <address>Description
socat establishes two bidirectional byte streams and transfers data between them. It acts as a universal connector for network sockets, files, devices, and pipes. Common uses include port forwarding, SSL/TLS wrapping, and bridging different protocol types.
Each address specifies a data channel using an address type (TCP, UDP, FILE, EXEC, UNIX socket, etc.) and type-specific parameters. socat reads from one address and writes to the other, then reverses the direction, creating a full duplex connection.
Common options
| Flag | What it does |
|---|---|
-d | increase verbosity; use multiple times for more detail (-dd, -ddd) |
-v | write transferred data to stderr as text |
-x | write transferred data to stderr in hexdump format |
-b <size> | set the buffer size for data transfer (default 8192) |
-t <timeout> | set timeout in seconds for all connections |
-T <timeout> | set timeout for each individual read/write operation |
-u | unidirectional mode; data flows only from first to second address |
-ly | syslog logging instead of stderr |
-L <file> | log to specified file instead of stderr |
-g | do not exit on first address EOF (useful for servers) |
Examples
Create a simple port forwarder: listen on port 8080 and relay to example.com:80
socat TCP-LISTEN:8080,reuseaddr TCP:example.com:80Interactive SSH relay: connect stdin/stdout to a remote SSH server
socat - TCP:example.com:22Terminate SSL/TLS on port 443 and forward plaintext to local port 80
socat TCP-LISTEN:443,reuseaddr,cert=/path/to/cert.pem,key=/path/to/key.pem TCP:localhost:80Create a reverse shell listener: incoming TCP connections get a bash shell
socat TCP-LISTEN:5555,reuseaddr EXEC:/bin/bash,pty,stderrTransparent proxy with verbose logging of all transferred data
socat -v TCP:192.168.1.100:3306 TCP-LISTEN:3306,reuseaddrRelay from a Unix socket to another Unix socket (useful for Docker forwarding)
socat UNIX-LISTEN:/tmp/relay.sock,reuseaddr UNIX:/var/run/docker.sockSSH port forwarder with debug output to troubleshoot connection issues
socat -d -d TCP-LISTEN:2222,reuseaddr TCP:10.0.0.5:22Bridge a serial device to a remote TCP service without line editing
socat /dev/ttyUSB0,raw,echo=0 TCP:10.20.30.40:9001