Home  »  ArticlesGuidesHow ToTechnology   »   How to Save IPtables Rules Permanently on Linux

How to Save IPtables Rules Permanently on Linux

IPtables is a powerful firewall tool for managing network traffic on Linux systems. While configuring IPtables rules is essential for securing your server, it’s equally important to ensure that these rules persist across reboots. In this guide, we’ll walk you through the steps to save IPtables rules permanently on your Linux system.

Understanding IPtables Rules

Before we dive into saving IPtables rules permanently, let’s briefly discuss how you can add and manage rules:

  • Add a Rule: You can use the iptables command to add a rule. For example, to allow incoming traffic on port 80, you would use a rule like this: sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  • List Rules: You can list the current rules with the iptables -L command.
  • Save Rules Temporarily: You can use the iptables-save command to save the current rules to a file, but this won’t make the rules persistent across reboots.

Now, let’s get into making your IPtables rules permanent.

Saving IPtables Rules Permanently

To save IPtables rules permanently on Linux, you need to follow these general steps:

Step 1: Install the ‘iptables-persistent’ Package

On some Linux distributions, the iptables-persistent package provides a convenient way to save and load IPtables rules at boot. To install it, use the package manager specific to your distribution:

  • On Debian/Ubuntu: sudo apt-get update && sudo apt-get install iptables-persistent

Step 2: Save Current IPtables Rules

Before saving rules permanently, you should ensure that your current rules are configured as you want. Use the iptables-save command to save your current rules to a file.

$ sudo iptables-save > /etc/iptables/rules.v4

This command saves your IPv4 rules to the specified file, but don’t forget to adjust the file path if necessary.

Step 3: Automatically Load Rules at Boot

The iptables-persistent package creates a systemd service that automatically loads the rules at boot. There is no need for manual configuration; the package handles this for you.

Step 4: Manage IPv6 Rules (Optional)

If you’re also working with IPv6 rules, you can follow similar steps to save and load them permanently. You would use the ip6tables-save command to save your current IPv6 rules and install the ip6tables-persistent package to manage them automatically at boot.

Verifying IPtables Rules

After saving the rules permanently, you can verify that they load correctly at boot and that the firewall behaves as expected. You can also run the following command to list the active rules and ensure they match your configurations:

$ sudo iptables -L


Saving IPtables rules permanently on Linux ensures that your firewall configurations persist across reboots, helping maintain the security and integrity of your system. By following the steps outlined in this guide, you can effortlessly manage your IPtables rules and make them a permanent part of your Linux server’s security setup. Don’t forget to periodically review and update your rules as your server’s needs change and new security requirements arise.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Available under:
Articles, Guides, How To, Technology