• 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. dnsspoof: command not found
  2. mountpoint: command not found
  3. autoreconf: command not found
  4. How to Stop/disable Firewalld on CentOS/RHEL 8
  5. How to configure VNC Server on CentOS/RHEL 6
  6. script Command Examples in Linux
  7. How to disable timeout in ssh during login prompt (login session inactivity) in Linux
  8. conky: command not found
  9. How to move /var on a separate disk as a separate mount point (Online)
  10. How to Use Udev Rules to Create oracleasm Disks in CentOS/RHEL 8

You May Also Like

Primary Sidebar

Recent Posts

  • aws ec2: CLI for AWS EC2 (Command Examples)
  • aws cur – Create, query, and delete AWS usage report definitions (Command Examples)
  • aws configure – Manage configuration for the AWS CLI (Command Examples)
  • aws cognito-idp: Manage Amazon Cognito user pool and its users and groups using the CLI

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright