Troubleshooting a TCP handoff often needs more than a port-open result because a scanner can prove that a socket accepts connections without showing what the other side receives. Netcat can run one terminal as a listener and another as a client so the test message appears at the receiving end.
A listener bound to 127.0.0.1:9000 accepts one client connection, prints the line it receives, and exits after the client closes the socket. The same pattern can test a remote host by replacing the loopback address with the target host when firewall and routing rules allow the connection.
OpenBSD Netcat from the netcat-openbsd package on Ubuntu 26.04 accepts this command form. The -N option on the client closes the socket after stdin reaches EOF; if another Netcat build lacks -N, use an interactive client and press Ctrl-D after typing the test line.
Related: How to install Netcat on Ubuntu
Related: How to test a TCP port with Netcat
Related: How to create a TCP listener with Netcat
Steps to use Netcat for a basic TCP test:
- Start a TCP listener in the first terminal.
$ nc -l 127.0.0.1 9000
The listener waits for one client connection on 127.0.0.1 port 9000. Leave this terminal open while sending the test line from another terminal.
- Send a test line from the second terminal.
$ printf 'hello from netcat\n' | nc -N 127.0.0.1 9000
-N closes the client socket after the piped input reaches EOF on OpenBSD Netcat, allowing the listener to finish after receiving the line.
- Confirm that the first terminal prints the same line.
$ nc -l 127.0.0.1 9000 hello from netcat
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.