Let's say, i'd like to know whether certain port (e.g. 21) is open or closed.
What is the best shell command for that?
Let's say, i'd like to know whether certain port (e.g. 21) is open or closed.
What is the best shell command for that?
My favorites are:
From a local machine
sudo lsof -i -n -P
netstat -an | grep LISTEN | grep -v ^unix
netstat -ntulp
From a remote box
nmap -v -A ip_address
netstat
will tell you this. To check for all open (listening) ports:
netstat -l
You can also show all current connections:
netstat -an
See the manpage for loads more, netstat is a very powerful tool :)
nmap -A -T4 localhost -p 80
It even shows you OS version and the service on that port
sudo apt-get install nmap
and also nmap is used in the matrix movie
Dec 14, 2011 at 22:27
You can use telnet
to try to connect to a TCP port on a give host:
telnet somehost.example.com 21
tries to connect to port 21 on somehost.example.com
If the port is closed you get a message like
telnet: Unable to connect to remote host: Connection refused
otherwise you'll see whatever the program listening on that port tells you on connect.