Linux port scanning with netcat (nc) command

by on July 12, 2007 · 4 comments· LAST UPDATED August 12, 2007

in , ,

Q. How do I find out which ports are opened on my own server? How do I run port scanning using nc command?

A. It may be useful to know which ports are open and running services on a target machine. You can use nmap command for port scanning.

How do I use nc to scan Linux / UNIX / Windows server port scanning?

If nmap is not installed try nc / netcat command. The -z flag can be used to tell nc to report open ports, rather than initiate a connection.

Run nc command with -z flag. You need to specify host name / ip along with the port range to limit and speedup operation.
$ nc -z 1-1023

Connection to localhost 25 port [tcp/smtp] succeeded!
Connection to 25 port [tcp/smtp] succeeded!
Connection to 80 port [tcp/http] succeeded!
Connection to 143 port [tcp/imap] succeeded!
Connection to 199 port [tcp/smux] succeeded!
Connection to 783 port [tcp/*] succeeded!
Connection to 904 port [tcp/vmware-authd] succeeded!
Connection to 993 port [tcp/imaps] succeeded!

See also

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 4 comments… read them below or add one }

1 Paul August 20, 2012 at 1:32 pm

I had to add verbosity (-v) to get the output as above. By default my version displayed nothing. (Talking of that, I couldn’t figure out how to get it’s version…)


2 Sandeep March 20, 2013 at 2:55 pm


I run this command on my ubuntu server but I am not getting that kind of output as you provided here. When I am using -z option that time it is not giving any kind of output. If use -t or option then it is giving output for port range 1-100 .. output is :SSH-2.0-OpenSSH_5.1p1 Debian-5ubuntu1 only.

I.e it is scanning for port 22 only.

Could you please tell me why options are not running on Ubuntu ?


3 Allen March 21, 2013 at 9:57 pm

I had to add -v for it to work for me

nc -z -v 22
Connection to 22 port [tcp/ssh] succeeded!


4 Tom October 31, 2013 at 4:58 pm

nc -zv server port
for lazy ones .)


Leave a Comment

Tagged as: , , , ,

Previous Faq:

Next Faq: