How to save iptables firewall rules permanently on Linux

How to save iptables firewall rules permanently on Linux

To save iptables firewall rules permanently on a Linux system, you can use the iptables-save command to save the rules to a file, and then use the iptables-restore command to load the rules from the file when the system is started.

  1. Save the iptables rules to a file using the iptables-save command. For example:
refer to‮al:‬utturi.com
iptables-save > /etc/iptables/rules.v4

This will save the iptables rules to the file /etc/iptables/rules.v4.

  1. Create a script to load the iptables rules when the system is started. The script should contain the following line:
iptables-restore < /etc/iptables/rules.v4
  1. Make the script executable using the chmod command. For example:
chmod +x /path/to/script.sh
  1. Configure the script to run when the system is started. This can typically be done by creating a symbolic link to the script in the /etc/init.d directory or by adding the script to the system startup scripts.

Keep in mind that the method for saving and restoring iptables rules may vary depending on the Linux distribution you are using. Consult the documentation for your Linux distribution for more information on how to save and restore iptables rules permanently.

You can also use other tools such as iptables-persistent or firewalld to save and restore iptables rules on a Linux system. These tools can simplify the process of saving and restoring iptables rules, and may be easier to use depending on your needs. Consult the documentation for these tools for more information on how to use them to save and restore iptables rules.

Created Time:2017-10-29 22:08:37  Author:lautturi