0

I want to check if a set of ports are opened or closed on some remote servers. I went through various discussions on the subject and most of the people suggested to use nmap, nc and telnet <server-ip-address> <port-no>. How can I differentiate these three cases:

  • The port is closed on firewall
  • The port is open but no service is listening on the port
  • The port is open and some service is also listening on it
  • If port is open on firewall and no service is listening on it, telnet will return "connection timeout". I don't know what makes you cosider this as "not useful" – user1700494 Jan 25 '16 at 10:34
  • If port is open on firewall and no service is listening on it, then telnet <ip address> <port-no> would return "connection refused". Yes, after reading the answer below and your comment, I tried it again and it's giving the results as expected. Thanks – user2436428 Jan 25 '16 at 14:13
5

well if you use telnet command to check the port connectivity, it will show

  • "connection timeout" if the port is blocked by the firewall
  • "Connection refused" if the service is down/not listening on specified port, but port is reachable.
  • "connected to server_ip" if connection is successful
3

Useful utilities :

  • 1.Telnet

  • 2.nc

  • 3.nmap

Scenario: For checking remote system tcp 80 port status

Usage :

telnet myserver.com 80 
nc -v myserver.com 80
nmap myserver.com 80 

Response Analysis :

if you get a time out or deny : the port is not open

suppose if you get "Connection refused" : then port is open but process is not listerning

If you get a connection successful : Port is open and process is listen

Solution:

start/restart the listening process (if connection refused)

Ask network team to monitor the connection we can confirm whether it is blocked from intermediate network firewall or from server firewall/iptables

Note :

  • Suppose firewall configured to Reject packets instead of Drop then u will get "connection refused" error , so here in this case we can't ensure wheteher process is listern or not.

For checking udp port (like ntp) you can use below nc option

nc -uzv yourserver.com 123

2

Although telnet or netcat can be used to determine port reachability, nmap is the standard port scanning tool.

The nmap default option (TCP SYN scan) determines if a given port is filtered or not by a firewall.

nmap -sS <host> -p <port> 

If you want a reliable differentiation between the open, closed, and filtered states, use the -sY option (SCTP INIT scan)

nmap -sY <host> -p <port>

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.