How can I communicate with a Unix domain socket via the shell on Debian Squeeze?

With socat (a 'bidirectional data relay between two data channels') you can connect to the unix domain socket like this:

$ socat - UNIX-CONNECT:/tmp/memcached.sock

With netcat-openbsd, there is a -U option. If you don't have it, you probably have netcat-traditional installed instead; I'd suggest switching.

Example command: nc -U /var/run/socket


netcat-openbsd supports connecting to UNIX-domain sockets. Using this you can connect to either a UNIX-domain stream socket or a UNIX-domain datagram socket, and therefore you have to tell the socket's type to netcat.

for example, /dev/log file in Linux is a UNIX-domain datagram socket socket, thus nc -U /dev/log won't work. Instead use nc -uU /dev/log. Using -u along with -U tells netcat that it is a UNIX-domain datagram socket.

nc -U /tmp/socket  #Connect to UNIX-domain stream socket
nc -uU /tmp/socket #Connect to UNIX-domain datagram socket


Similarly, while using socat, use UNIX-CLIENT option. Using this option you can connect to both UNIX-domain stream and UNIX-domain datagram sockets. From its man page (man socat), "It first tries to connect and, if that fails, assumes it is a datagram socket, thus supporting both types".

socat - UNIX-CLIENT:/dev/socket #connect to UNIX-domain socket, irrespective of its type