Iptables: block all traffic except SSH

I needed to update some servers and block traffic generated by a lot of services. Since I couldn’t block every single service neither disconnect the network, I used this simple iptables rule:

iptables -A INPUT -p tcp -m state --state NEW -m multiport ! --dports 22 -j REJECT

 

Flushing iptables

You can flush and reset iptables to default running these commands:

iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

The -F command flushes all the chains and -X deletes empty (non-default) chains.
You can also create a script:Continue reading