How to block all incoming traffic excepting specified services

For your own security, sometimes we want to filter all incoming traffic to our machine and let it go to only some specified ports. We can do it easily using IPTables.

Here is the simple command, which will DROP all incoming traffic to all ports excepting 80,443 (HTTP):
iptables -A INPUT -p tcp -m tcp -m multiport ! --dports 80,443 -j DROP

List of common used ports is here.

Remember to allow yourself to connect to SSH port :)

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>