nmap says port is closed while nestat says it's listening

Shengjie picture Shengjie · Aug 10, 2012 · Viewed 14k times · Source

This is Ubuntu 12.04 env. I have a TCP service running on port 8020 on the box:

My question is:

Why port 8020 is not discovered in nmap as an open port while nestat says it's listening?

if i run

netstat -tuplen

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User           Inode       PID/Program name
tcp        0      0 127.0.0.1:9001          0.0.0.0:*               LISTEN      0          10564       1917/python    
tcp        0      0 127.0.0.1:8020          0.0.0.0:*               LISTEN      117        29259       4448/java       

But if i run

nmap -v -sT 127.0.0.1

Starting Nmap 5.21 ( http://nmap.org ) at 2012-08-10 08:51 PDT
Initiating Connect Scan at 08:51
Scanning localhost (127.0.0.1) [1000 ports]
Discovered open port 53/tcp on 127.0.0.1
Discovered open port 22/tcp on 127.0.0.1
Discovered open port 9000/tcp on 127.0.0.1
Discovered open port 631/tcp on 127.0.0.1
Discovered open port 9001/tcp on 127.0.0.1
Completed Connect Scan at 08:51, 0.04s elapsed (1000 total ports)
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00046s latency).
rDNS record for 127.0.0.1: hadoop-namenode-01
Not shown: 995 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
53/tcp   open  domain
631/tcp  open  ipp
9000/tcp open  cslistener
9001/tcp open  tor-orport

Read data files from: /usr/share/nmap
Nmap done: 1 IP address (1 host up) scanned in 0.10 seconds
       Raw packets sent: 0 (0B) | Rcvd: 0 (0B)

Answer

Satish picture Satish · Aug 10, 2012

By default nmap doesn't scan all ports. try this one.

nmap -sT -sU -p- 127.0.0.1