Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to know which ports are open on my ubuntu machine.

I just want to initially block all ports in iptables

and then slowly and slowly will open only those ports which i need. Currenly i have no idea how many services have opened their ports on my system

any idea to know

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Two ways I do it are:

  • lsof -i (listed open files, a network socket counts as a file and that's what the -i flag specifies)
  • netstat -antp
share|improve this answer
    
i think i also have vsftp server running but i can't see any port 21 in netstat ouput. i am using ftp via ssh ,does it means that it will come under ssh or port 21 –  John Aug 26 '10 at 4:41
1  
I prefer "netstat -tlnp", since it only lists the listening ports. –  Janne Pikkarainen Aug 26 '10 at 7:02

netstat -l

will list all open ports as well as the address it's listening on. You may have to resolve names to port numbers. The list of associations is found in /etc/services.

You might also want to check out the man page on netstat. There may be other options you want to add to the command.

man netstat

share|improve this answer

netstat -tunpl will tell you the numbers of tcp and udp ports that are being listened on.and what process is listening on each one (so you can tell whether you want it to do so or not).

The manpage has further options that may be of interest.

share|improve this answer

Your Answer

 
discard

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