Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I would like to see what ports are open on my machine, e.g. what ports my machine is listening on. E.g. port 80 if I have installed a web server, and so on.

Is there any command for this?

share|improve this question
add comment

3 Answers

up vote 12 down vote accepted

nmap Install nmap

Nmap ("Network Mapper") is a free and open source utility for network exploration or security auditing

nmap 192.168.1.33 internal Pc or nmap external ip address

more information man nmap

share|improve this answer
    
Thanks, nmap localhost worked great. –  Jonas Oct 25 '10 at 13:24
2  
Remember that there is a difference between nmap localhost and nmap 192.168.0.3 (or what ever you machine IP is) –  Source Lab Oct 25 '10 at 14:47
    
If you want a nice GUI for nmap, you can try 'zenmap'. –  htorque Oct 28 '10 at 11:17
    
I think netstat is a better answer to this. netstat will list what the system is listening on directly, and without using an additional application or doing unnecessary calls over localhost or thought the network. –  Mathieu Trudel-Lapierre Nov 3 '10 at 1:57
    
@Mathieu: I agree with that. I change my accepted answer. –  Jonas May 27 '11 at 14:44
add comment

Other good ways to find out what ports are listenting and what your firewall rules are:

  • sudo netstat -tulpn

  • sudo ufw status

share|improve this answer
    
I change the answer to nmap again, the usability of netstat is crap. –  Jonas Mar 23 at 17:28
add comment

To list open ports use the netstat command.

For example:

    $ sudo netstat -tulpn | grep LISTEN
    tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      5452/dnsmasq    
    tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1037/cupsd      
    tcp6       0      0 ::1:631                 :::*                    LISTEN      1037/cupsd

In the above example three services are bound to the loopback address.

IPv4 services bound to the loopback address "127.0.0.1" are only available on the local machine. The equivalent loopback address for IPv6 is "::1". The IPv4 address "0.0.0.0" means "any IP address", which would mean that other machines could potentially connect to any of the locally configured network interfaces on the specific port.

Another method is to use the lsof command:

    $ sudo lsof -nP -i | grep LISTEN
    cupsd     1037   root    9u  IPv6  11276      0t0  TCP [::1]:631 (LISTEN)
    cupsd     1037   root   10u  IPv4  11277      0t0  TCP 127.0.0.1:631 (LISTEN)
    dnsmasq   5452 nobody    5u  IPv4 212707      0t0  TCP 127.0.0.1:53 (LISTEN)

For more details see man netstat or man lsof.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.