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

link|improve this question
2  
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: stackoverflow.com/questions/41602/… – sleske Sep 14 '10 at 22:43
feedback

2 Answers

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

# ifconfig eth0 down
link|improve this answer
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.