Super User is a question and answer site for computer enthusiasts and power users. 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

How can I force all currently open sockets in linux to close from the command line?

share|improve this question
This is hard, I think it would be easier to answer if you said why. All of your sockets? All on the computer? Kill apps or not? – Rich Homolka Sep 14 '10 at 22:28
If you do that, the programs using these sockets will encounter errors, which they might or might not handle. Is that what you want? – sleske Sep 14 '10 at 22:43
Maybe you could describe why you want to do this. Then it'll be easier to help. Also see:… – sleske Sep 14 '10 at 22:43

Maybe it's easier to shut down a specific interface, for example:

# ifconfig eth0 down
share|improve this answer

to flush all your rules in the filter table iptables -F
set default behavior to drop in INPUT chain iptables -P INPUT DROP

at this point all local sockets should be unavailable to a remote host if you have a redhat based os you should also use iptables -X to get rid of their custom chain for INPUT

if you want to the rules to remain on startup then you need to either include these in a script that runs in the /etc/rc.local file or use iptables save

This is all assuming that what you said you want to do is what you want to do.

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.