How to restore iptables rules?

To restore iptables rules, you can use the iptables-restore command. This command reads rules from a file and applies them to the iptables configuration. Here’s how you can do it:

  1. Create a backup of your current iptables rules (optional but recommended):

    iptables-save > /path/to/backup/iptables.rules
  2. Create a file with your desired iptables rules (e.g., rules.v4):

    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
    -A INPUT -p tcp --dport 22 -j ACCEPT
    -A INPUT -j DROP
    COMMIT
  3. Restore the iptables rules from the file:

    iptables-restore < /path/to/rules.v4
  4. Verify that the rules have been applied:

    iptables -L -v

This will restore your iptables rules as specified in the file. Make sure to adjust the file paths and rules according to your needs.

0 Comments

no data
Be the first to share your comment!