LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-10-2018, 12:33 AM   #1
catiewong
Member
 
Registered: Aug 2018
Posts: 190

Rep: Reputation: Disabled
How to check a port is open or not


If I would like to confirm a port eg . port 111 is open to connect or not , I just use "netstat -na" to find it , if it is in "Listen" , then means it is open ?

or if I "telnet localhost 111" , if it pops the below message , then mean it is opened ?

Code:
Trying ::1...
Connected to localhost.
Escape character is '^]'.
 
Old 12-10-2018, 01:08 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
"port open" usually means that no firewall blocks it. When a port is blocked by a firewall, all attempts to connect to it will simply be ignored.

The firewall can be on your server. You can check with the iptables command or, if your distro deploys it, firewall-cmd.

The firewall can be around your server, for example using a firewall appliance or, in an Amazon or OpenStack cloud, using security groups. I don't know of a method to check this from the server.

From outside, a command like telnet or nc can tell you if the port is open. In your example however, you use telnet on the same server as the port. You confirm that a process is listening on port 111, but you don't confirm whether the port is blocked. You have to run telnet or nc from a remote system to confirm this.

If your telnet or nc connection attempt succeeds, you know that the port is open and a process is listening.
If you get "connection refused", you know that the port is open but no process listens.
If you get a message like "no route to host", the server is either not accessible at all (it may be down or there is literally no route to it) or that particular port is blocked. You can then use a tool like ping to check if there is any connectivity.

I am sure nmap is also useful for such tests, but I don't know how to use it in this context.
 
Old 12-10-2018, 04:01 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
in general: if there was a program running on the system which is listening on that port (=waiting for some kind of data) we used to say the port is open.
But it is not that trivial, because we can have firewalls, proxy servers, port mapping and other tricks which may make that port unavailable or available (depending on their config/usage). So port is opened does/may not mean it is reachable from another host.

Last edited by pan64; 12-10-2018 at 04:03 AM.
 
Old 12-11-2018, 07:28 AM   #4
Sakralbar
LQ Newbie
 
Registered: Dec 2018
Posts: 3

Rep: Reputation: Disabled
May be this help you https://portchecker.co/
 
Old 12-11-2018, 07:44 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Sakralbar View Post
May be this help you <BAD ADVICE LINK REMOVED>
Sorry, but this is a VERY bad bit of advice; why would anyone go to an unknown website and run something to scan their system for open ports?? You're advertising to some unknown parties what your IP address is, what ports/services are running, etc.
 
1 members found this post helpful.
Old 12-11-2018, 07:47 AM   #6
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153
Code:
sudo nmap -p 111 127.0.0.1
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Check port open status for port 443 asteroid4u Linux - Server 8 07-06-2017 09:56 PM
[SOLVED] iptables port forward not working for port range mapping to anohter Port range in Linux 2.6.39 kinghong66 Linux - Networking 2 06-17-2015 07:17 PM
[SOLVED] iptables: verify traffic on port to check if it is legitimate for that port. lievendp Linux - Security 5 04-18-2011 08:00 AM
Partition check, check double check Vincentius Linux - General 0 12-25-2004 05:47 AM
Boot disk; check. CD in drive; check. Doesn't work; check. Hal DamnSmallLinux 7 02-04-2004 02:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration