• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL 6 : How to Save iptables Rules

by admin

Question : I set up my firewall/packet filtering but after a reboot the rules are not there any more.

Solution:
By default, rules created with the iptables command are stored in memory. If the system is restarted before saving the iptables rule set, all rules will be lost. For netfilter rules to persist through system reboot, they need to be saved. To do this, log in as root and type:

# service iptables save

This executes the iptables init script, which runs the iptables-save program and writes the current iptables configuration to /etc/sysconfig/iptables. The existing /etc/sysconfig/iptables file is saved as /etc/sysconfig/iptables.save.

The next time the system boots, the iptables init script reapplies the rules saved in /etc/sysconfig/iptables by using the iptables-restore command.

Another method to save the iptables rules

Another option is to use the iptables-save and iptables-restore commands. To save the current iptables rule set into a file of your choice :

# iptables-save > /tmp/rules.backup

Restoring the Rules

You can restore the ruleset at a later time by running

# iptables-restore < /tmp/rules.backup
Remember that for the restore to work, you should have first taken the backup of the existing iptables rules.

Ensuring that iptables service start on boot

Another issue commonly faced by users is that the iptables service in not enabled to start on boot. To avoid this, verify that the service was set to start on boot

# chkconfig iptables --list
iptables          0:off   1:off   2:off   3:on    4:on    5:on    6:off

If iptables is off, then enable the service for runlevels 3-5

# chkconfig iptables on

Filed Under: Linux

Some more articles you might also be interested in …

  1. “gnmic subscribe” Command Examples
  2. blackfire: A command-line profiling tool for PHP (Command Examples)
  3. htpasswd Command Examples
  4. apt-get Command Examples in Linux
  5. dnsspoof: command not found
  6. git daemon: A really simple server for Git repositories
  7. echo Command Examples in Linux
  8. Examples of creating command alias in different shells
  9. azurite: Azure Storage API compatible server (emulator) in local environment
  10. qrcp Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright