4

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

echo ruok | nc 127.0.0.1 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 127.0.0.1 -p 5111  

but I got the same message.

Avinash Raj
  • 77,204
  • 56
  • 214
  • 254
Blankman
  • 8,095
  • 14
  • 38
  • 39

1 Answers1

5

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.

Jos
  • 28,156
  • 8
  • 82
  • 88
  • 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 127.0.0.1 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