Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
I prefer "netstat -tlnp", since it only lists the listening ports. – Janne Pikkarainen Aug 26 '10 at 7:02

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

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

Your Answer


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