How to make rules persistent?

To make iptables rules persistent across reboots, you can follow these steps depending on your Linux distribution:

For Debian/Ubuntu:

  1. Install iptables-persistent:

    sudo apt-get install iptables-persistent
  2. Save Current Rules:
    During installation, you will be prompted to save your current iptables rules. If you want to save them later, you can run:

    sudo netfilter-persistent save
  3. Automatically Load Rules on Boot:
    The iptables-persistent package automatically loads the saved rules on boot.

For CentOS/RHEL:

  1. Install iptables-services:

    sudo yum install iptables-services
  2. Save Current Rules:
    Save your current rules using:

    sudo service iptables save
  3. Enable the Service:
    Ensure the iptables service is enabled to start on boot:

    sudo systemctl enable iptables

For Other Distributions:

You may need to check the specific method for your distribution, but generally, you can save the rules to a file and create a script to load them on boot.

Example Script:

You can create a script to restore rules at startup:

  1. Create a script file, e.g., /etc/iptables/restore-rules.sh:

    #!/bin/bash
    iptables-restore < /path/to/your/rules.v4
  2. Make it executable:

    sudo chmod +x /etc/iptables/restore-rules.sh
  3. Add it to your system's startup scripts (e.g., using cron or systemd).

By following these steps, your iptables rules should persist across reboots.

0 Comments

no data
Be the first to share your comment!