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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. lsof : Most commonly used examples
  2. How to disable write access to USB devices using “hdparm” tool
  3. RHEL 7 – RHCSA Notes (Cheat Sheets)
  4. How to Create a Custom Log File Rotation by logrotate in Linux
  5. Change default kernel (boot with old kernel) – CentOS/RHEL/OEL 7
  6. How to Partition DM-Multipath Pseudo Devices in CentOS/RHEL
  7. mountstats Command Examples in Linux
  8. How to Configure Proxy in CentOS/RHEL/Fedora
  9. How to create a networking bridge under CentOS/RHEL
  10. date Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • vgextend Command Examples in Linux
  • setpci command – configure PCI device
  • db_load command – generate db database
  • bsdtar command – Read and write tape archive files

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright