How to get a list of open ports in Linux?

So you have set up a very secured server but still don't you want to cross check if the machine is really secured and your server has not been compromised by anyone. If is always better to regularly scan your system with open ports and list of connected machines.
For this blog I will show you the command to get a list of open ports in any machine

NOTE:

On RHEL system you must have an active subscription to RHN or you can configure a local offline repository using which "yum" package manager can install the provided rpm and it's dependencies.
# yum install nmap

Once installed verify the package

# rpm -qa | grep nmap
nmap-5.51-2.el6.i686

Execute nmap in the below format for testing on localhost

# nmap localhost
Starting Nmap 5.51 ( http://nmap.org ) at 2013-09-18 12:04 IST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0000080s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 995 closed ports
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
111/tcp open rpcbind
631/tcp open ipp
5989/tcp open wbem-https
Nmap done: 1 IP address (1 host up) scanned in 0.29 seconds

Here as you can see I got a long list of opened ports on my machine.

Go ahead and try the same on your machine.