Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

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

2 Answers 2

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

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

# ifconfig eth0 down
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.