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

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • 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. CentOS / RHEL 6 : How to Change the Volume Group Name for Root Disk Device
  2. Active FTP vs. Passive FTP
  3. How to disable a specific command for a specific user in Linux
  4. Examples of using tcpdump command for network troubleshooting
  5. CentOS / RHEL 7 : How to enable or disable automatic updates (via packagekit)
  6. UNIX / Linux : Send mail with attachment using mutt
  7. How to change the default location (/var/cache/yum) of yum cache
  8. “passwd: Module is unknown” – error while changing the password in CentOS/RHEL 6
  9. Audit Rule Configuration not Reflected – How to troubleshoot
  10. How to backup Linux OS using “dd” Command

You May Also Like

Primary Sidebar

Recent Posts

  • How to disable ACPI in CentOS/RHEL 7
  • How to Use real-time query to access data on a physical standby database
  • CentOS/RHEL 8: “ACPI MEMORY OR I/O RESET_REG” Server Hung after reboot
  • How to Create a Physical Standby Database by Using SQL and RMAN Commands
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary