Monday, October 26, 2015

Common iptables commands

A few years ago I wrote a iptables tutorial explaining the basics of the topic. This post is just a small cheat sheet of most simple and effective commands that I end up using very frequently. I am assuming that we are operating for IP and using INPUT chain of the iptables.
  1. Block an IP
    iptables -A INPUT -s -j DROP
  2. Block an IP range
    iptables -A INPUT -s -j DROP
  3. List current rule set
    iptables --list
  4. List current rules set with numbers
    iptables --line-numbers --list
  5. Delete a rule by rule
    iptables -D INPUT -s -j DROP
  6. Delete a rule by number
    iptables -D INPUT 7
  7. Save iptables rules to a file
    iptables-save > iptables.dat
  8. Load iptables rules from a file
    iptables-restore < iptables.dat

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.