I'm trying to test if a service is up and running using nc.

echo ruok | nc 5111

But I get this response:

This is nc from the netcat-openbsd package. An alternative nc is available
in the netcat-traditional package.
usage: nc [-46DdhklnrStUuvzC] [-i interval] [-P proxy_username] [-p source_port]
      [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]
      [-x proxy_address[:port]] [hostname] [port[s]]

I'm not sure how to use this 'alternative nc', can someone please explain this to me?

I tried:

echo ruok | nc -s -p 5111  

but I got the same message.


You have the right nc. You may verify that by entering apt-cache policy netcat which should give you the installed and candidate versions for netcat.
The response you get suggests that you haven't entered the command correctly, so please verify that you tried the command just as stated above. If no process is running on your localhost at port 5111, you will receive no output.
The version with the -s and -p parameters works differently though. These are the source address and port parameters, respectively, not the target address and port. As you haven't specified a target, nothing is sent in this case.

| improve this answer | |
  • So what is the correct command format then? I'm confused b/c the first one didn't work so I tried -p and -s. – Blankman Jun 18 '14 at 14:14
  • The first command you gave: echo ruok | nc 5111 is in fact the right command format. Fortunately, nc is very easy to test. In one terminal, enter: nc -l 5111. This will start a process that listens on port 5111 for incoming packets. In another terminal window, enter the command above. You should see the string "ruok" appear in the first terminal. – Jos Jun 18 '14 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.