socat(1): Multipurpose relay - Linux man page
Archived: 2026-04-05 13:08:16 UTC
Name
socat - Multipurpose relay (SOcket CAT)
Synopsis
CWsocat [options]
CWsocat -V
CWsocat -h[h[h]] | -?[?[?]]
CWfilan
CWprocan
Description
Socat is a command line based utility that establishes two bidirectional byte streams and transfers data between
them. Because the streams can be constructed from a large set of different types of data sinks and sources (see
address types), and because lots of address options may be applied to the streams, socat can be used for many
different purposes.
Filan is a utility that prints information about its active file descriptors to stdout. It has been written for debugging
socat, but might be useful for other purposes too. Use the -h option to find more infos.
Procan is a utility that prints information about process parameters to stdout. It has been written to better
understand some UNIX process properties and for debugging socat, but might be useful for other purposes too.
The life cycle of a socat instance typically consists of four phases.
In the init phase, the command line options are parsed and logging is initialized.
During the open phase, socat opens the first address and afterwards the second address. These steps are usually
blocking; thus, especially for complex address types like socks, connection requests or authentication dialogs must
be completed before the next step is started.
In the transfer phase, socat watches both streamscq read and write file descriptors via CWselect() , and, when data
is available on one side and can be written to the other side, socat reads it, performs newline character conversions
if required, and writes the data to the write file descriptor of the other stream, then continues waiting for more data
in both directions.
When one of the streams effectively reaches EOF, the closing phase begins. Socat transfers the EOF condition to
the other stream, i.e. tries to shutdown only its write stream, giving it a chance to terminate gracefully. For a defined
time socat continues to transfer data in the other direction, but then closes all remaining channels and terminates.
https://linux.die.net/man/1/socat
Page 1 of 48
Options
Socat provides some command line options that modify the behaviour of the program. They have nothing to do with
so called address options that are used as parts of address specifications.
CW-V
Print version and available feature information to stdout, and exit.
CW-h | -?
Print a help text to stdout describing command line options and available address types, and exit.
CW-hh | -??
Like -h, plus a list of the short names of all available address options. Some options are platform dependend,
so this output is helpful for checking the particular implementation.
CW-hhh | -???
Like -hh, plus a list of all available address option names.
CW-d
Without this option, only fatal and error messages are generated; applying this option also prints warning
messages. See DIAGNOSTICS for more information.
CW-d -d
Prints fatal, error, warning, and notice messages.
CW-d -d -d
Prints fatal, error, warning, notice, and info messages.
CW-d -d -d -d
Prints fatal, error, warning, notice, info, and debug messages.
CW-D
Logs information about file descriptors before starting the transfer phase.
CW-ly[]
Writes messages to syslog instead of stderr; severity as defined with -d option. With optional , the
syslog type can be selected, default is dqdaemondq.
CW-lfCW
Writes messages to [filename] instead of stderr.
CW-ls
Writes messages to stderr (this is the default).
CW-lpCW
Overrides the program name printed in error messages and used for constructing environment variable
names.
CW-lu
Extends the timestamp of error messages to microsecond resolution. Does not work when logging to syslog.
CW-lm[]
Mixed log mode. During startup messages are printed to stderr; when socat starts the transfer phase loop or
daemon mode (i.e. after opening all streams and before starting data transfer, or, with listening sockets with
fork option, before the first accept call), it switches logging to syslog. With optional , the syslog
type can be selected, default is dqdaemondq.
CW-lh
https://linux.die.net/man/1/socat
Page 2 of 48
Adds hostname to log messages. Uses the value from environment variable HOSTNAME or the value
retrieved with CWuname() if HOSTNAME is not set.
CW-v
Writes the transferred data not only to their target streams, but also to stderr. The output format is text with
some conversions for readability, and prefixed with dq> dq or dq< dq indicating flow directions.
CW-x
Writes the transferred data not only to their target streams, but also to stderr. The output format is
hexadecimal, prefixed with dq> dq or dq< dq indicating flow directions. Can be combined with CW-v .
CW-bCW
Sets the data transfer block [size_t]. At most bytes are transferred per step. Default is 8192
bytes.
CW-s
By default, socat terminates when an error occurred to prevent the process from running when some option
could not be applied. With this option, socat is sloppy with errors and tries to continue. Even with this
option, socat will exit on fatals, and will abort connection attempts when security checks failed.
CW-tCW
When one channel has reached EOF, the write part of the other channel is shut down. Then, socat waits
[timeval] seconds before terminating. Default is 0.5 seconds. This timeout only applies to
addresses where write and read part can be closed independently. When during the timeout interval the read
part gives EOF, socat terminates without awaiting the timeout.
CW-TCW
Total inactivity timeout: when socat is already in the transfer loop and nothing has happened for
[timeval] seconds (no data arrived, no interrupt occurred...) then it terminates. Useful with protocols like
UDP that cannot transfer EOF.
CW-u
Uses unidirectional mode. The first address is only used for reading, and the second address is only used for
writing (example).
CW-U
Uses unidirectional mode in reverse direction. The first address is only used for writing, and the second
address is only used for reading.
CW-g
During address option parsing, doncqt check if the option is considered useful in the given address
environment. Use it if you want to force, e.g., appliance of a socket option to a serial device.
CW-LCW
If lockfile exists, exits with error. If lockfile does not exist, creates it and continues, unlinks lockfile on exit.
CW-WCW
If lockfile exists, waits until it disappears. When lockfile does not exist, creates it and continues, unlinks
lockfile on exit.
CW-4
Use IP version 4 in case that the addresses do not implicitly or explicitly specify a version; this is the default.
CW-6
Use IP version 6 in case that the addresses do not implicitly or explicitly specify a version.
https://linux.die.net/man/1/socat
Page 3 of 48
Address Specifications
With the address command line arguments, the user gives socat instructions and the necessary information for
establishing the byte streams.
An address specification usually consists of an address type keyword, zero or more required address parameters
separated by cq:cq from the keyword and from each other, and zero or more address options separated by cq,cq.
The keyword specifies the address type (e.g., TCP4, OPEN, EXEC). For some keywords there exist synonyms (cq-cq for STDIO, TCP for TCP4). Keywords are case insensitive. For a few special address types, the keyword may be
omitted: Address specifications starting with a number are assumed to be FD (raw file descriptor) addresses; if a
cq/cq is found before the first cq:cq or cq,cq, GOPEN (generic file open) is assumed.
The required number and type of address parameters depend on the address type. E.g., TCP4 requires a server
specification (name or address), and a port specification (number or service name).
Zero or more address options may be given with each address. They influence the address in some ways. Options
consist of an option keyword or an option keyword and a value, separated by cq=cq. Option keywords are case
insensitive. For filtering the options that are useful with an address type, each option is member of one option
group. For each address type there is a set of option groups allowed. Only options belonging to one of these address
groups may be used (except with option -g).
Address specifications following the above schema are also called single address specifications. Two single
addresses can be combined with dq!!dq to form a dual type address for one channel. Here, the first address is used
by socat for reading data, and the second address for writing data. There is no way to specify an option only once
for being applied to both single addresses.
Usually, addresses are opened in read/write mode. When an address is part of a dual address specification, or when
option -u or -U is used, an address might be used only for reading or for writing. Considering this is important with
some address types.
With socat version 1.5.0 and higher, the lexical analysis tries to handle quotes and parenthesis meaningfully and
allows escaping of special characters. If one of the characters ( { [ cq is found, the corresponding closing character -
) } ] cq - is looked for; they may also be nested. Within these constructs, socats special characters and strings : , !!
are not handled specially. All those characters and strings can be escaped with \ or within dqdq
Address Types
This section describes the available address types with their keywords, parameters, and semantics.
CWCREATE:
Opens with CWcreat() and uses the file descriptor for writing. This address type requires write-only context, because a file opened with CWcreat cannot be read from.
Flags like O_LARGEFILE cannot be applied. If you need them use OPEN with options create,create.
must be a valid existing or not existing path. If is a named pipe, CWcreat() might
block; if refers to a socket, this is an error.
https://linux.die.net/man/1/socat
Page 4 of 48
Option groups: FD,REG,NAMED
Useful options: mode, user, group, unlink-early, unlink-late, append
See also: OPEN, GOPEN
CWEXEC:
Forks a sub process that establishes communication with its parent process and invokes the specified
program with CWexecvp() . is a simple command with arguments separated by single
spaces. If the program name contains a cq/cq, the part after the last cq/cq is taken as ARGV[0]. If the
program name is a relative path, the CWexecvp() semantics for finding the program via CW$PATH apply.
After successful program start, socat writes data to stdin of the process and reads from its stdout using a
UNIX domain socket generated by CWsocketpair() per default. (example)
Option groups: FD,SOCKET,EXEC,FORK,TERMIOS
Useful options: path, fdin, fdout, chroot, su, su-d, nofork, pty, stderr, ctty, setsid, pipes, login, sigint, sigquit
See also: SYSTEM
CWFD:
Uses the file descriptor . It must already exist as valid UN*X file descriptor.
Option groups: FD (TERMIOS,REG,SOCKET)
See also: STDIO, STDIN, STDOUT, STDERR
CWGOPEN:
(Generic open) This address type tries to handle any file system entry except directories usefully.
may be a relative or absolute path. If it already exists, its type is checked. In case of a UNIX domain socket,
socat connects; if connecting fails, socat assumes a datagram socket and uses CWsendto() calls. If the entry
is not a socket, socat opens it applying the CWO_APPEND flag. If it does not exist, it is opened with flag
CWO_CREAT as a regular file (example).
Option groups: FD,REG,SOCKET,NAMED,OPEN
See also: OPEN, CREATE, UNIX-CONNECT
CWIP-SENDTO::
Opens a raw IP socket. Depending on host specification or option pf, IP protocol version 4 or 6 is used. It
uses to send packets to [IP address] and receives packets from host, ignores packets from
other hosts. Protocol 255 uses the raw socket with the IP header being part of the data.
Option groups: FD,SOCKET,IP4,IP6
Useful options: pf, ttl
See also: IP4-SENDTO, IP6-SENDTO, IP-RECVFROM, IP-RECV, UDP-SENDTO, UNIX-SENDTO
CWINTERFACE:
Communicates with a network connected on an interface using raw packets including link level data.
is the name of the network interface. Currently only available on Linux. Option groups:
FD,SOCKET
Useful options: pf, type
See also: ip-recv
CWIP4-SENDTO::
Like IP-SENDTO, but always uses IPv4.
Option groups: FD,SOCKET,IP4
CWIP6-SENDTO::
https://linux.die.net/man/1/socat
Page 5 of 48
Like IP-SENDTO, but always uses IPv6.
Option groups: FD,SOCKET,IP6
CWIP-DATAGRAM::
Sends outgoing data to the specified address which may in particular be a broadcast or multicast address.
Packets arriving on the local socket are checked if their source addresses match RANGE or TCPWRAP
options. This address type can for example be used for implementing symmetric or asymmetric broadcast or
multicast communications.
Option groups: FD, SOCKET, IP4, IP6, RANGE
Useful options: bind, range, tcpwrap, broadcast, ip-multicast-loop, ip-multicast-ttl, ip-multicast-if, ip-add-membership, ttl, tos, pf
See also: IP4-DATAGRAM, IP6-DATAGRAM, IP-SENDTO, IP-RECVFROM, IP-RECV, UDP-DATAGRAM
CWIP4-DATAGRAM::
Like IP-DATAGRAM, but always uses IPv4. (example)
Option groups: FD,SOCKET,IP4,RANGE
CWIP6-DATAGRAM::
Like IP-DATAGRAM, but always uses IPv6. Please note that IPv6 does not know broadcasts.
Option groups: FD,SOCKET,IP6,RANGE
CWIP-RECVFROM:
Opens a raw IP socket of . Depending on option pf, IP protocol version 4 or 6 is used. It receives
one packet from an unspecified peer and may send one or more answer packets to that peer. This mode is
particularly useful with fork option where each arriving packet - from arbitrary peers - is handled by its own
sub process. This allows a behaviour similar to typical UDP based servers like ntpd or named.
Please note that the reply packets might be fetched as incoming traffic when sender and receiver IP address
are identical because there is no port number to distinguish the sockets.
This address works well with IP-SENDTO address peers (see above). Protocol 255 uses the raw socket with
the IP header being part of the data.
Option groups: FD,SOCKET,IP4,IP6,CHILD,RANGE
Useful options: pf, fork, range, ttl, broadcast
See also: IP4-RECVFROM, IP6-RECVFROM, IP-SENDTO, IP-RECV, UDP-RECVFROM, UNIX-RECVFROM
CWIP4-RECVFROM:
Like IP-RECVFROM, but always uses IPv4.
Option groups: FD,SOCKET,IP4,CHILD,RANGE
CWIP6-RECVFROM:
Like IP-RECVFROM, but always uses IPv6.
Option groups: FD,SOCKET,IP6,CHILD,RANGE
CWIP-RECV:
Opens a raw IP socket of . Depending on option pf, IP protocol version 4 or 6 is used. It receives
packets from multiple unspecified peers and merges the data. No replies are possible. It can be, e.g.,
addressed by socat IP-SENDTO address peers. Protocol 255 uses the raw socket with the IP header being
part of the data.
Option groups: FD,SOCKET,IP4,IP6,RANGE
https://linux.die.net/man/1/socat
Page 6 of 48
Useful options: pf, range
See also: IP4-RECV, IP6-RECV, IP-SENDTO, IP-RECVFROM, UDP-RECV, UNIX-RECV
CWIP4-RECV:
Like IP-RECV, but always uses IPv4.
Option groups: FD,SOCKET,IP4,RANGE
CWIP6-RECV:
Like IP-RECV, but always uses IPv6.
Option groups: FD,SOCKET,IP6,RANGE
CWOPEN:
Opens using the CWopen() system call (example). This operation fails on UNIX domain sockets.
Note: This address type is rarly useful in bidirectional mode.
Option groups: FD,REG,NAMED,OPEN
Useful options: creat, excl, noatime, nofollow, append, rdonly, wronly, lock, readbytes, ignoreeof
See also: CREATE, GOPEN, UNIX-CONNECT
CWOPENSSL::
Tries to establish a SSL connection to [TCP service] on [IP address] using TCP/IP version 4
or 6 depending on address specification, name resolution, or option pf.
NOTE: The server certificate is only checked for validity against cafile or capath, but not for match with the
servercqs name or its IP address!
Option groups: FD,SOCKET,IP4,IP6,TCP,OPENSSL,RETRY
Useful options: cipher, method, verify, cafile, capath, certificate, key, compress, bind, pf, connect-timeout,
sourceport, retry
See also: OPENSSL-LISTEN, TCP
CWOPENSSL-LISTEN:
Listens on tcp [TCP service]. The IP version is 4 or the one specified with pf. When a connection is
accepted, this address behaves as SSL server.
Note: You probably want to use the certificate option with this address.
NOTE: The client certificate is only checked for validity against cafile or capath, but not for match with the
clientcqs name or its IP address!
Option groups: FD,SOCKET,IP4,IP6,TCP,LISTEN,OPENSSL,CHILD,RANGE,RETRY
Useful options: pf, cipher, method, verify, cafile, capath, certificate, key, compress, fork, bind, range,
tcpwrap, su, reuseaddr, retry
See also: OPENSSL, TCP-LISTEN
CWPIPE:
If already exists, it is opened. If it does not exist, a named pipe is created and opened. Beginning
with socat version 1.4.3, the named pipe is removed when the address is closed (but see option unlink-close
Note: When a pipe is used for both reading and writing, it works as echo service.
Note: When a pipe is used for both reading and writing, and socat tries to write more bytes than the pipe can
buffer (Linux 2.4: 2048 bytes), socat might block. Consider using socat option, e.g., CW-b 2048
Option groups: FD,NAMED,OPEN
Useful options: rdonly, nonblock, group, user, mode, unlink-early
See also: unnamed pipe
CWPIPE
https://linux.die.net/man/1/socat
Page 7 of 48
Creates an unnamed pipe and uses it for reading and writing. It works as an echo, because everything written
to it appeares immediately as read data.
Note: When socat tries to write more bytes than the pipe can queue (Linux 2.4: 2048 bytes), socat might
block. Consider, e.g., using option CW-b 2048
Option groups: FD
See also: named pipe
CWPROXY:::
Connects to an HTTP proxy server on port 8080 using TCP/IP version 4 or 6 depending on address
specification, name resolution, or option pf, and sends a CONNECT request for hostname:port. If the proxy
grants access and succeeds to connect to the target, data transfer between socat and the target can start. Note
that the traffic need not be HTTP but can be an arbitrary protocol.
Option groups: FD,SOCKET,IP4,IP6,TCP,HTTP,RETRY
Useful options: proxyport, ignorecr, proxyauth, resolve, crnl, bind, connect-timeout, mss, sourceport, retry
See also: SOCKS, TCP
CWPTY
Generates a pseudo terminal (pty) and uses its master side. Another process may open the ptycqs slave side
using it like a serial line or terminal. (example). If both the ptmx and the openpty mechanisms are available,
ptmx is used (POSIX).
Option groups: FD,NAMED,PTY,TERMIOS
Useful options: link, openpty, wait-slave, mode, user, group
See also: UNIX-LISTEN, PIPE, EXEC, SYSTEM
CWREADLINE
Uses GNU readline and history on stdio to allow editing and reusing input lines (example). This requires the
GNU readline and history libraries. Note that stdio should be a (pseudo) terminal device, otherwise readline
does not seem to work.
Option groups: FD,READLINE,TERMIOS
Useful options: history, noecho
See also: STDIO
CWSCTP-CONNECT::
Establishes an SCTP stream connection to the specified [IP address] and [TCP service] using
TCP/IP version 4 or 6 depending on address specification, name resolution, or option pf.
Option groups: FD,SOCKET,IP4,IP6,SCTP,CHILD,RETRY
Useful options: bind, pf, connect-timeout, tos, mtudiscover, sctp-maxseg, sctp-nodelay, nonblock,
sourceport, retry, readbytes
See also: SCTP4-CONNECT, SCTP6-CONNECT, SCTP-LISTEN, TCP-CONNECT
CWSCTP4-CONNECT::
Like SCTP-CONNECT, but only supports IPv4 protocol.
Option groups: FD,SOCKET,IP4,SCTP,CHILD,RETRY
CWSCTP6-CONNECT::
Like SCTP-CONNECT, but only supports IPv6 protocol.
Option groups: FD,SOCKET,IP6,SCTP,CHILD,RETRY
CWSCTP-LISTEN:
https://linux.die.net/man/1/socat
Page 8 of 48
Listens on [TCP service] and accepts a TCP/IP connection. The IP version is 4 or the one specified
with address option pf, socat option (-4, -6), or environment variable SOCAT_DEFAULT_LISTEN_IP. Note
that opening this address usually blocks until a client connects.
Option groups: FD,SOCKET,LISTEN,CHILD,RANGE,IP4,IP6,SCTP,RETRY
Useful options: crnl, fork, bind, range, tcpwrap, pf, max-children, backlog, sctp-maxseg, sctp-nodelay, su,
reuseaddr, retry, cool-write
See also: SCTP4-LISTEN, SCTP6-LISTEN, TCP-LISTEN, SCTP-CONNECT
CWSCTP4-LISTEN:
Like SCTP-LISTEN, but only supports IPv4 protocol.
Option groups: FD,SOCKET,LISTEN,CHILD,RANGE,IP4,SCTP,RETRY
CWSCTP6-LISTEN:
Like SCTP-LISTEN, but only supports IPv6 protocol.
Option groups: FD,SOCKET,LISTEN,CHILD,RANGE,IP6,SCTP,RETRY
CWSOCKET-CONNECT:::
Creates a stream socket using the first and second given socket parameters and CWSOCK_STREAM (see
man socket\(2)) and connects to the remote-address. The two socket parameters have to be specified by int
numbers. Consult your OS documentation and include files to find the appropriate values. The remote-address must be the data representation of a sockaddr structure without sa_family and (BSD) sa_len
components.
Please note that you can - beyond the options of the specified groups - also use options of higher level
protocols when you apply socat option -g.
Option groups: FD,SOCKET,CHILD,RETRY
Useful options: bind, setsockopt-int, setsockopt-bin, setsockopt-string
See also: TCP, UDP-CONNECT, UNIX-CONNECT, SOCKET-LISTEN, SOCKET-SENDTO
CWSOCKET-DATAGRAM::::
Creates a datagram socket using the first three given socket parameters (see man socket\(2)) and sends
outgoing data to the remote-address. The three socket parameters have to be specified by int numbers.
Consult your OS documentation and include files to find the appropriate values. The remote-address must be
the data representation of a sockaddr structure without sa_family and (BSD) sa_len components.
Please note that you can - beyond the options of the specified groups - also use options of higher level
protocols when you apply socat option -g.
Option groups: FD,SOCKET,RANGE
Useful options: bind, range, setsockopt-int, setsockopt-bin, setsockopt-string
See also: UDP-DATAGRAM, IP-DATAGRAM, SOCKET-SENDTO, SOCKET-RECV, SOCKET-RECVFROM
CWSOCKET-LISTEN:::
Creates a stream socket using the first and second given socket parameters and CWSOCK_STREAM (see
man socket\(2)) and waits for incoming connections on local-address. The two socket parameters have to be
specified by int numbers. Consult your OS documentation and include files to find the appropriate values.
The local-address must be the data representation of a sockaddr structure without sa_family and (BSD)
sa_len components.
Please note that you can - beyond the options of the specified groups - also use options of higher level
protocols when you apply socat option -g.
https://linux.die.net/man/1/socat
Page 9 of 48
Option groups: FD,SOCKET,LISTEN,RANGE,CHILD,RETRY
Useful options: setsockopt-int, setsockopt-bin, setsockopt-string
See also: TCP, UDP-CONNECT, UNIX-CONNECT, SOCKET-LISTEN, SOCKET-SENDTO, SOCKET-SENDTO
CWSOCKET-RECV::::
Creates a socket using the three given socket parameters (see man socket\(2)) and binds it to . Receives arriving data. The three parameters have to be specified by int numbers. Consult your OS
documentation and include files to find the appropriate values. The local-address must be the data
representation of a sockaddr structure without sa_family and (BSD) sa_len components.
Option groups: FD,SOCKET,RANGE
Useful options: range, setsockopt-int, setsockopt-bin, setsockopt-string
See also: UDP-RECV, IP-RECV, UNIX-RECV, SOCKET-DATAGRAM, SOCKET-SENDTO, SOCKET-RECVFROM
CWSOCKET-RECVFROM::::
Creates a socket using the three given socket parameters (see man socket\(2)) and binds it to . Receives arriving data and sends replies back to the sender. The first three parameters have to be
specified as int numbers. Consult your OS documentation and include files to find the appropriate values.
The local-address must be the data representation of a sockaddr structure without sa_family and (BSD)
sa_len components.
Option groups: FD,SOCKET,CHILD,RANGE
Useful options: fork, range, setsockopt-int, setsockopt-bin, setsockopt-string
See also: UDP-RECVFROM, IP-RECVFROM, UNIX-RECVFROM, SOCKET-DATAGRAM, SOCKET-SENDTO, SOCKET-RECV
CWSOCKET-SENDTO::::
Creates a socket using the three given socket parameters (see man socket\(2)). Sends outgoing data to the
given address and receives replies. The three parameters have to be specified as int numbers. Consult your
OS documentation and include files to find the appropriate values. The remote-address must be the data
representation of a sockaddr structure without sa_family and (BSD) sa_len components.
Option groups: FD,SOCKET
Useful options: bind, setsockopt-int, setsockopt-bin, setsockopt-string
See also: UDP-SENDTO, IP-SENDTO, UNIX-SENDTO, SOCKET-DATAGRAM, SOCKET-RECV
SOCKET-RECVFROM
CWSOCKS4:::
Connects via [IP address] to [IPv4 address] on [TCP service], using socks
version 4 protocol over IP version 4 or 6 depending on address specification, name resolution, or option pf
(example).
Option groups: FD,SOCKET,IP4,IP6,TCP,SOCKS4,RETRY
Useful options: socksuser, socksport, sourceport, pf, retry
See also: SOCKS4A, PROXY, TCP
CWSOCKS4A:::
like SOCKS4, but uses socks protocol version 4a, thus leaving host name resolution to the socks server.
Option groups: FD,SOCKET,IP4,IP6,TCP,SOCKS4,RETRY
CWSTDERR
https://linux.die.net/man/1/socat
Page 10 of 48
Uses file descriptor 2.
Option groups: FD (TERMIOS,REG,SOCKET)
See also: FD
CWSTDIN
Uses file descriptor 0.
Option groups: FD (TERMIOS,REG,SOCKET)
Useful options: readbytes
See also: FD
CWSTDIO
Uses file descriptor 0 for reading, and 1 for writing.
Option groups: FD (TERMIOS,REG,SOCKET)
Useful options: readbytes
See also: FD
CWSTDOUT
Uses file descriptor 1.
Option groups: FD (TERMIOS,REG,SOCKET)
See also: FD
CWSYSTEM:
Forks a sub process that establishes communication with its parent process and invokes the specified
program with CWsystem() . Please note that [string] must not contain cq,cq or dq!!dq, and
that shell meta characters may have to be protected. After successful program start, socat writes data to stdin
of the process and reads from its stdout.
Option groups: FD,SOCKET,EXEC,FORK,TERMIOS
Useful options: path, fdin, fdout, chroot, su, su-d, nofork, pty, stderr, ctty, setsid, pipes, sigint, sigquit
See also: EXEC
CWTCP::
Connects to [TCP service] on [IP address] using TCP/IP version 4 or 6 depending on address
specification, name resolution, or option pf.
Option groups: FD,SOCKET,IP4,IP6,TCP,RETRY
Useful options: crnl, bind, pf, connect-timeout, tos, mtudiscover, mss, nodelay, nonblock, sourceport, retry,
readbytes
See also: TCP4, TCP6, TCP-LISTEN, UDP, SCTP-CONNECT, UNIX-CONNECT
CWTCP4::
Like TCP, but only supports IPv4 protocol (example).
Option groups: FD,SOCKET,IP4,TCP,RETRY
CWTCP6::
Like TCP, but only supports IPv6 protocol.
Option groups: FD,SOCKET,IP6,TCP,RETRY
CWTCP-LISTEN:
Listens on [TCP service] and accepts a TCP/IP connection. The IP version is 4 or the one specified
with address option pf, socat option (-4, -6), or environment variable SOCAT_DEFAULT_LISTEN_IP. Note
that opening this address usually blocks until a client connects.
Option groups: FD,SOCKET,LISTEN,CHILD,RANGE,IP4,IP6,TCP,RETRY
https://linux.die.net/man/1/socat
Page 11 of 48
Useful options: crnl, fork, bind, range, tcpwrap, pf, max-children, backlog, mss, su, reuseaddr, retry, cool-write
See also: TCP4-LISTEN, TCP6-LISTEN, UDP-LISTEN, SCTP-LISTEN, UNIX-LISTEN, OPENSSL-LISTEN, TCP-CONNECT
CWTCP4-LISTEN:
Like TCP-LISTEN, but only supports IPv4 protocol (example).
Option groups: FD,SOCKET,LISTEN,CHILD,RANGE,IP4,TCP,RETRY
CWTCP6-LISTEN:
Like TCP-LISTEN, but only supports IPv6 protocol.
Additional useful option: ipv6only
Option groups: FD,SOCKET,LISTEN,CHILD,RANGE,IP6,TCP,RETRY
CWTUN[:/]
Creates a Linux TUN/TAP device and optionally assignes it the address and netmask given by the
parameters. The resulting network interface is almost ready for use by other processes; socat serves its
dqwire sidedq. This address requires read and write access to the tunnel cloning device, usually
CW/dev/net/tun , as well as permission to set some CWioctl()s. Option iff-up is required to immediately
activate the interface!
Option groups: FD,NAMED,OPEN,TUN
Useful options: iff-up, tun-device, tun-name, tun-type, iff-no-pi
See also: ip-recv
CWUDP::
Connects to [UDP service] on [IP address] using UDP/IP version 4 or 6 depending on address
specification, name resolution, or option pf.
Please note that, due to UDP protocol properties, no real connection is established; data has to be sent for
'connectingcq to the server, and no end-of-file condition can be transported.
Option groups: FD,SOCKET,IP4,IP6
Useful options: ttl, tos, bind, sourceport, pf
See also: UDP4, UDP6, UDP-LISTEN, TCP, IP
CWUDP4::
Like UDP, but only supports IPv4 protocol.
Option groups: FD,SOCKET,IP4
CWUDP6::
Like UDP, but only supports IPv6 protocol.
Option groups: FD,SOCKET,IP6
CWUDP-DATAGRAM::
Sends outgoing data to the specified address which may in particular be a broadcast or multicast address.
Packets arriving on the local socket are checked for the correct remote port and if their source addresses
match RANGE or TCPWRAP options. This address type can for example be used for implementing
symmetric or asymmetric broadcast or multicast communications.
Option groups: FD,SOCKET,IP4,IP6,RANGE
Useful options: bind, range, tcpwrap, broadcast, ip-multicast-loop, ip-multicast-ttl, ip-multicast-if, ip-add-membership, ttl, tos, sourceport, pf
https://linux.die.net/man/1/socat
Page 12 of 48
See also: UDP4-DATAGRAM, UDP6-DATAGRAM, UDP-SENDTO, UDP-RECVFROM, UDP-RECV,
UDP-CONNECT, UDP-LISTEN, IP-DATAGRAM
CWUDP4-DATAGRAM::
Like UDP-DATAGRAM, but only supports IPv4 protocol (example1, example2).
Option groups: FD,SOCKET,IP4, RANGE
CWUDP6-DATAGRAM::
Like UDP-DATAGRAM, but only supports IPv6 protocol.
Option groups: FD,SOCKET,IP6,RANGE
CWUDP-LISTEN:
Waits for a UDP/IP packet arriving on [UDP service] and 'connectscq back to sender. The accepted IP
version is 4 or the one specified with option pf. Please note that, due to UDP protocol properties, no real
connection is established; data has to arrive from the peer first, and no end-of-file condition can be
transported. Note that opening this address usually blocks until a client connects.
Option groups: FD,SOCKET,LISTEN,CHILD,RANGE,IP4,IP6
Useful options: fork, bind, range, pf
See also: UDP, UDP4-LISTEN, UDP6-LISTEN, TCP-LISTEN
CWUDP4-LISTEN:
Like UDP-LISTEN, but only support IPv4 protocol.
Option groups: FD,SOCKET,LISTEN,CHILD,RANGE,IP4
CWUDP6-LISTEN:
Like UDP-LISTEN, but only support IPv6 protocol.
Option groups: FD,SOCKET,LISTEN,CHILD,RANGE,IP6
CWUDP-SENDTO::
Communicates with the specified peer socket, defined by [UDP service] on [IP address],
using UDP/IP version 4 or 6 depending on address specification, name resolution, or option pf. It sends
packets to and receives packets from that peer socket only. This address effectively implements a datagram
client. It works well with socat UDP-RECVFROM and UDP-RECV address peers.
Option groups: FD,SOCKET,IP4,IP6
Useful options: ttl, tos, bind, sourceport, pf
See also: UDP4-SENDTO, UDP6-SENDTO, UDP-RECVFROM, UDP-RECV, UDP-CONNECT, UDP-LISTEN, IP-SENDTO
CWUDP4-SENDTO::
Like UDP-SENDTO, but only supports IPv4 protocol.
Option groups: FD,SOCKET,IP4
CWUDP6-SENDTO::
Like UDP-SENDTO, but only supports IPv6 protocol.
Option groups: FD,SOCKET,IP6
CWUDP-RECVFROM:
Creates a UDP socket on [UDP service] using UDP/IP version 4 or 6 depending on option pf. It
receives one packet from an unspecified peer and may send one or more answer packets to that peer. This
mode is particularly useful with fork option where each arriving packet - from arbitrary peers - is handled by
its own sub process. This allows a behaviour similar to typical UDP based servers like ntpd or named. This
address works well with socat UDP-SENDTO address peers.
https://linux.die.net/man/1/socat
Page 13 of 48
Option groups: FD,SOCKET,IP4,IP6,CHILD,RANGE
Useful options: fork, ttl, tos, bind, sourceport, pf
See also: UDP4-RECVFROM, UDP6-RECVFROM, UDP-SENDTO, UDP-RECV, UDP-CONNECT, UDP-LISTEN, IP-RECVFROM, UNIX-RECVFROM
CWUDP4-RECVFROM:
Like UDP-RECVFROM, but only supports IPv4 protocol.
Option groups: FD,SOCKET,IP4,CHILD,RANGE
CWUDP6-RECVFROM:
Like UDP-RECVFROM, but only supports IPv6 protocol.
Option groups: FD,SOCKET,IP6,CHILD,RANGE
CWUDP-RECV:
Creates a UDP socket on [UDP service] using UDP/IP version 4 or 6 depending on option pf. It
receives packets from multiple unspecified peers and merges the data. No replies are possible. It works well
with, e.g., socat UDP-SENDTO address peers; it behaves similar to a syslog server.
Option groups: FD,SOCKET,IP4,IP6,RANGE
Useful options: fork, pf, bind, sourceport, ttl, tos
See also: UDP4-RECV, UDP6-RECV, UDP-SENDTO, UDP-RECVFROM, UDP-CONNECT, UDP-LISTEN, IP-RECV, UNIX-RECV
CWUDP4-RECV:
Like UDP-RECV, but only supports IPv4 protocol.
Option groups: FD,SOCKET,IP4,RANGE
CWUDP6-RECV:
Like UDP-RECV, but only supports IPv6 protocol.
Option groups: FD,SOCKET,IP6,RANGE
CWUNIX-CONNECT:
Connects to assuming it is a UNIX domain socket. If does not exist, this is an error;
if is not a UNIX domain socket, this is an error; if is a UNIX domain socket, but no
process is listening, this is an error.
Option groups: FD,SOCKET,NAMED,RETRY,UNIX
) Useful options: bind
See also: UNIX-LISTEN, UNIX-SENDTO, TCP
CWUNIX-LISTEN:
Listens on using a UNIX domain stream socket and accepts a connection. If exists
and is not a socket, this is an error. If exists and is a UNIX domain socket, binding to the address
fails (use option unlink-early!). Note that opening this address usually blocks until a client connects.
Beginning with socat version 1.4.3, the file system entry is removed when this address is closed (but see
option unlink-close) (example).
Option groups: FD,SOCKET,NAMED,LISTEN,CHILD,RETRY,UNIX
Useful options: fork, umask, mode, user, group, unlink-early
See also: UNIX-CONNECT, UNIX-RECVFROM, UNIX-RECV, TCP-LISTEN
CWUNIX-SENDTO:
Communicates with the specified peer socket, defined by [] assuming it is a UNIX domain
datagram socket. It sends packets to and receives packets from that peer socket only. Please note that it might
https://linux.die.net/man/1/socat
Page 14 of 48
be neccessary to bind the local socket to an address (e.g. CW/tmp/sock1, which must not exist before). This
address type works well with socat UNIX-RECVFROM and UNIX-RECV address peers.
Option groups: FD,SOCKET,NAMED,UNIX
Useful options: bind
See also: UNIX-RECVFROM, UNIX-RECV, UNIX-CONNECT, UDP-SENDTO, IP-SENDTO
CWUNIX-RECVFROM:
Creates a UNIX domain datagram socket []. Receives one packet and may send one or more
answer packets to that peer. This mode is particularly useful with fork option where each arriving packet -
from arbitrary peers - is handled by its own sub process. This address works well with socat UNIX-SENDTO
address peers.
Option groups: FD,SOCKET,NAMED,CHILD,UNIX
Useful options: fork
See also: UNIX-SENDTO, UNIX-RECV, UNIX-LISTEN, UDP-RECVFROM, IP-RECVFROM
CWUNIX-RECV:
Creates a UNIX domain datagram socket []. Receives packets from multiple unspecified peers
and merges the data. No replies are possible. It can be, e.g., addressed by socat UNIX-SENDTO address
peers. It behaves similar to a syslog server. Option groups: FD,SOCKET,NAMED,UNIX
See also: UNIX-SENDTO, UNIX-RECVFROM, UNIX-LISTEN, UDP-RECV, IP-RECV
CWUNIX-CLIENT:
Communicates with the specified peer socket, defined by [] assuming it is a UNIX domain
socket. It first tries to connect and, if that fails, assumes it is a datagram socket, thus supporting both types.
Option groups: FD,SOCKET,NAMED,UNIX
Useful options: bind
See also: UNIX-CONNECT, UNIX-SENDTO, GOPEN
CWABSTRACT-CONNECT:
CWABSTRACT-LISTEN:
CWABSTRACT-SENDTO:
CWABSTRACT-RECVFROM:
CWABSTRACT-RECV:
CWABSTRACT-CLIENT:
The ABSTRACT addresses are almost identical to the related UNIX addresses except that they do not
address file system based sockets but an alternate UNIX domain address space. To archieve this the socket
address strings are prefixed with dq\0dq internally. This feature is available (only?) on Linux. Option groups
are the same as with the related UNIX addresses, except that the ABSTRACT addresses are not member of
the NAMED group.
Address Options
Address options can be applied to address specifications to influence the process of opening the addresses and the
properties of the resulting data channels.
For technical reasons not every option can be applied to every address type; e.g., applying a socket option to a
regular file will fail. To catch most useless combinations as early as in the open phase, the concept of option groups
https://linux.die.net/man/1/socat
Page 15 of 48
was introduced. Each option belongs to one or more option groups. Options can be used only with address types that
support at least one of their option groups (but see option -g).
Address options have data types that their values must conform to. Every address option consists of just a keyword
or a keyword followed by dq=valuedq, where value must conform to the options type. Some address options
manipulate parameters of system calls; e.g., option sync sets the CWO_SYNC flag with the CWopen() call. Other
options cause a system or library call; e.g., with option 'ttl=valuecq the CWsetsockopt(fd, SOL_IP, IP_TTL, value,
sizeof(int)) call is applied. Other options set internal socat variables that are used during data transfer; e.g., 'crnlcq
causes explicit character conversions. A few options have more complex implementations; e.g., su-d (substuser-delayed) inquires some user and group infos, stores them, and applies them later after a possible CWchroot() call.
If multiple options are given to an address, their sequence in the address specification has (almost) no effect on the
sequence of their execution/application. Instead, socat has built in an option phase model that tries to bring the
options in a useful order. Some options exist in different forms (e.g., unlink, unlink-early, unlink-late) to control the
time of their execution.
If the same option is specified more than once within one address specification, with equal or different values, the
effect depends on the kind of option. Options resulting in function calls like CWsetsockopt() cause multiple
invocations. With options that set parameters for a required call like CWopen() or set internal flags, the value of the
last option occurrence is effective.
The existence or semantics of many options are system dependent. Socat usually does NOT try to emulate missing
libc or kernel features, it just provides an interface to the underlying system. So, if an operating system lacks a
feature, the related option is simply not available on this platform.
The following paragraphs introduce just the more common address options. For a more comprehensive reference
and to find information about canonical option names, alias names, option phases, and platforms see file xio.help.
FD option group
This option group contains options that are applied to a UN*X style file descriptor, no matter how it was generated.
Because all current socat address types are file descriptor based, these options may be applied to any address.
Note: Some of these options are also member of another option group, that provides an other, non-fd based
mechanism. For these options, it depends on the actual address type and its option groups which mechanism is used.
The second, non-fd based mechanism is prioritized.
CWcloexec=
Sets the CWFD_CLOEXEC flag with the CWfcntl() system call to value . If set, the file descriptor is
closed on CWexec() family function calls. Socat internally handles this flag for the fds it controls, so in most
cases there will be no need to apply this option.
CWsetlk
Tries to set a discretionary write lock to the whole file using the CWfcntl(fd, F_SETLK, ...) system call. If
the file is already locked, this call results in an error. On Linux, when the file permissions for group are
dqSdq (g-x,g+s), and the file system is locally mounted with the dqmanddq option, the lock is mandatory, i.e.
prevents other processes from opening the file.
CWsetlkw
https://linux.die.net/man/1/socat
Page 16 of 48
Tries to set a discretionary waiting write lock to the whole file using the CWfcntl(fd, F_SETLKW, ...) system
call. If the file is already locked, this call blocks. See option setlk for information about making this lock
mandatory.
CWsetlk-rd
Tries to set a discretionary read lock to the whole file using the CWfcntl(fd, F_SETLK, ...) system call. If the
file is already write locked, this call results in an error. See option setlk for information about making this
lock mandatory.
CWsetlkw-rd
Tries to set a discretionary waiting read lock to the whole file using the CWfcntl(fd, F_SETLKW, ...) system
call. If the file is already write locked, this call blocks. See option setlk for information about making this
lock mandatory.
CWflock-ex
Tries to set a blocking exclusive advisory lock to the file using the CWflock(fd, LOCK_EX) system call.
Socat hangs in this call if the file is locked by another process.
CWflock-ex-nb
Tries to set a nonblocking exclusive advisory lock to the file using the CWflock(fd, LOCK_EX|LOCK_NB)
system call. If the file is already locked, this option results in an error.
CWflock-sh
Tries to set a blocking shared advisory lock to the file using the CWflock(fd, LOCK_SH) system call. Socat
hangs in this call if the file is locked by another process.
CWflock-sh-nb
Tries to set a nonblocking shared advisory lock to the file using the CWflock(fd, LOCK_SH|LOCK_NB)
system call. If the file is already locked, this option results in an error.
CWlock
Sets a blocking lock on the file. Uses the setlk or flock mechanism depending on availability on the
particular platform. If both are available, the POSIX variant (setlkw) is used.
CWuser=
Sets the (owner) of the stream. If the address is member of the NAMED option group, socat uses the
CWchown() system call after opening the file or binding to the UNIX domain socket (race condition!).
Without filesystem entry, socat sets the user of the stream using the CWfchown() system call. These calls
might require root privilege.
CWuser-late=
Sets the owner of the fd to with the CWfchown() system call after opening or connecting the channel.
This is useful only on file system entries.
CWgroup=
Sets the of the stream. If the address is member of the NAMED option group, socat uses the
CWchown() system call after opening the file or binding to the UNIX domain socket (race condition!).
Without filesystem entry, socat sets the group of the stream with the CWfchown() system call. These calls
might require group membership or root privilege.
CWgroup-late=
Sets the group of the fd to with the CWfchown() system call after opening or connecting the
channel. This is useful only on file system entries.
CWmode=
https://linux.die.net/man/1/socat
Page 17 of 48
Sets the [mode_t] (permissions) of the stream. If the address is member of the NAMED option
group and uses the CWopen() or CWcreat() call, the mode is applied with these. If the address is member of
the NAMED option group without using these system calls, socat uses the CWchmod() system call after
opening the filesystem entry or binding to the UNIX domain socket (race condition!). Otherwise, socat sets
the mode of the stream using CWfchmod() . These calls might require ownership or root privilege.
CWperm-late=
Sets the permissions of the fd to value [mode_t] using the CWfchmod() system call after opening or
connecting the channel. This is useful only on file system entries.
CWappend=
Always writes data to the actual end of file. If the address is member of the OPEN option group, socat uses
the CWO_APPEND flag with the CWopen() system call (example). Otherwise, socat applies the
CWfcntl(fd, F_SETFL, O_APPEND) call.
CWnonblock=
Tries to open or use file in nonblocking mode. Its only effects are that the CWconnect() call of TCP
addresses does not block, and that opening a named pipe for reading does not block. If the address is member
of the OPEN option group, socat uses the CWO_NONBLOCK flag with the CWopen() system call.
Otherwise, socat applies the CWfcntl(fd, F_SETFL, O_NONBLOCK) call.
CWbinary
Opens the file in binary mode to avoid implicit line terminator conversions (Cygwin).
CWtext
Opens the file in text mode to force implicit line terminator conversions (Cygwin).
CWnoinherit
Does not keep this file open in a spawned process (Cygwin).
CWcool-write
Takes it easy when write fails with EPIPE or ECONNRESET and logs the message with notice level instead
of error. This prevents the log file from being filled with useless error messages when socat is used as a high
volume server or proxy where clients often abort the connection.
This option is experimental.
CWend-close
Changes the (address dependent) method of ending a connection to just close the file descriptors. This is
useful when the connection is to be reused by or shared with other processes (example).
Normally, socket connections will be ended with CWshutdown(2) which terminates the socket even if it is
shared by multiple processes. CWclose(2) dqunlinksdq the socket from the process but keeps it active as
long as there are still links from other processes.
Similarly, when an address of type EXEC or SYSTEM is ended, socat usually will explicitely kill the sub
process. With this option, it will just close the file descriptors.
CWshut-none
Changes the (address dependent) method of shutting down the write part of a connection to not do anything.
CWshut-down
Changes the (address dependent) method of shutting down the write part of a connection to CWshutdown\
(fd, SHUT_WR). Is only useful with sockets.
CWshut-close
Changes the (address dependent) method of shutting down the write part of a connection to CWclose\(fd).
https://linux.die.net/man/1/socat
Page 18 of 48
CWshut-null
When one address indicates EOF, socat will send a zero sized packet to the write channel of the other
address to transfer the EOF condition. This is useful with UDP and other datagram protocols. Has been
tested against netcat and socat with option null-eof.
CWnull-eof
Normally socat will ignore empty (zero size payload) packets arriving on datagram sockets, so it survives
port scans. With this option socat interprets empty datagram packets as EOF indicator (see shut-null).
CWioctl-void=
Calls CWioctl() with the request value as second argument and NULL as third argument. This option allows
to utilize ioctls that are not explicitely implemented in socat.
CWioctl-int=:
Calls CWioctl() with the request value as second argument and the integer value as third argument.
CWioctl-intp=:
Calls CWioctl() with the request value as second argument and a pointer to the integer value as third
argument.
CWioctl-bin=:
Calls CWioctl() with the request value as second argument and a pointer to the given data value as third
argument. This data must be specified in form.
CWioctl-string=:
Calls CWioctl() with the request value as second argument and a pointer to the given string as third
argument. form.
NAMED option group
These options work on file system entries.
See also options user, group, and mode.
CWuser-early=
Changes the (owner) of the file system entry before accessing it, using the CWchown() system call.
This call might require root privilege.
CWgroup-early=
Changes the of the file system entry before accessing it, using the CWchown() system call. This
call might require group membership or root privilege.
CWperm-early=
Changes the [mode_t] of the file system entry before accessing it, using the CWchmod() system
call. This call might require ownership or root privilege.
CWumask=
Sets the umask of the process to [mode_t] before accessing the file system entry (useful with UNIX
domain sockets!). This call might affect all further operations of the socat process!
CWunlink-early
Unlinks (removes) the file before opening it and even before applying user-early etc.
CWunlink
Unlinks (removes) the file before accessing it, but after user-early etc.
CWunlink-late
https://linux.die.net/man/1/socat
Page 19 of 48
Unlinks (removes) the file after opening it to make it inaccessible for other processes after a short race
condition.
CWunlink-close
Removes the addresses file system entry when closing the address. For named pipes, listening unix domain
sockets, and the symbolic links of pty addresses, the default is 1; for created files, opened files, generic
opened files, and client unix domain sockets the default is 0.
OPEN option group
The OPEN group options allow to set flags with the CWopen() system call. E.g., option 'creatcq sets the
CWO_CREAT flag.
See also options append and nonblock.
CWcreat=
Creates the file if it does not exist (example).
CWdsync=
Blocks CWwrite() calls until metainfo is physically written to media.
CWexcl=
With option creat, if file exists this is an error.
CWlargefile=
On 32 bit systems, allows a file larger than 2^31 bytes.
CWnoatime
Sets the O_NOATIME options, so reads do not change the access timestamp.
CWnoctty=
Does not make this file the controlling terminal.
CWnofollow=
Does not follow symbolic links.
CWnshare=
Does not allow to share this file with other processes.
CWrshare=
Does not allow other processes to open this file for writing.
CWrsync=
Blocks CWwrite() until metainfo is physically written to media.
CWsync=
Blocks CWwrite() until data is physically written to media.
CWrdonly=
Opens the file for reading only.
CWwronly=
Opens the file for writing only.
CWtrunc
Truncates the file to size 0 during opening it.
REG and BLK option group
https://linux.die.net/man/1/socat
Page 20 of 48
These options are usually applied to a UN*X file descriptor, but their semantics make sense only on a file
supporting random access.
CWseek=
Applies the CWlseek(fd, , SEEK_SET) (or CWlseek64 ) system call, thus positioning the file
pointer absolutely to [off_t or off64_t]. Please note that a missing value defaults to 1, not 0.
CWseek-cur=
Applies the CWlseek(fd, , SEEK_CUR) (or CWlseek64 ) system call, thus positioning the file
pointer [off_t or off64_t] bytes relatively to its current position (which is usually 0). Please note that
a missing value defaults to 1, not 0.
CWseek-end=
Applies the CWlseek(fd, , SEEK_END) (or CWlseek64 ) system call, thus positioning the file
pointer [off_t or off64_t] bytes relatively to the files current end. Please note that a missing value
defaults to 1, not 0.
CWftruncate=
Applies the CWftruncate(fd, ) (or CWftruncate64 if available) system call, thus truncating the file at
the position [off_t or off64_t]. Please note that a missing value defaults to 1, not 0.
CWsecrm=
CWunrm=
CWcompr=
CWext2-sync=
CWimmutable=
CWext2-append=
CWnodump=
CWext2-noatime=
CWjournal-data=
CWnotail=
CWdirsync=