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.

Steps to use Netcat for a basic TCP test:

  1. 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.

  2. 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.

  3. Confirm that the first terminal prints the same line.
    $ nc -l 127.0.0.1 9000
    hello from netcat