Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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 need a command to list all open ports in my PC, and another command to close a port.

Any suggestions?

I need to close some applications' port.

share|improve this question
up vote 14 down vote accepted

netstat can be used to see the ports stat.

sudo netstat -lnp

To list all listening ports numbers with the process responsible on each one. Terminate or kill the process to close port. (kill, pkill ...)

Without process termination, It is not possible! . See Manually closing a port from commandline. Other way you may look for a firewall solution (as isolating that port from network)

share|improve this answer
i need to close the port but without killing the application – nux Jan 24 '14 at 19:15

You can use iptables to block the port on the network level without having to close the application. The port would still appear open, but will be unreachable.

alternatively, this is dependent on the application, some permit to disable some port ( think dovecot and the pop3 or imap port ), and some cannot. Some application can also be configured to listen only on localhost or a specific address.

share|improve this answer

You can use netstat -nalp and lsof -i:port tools to identify process/binaries behind open port.

If you want to close port you have to kill process or stop relative service.If you want run services only for your local box you can configure respective service to listen on localhost/ not on all available ( ips.

share|improve this answer
sudo ufw allow 22

sudo ufw deny 22
share|improve this answer

Your Answer


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.