# nmap -sT -O localhost
Starting Nmap 6.47 ( http://nmap.org ) at 2014-09-25 19:50 EDT
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000076s latency).
Other addresses for localhost (not scanned): 127.0.0.1
rDNS record for 127.0.0.1: localhost.localdomain
Not shown: 998 closed ports
PORT STATE SERVICE
111/tcp open rpcbind
3306/tcp open mysql
Device type: general purpose
Running: Linux 3.X
OS CPE: cpe:/o:linux:linux_kernel:3
OS details: Linux 3.7 - 3.15
Network Distance: 0 hops
OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 1.79 seconds
If your system returns an unknown port (under Service) first check if your port is associated with a service in /etc/services
# cat /etc/services | grep <port_number>
Ex:
# cat /etc/services | grep 3306
mysql 3306/tcp
mysql 3306/udp
If it isn't, use lsof or ss (the netstat successor)
#lsof -i | grep <port_number>
# ss | grep <port_number>
SS is also a good tool for showing the listening sockets:
# ss -ltn
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::3306 :::*