Local daemons sometimes expose a Unix-domain socket instead of a TCP host and port, so a normal nc 127.0.0.1 9000 probe cannot reach them. Netcat can connect to the socket pathname directly when the installed implementation supports the -U option.
OpenBSD Netcat from netcat-openbsd on Ubuntu 26.04 accepts this command form. A one-shot listener creates /tmp/netcat-demo.sock, a client sends one test line to that pathname, and -N closes the client side after the piped input reaches end-of-file.
The command form uses a stream Unix socket. Add -u only when the target service documents a datagram socket, and avoid sending state-changing protocol messages to a production socket unless the service owner has confirmed the request is safe.
Steps to connect to a Unix socket with Netcat:
- Check that the active Netcat build supports Unix-domain sockets.
$ nc -h OpenBSD netcat (Debian patchlevel 1.234-1) usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl] ##### snipped ##### -U Use UNIX domain socket ##### snipped #####
If the help text does not show -U, install OpenBSD Netcat before continuing.
Related: How to install Netcat on Ubuntu
- Start a one-shot Unix socket listener in the first terminal.
$ nc -lU /tmp/netcat-demo.sock
The listener creates /tmp/netcat-demo.sock and waits for one client connection. Leave this terminal open while sending the test line from another terminal.
- Confirm that the socket file appeared from the second terminal.
$ ls -l /tmp/netcat-demo.sock srwxr-xr-x 1 root root 0 Jun 7 23:58 /tmp/netcat-demo.sock
The leading s in the file mode marks the path as a socket, not a regular file.
- Send a test payload to the socket from the second terminal.
$ printf 'unix socket check\n' | nc -N -U /tmp/netcat-demo.sock
-N lets the listener finish after printf reaches end-of-file.
- Confirm that the first terminal printed the payload.
$ nc -lU /tmp/netcat-demo.sock unix socket check
The matching line confirms that Netcat reached the Unix-domain socket path.
- Remove the temporary socket file.
$ rm -f /tmp/netcat-demo.sock
Do not remove a production service socket. Deleting its pathname can break local clients until the daemon recreates it.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.