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 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

4 Answers 4

up vote 11 down vote accepted

netstat can be used to see the ports stat.

sudo netstat -lnp

To list all listening ports with processes responsible on them. 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 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/127.0.0.1 not on all available (0.0.0.0) ips.

share|improve this answer
sudo ufw allow 22

sudo ufw deny 22
share|improve this answer

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.