Skip to content
SysTutorials
  • SysTutorialsExpand
    • Linux & Systems Administration Academy
    • Web3 & Crypto Academy
    • Programming Academy
    • Systems & Architecture Academy
  • Subscribe
  • Linux Manuals
  • Search
SysTutorials
Programming Languages

Persisting iptables Rules on CentOS 7

ByQ A Posted onMar 24, 2018Apr 13, 2026 Updated onApr 13, 2026

Rocky Linux 9 and later distributions use FirewallD as the default firewall management tool. However, if you need direct control over iptables and ip6tables rules, you can disable FirewallD and use the iptables-services package to restore your rules at boot.

Install and Configure iptables-services

Start by installing the iptables-services package:

dnf install iptables-services

Create the rule files if they don’t exist:

touch /etc/sysconfig/iptables
touch /etc/sysconfig/ip6tables

Disable FirewallD (if running)

If FirewallD is currently active, stop and disable it:

systemctl disable firewalld.service
systemctl stop firewalld.service

Verify FirewallD is no longer running:

systemctl status firewalld.service

Start and Enable iptables Services

Start the iptables and ip6tables services:

systemctl start iptables
systemctl start ip6tables

Enable them to start automatically on boot:

systemctl enable iptables
systemctl enable ip6tables

Verify they’re active:

systemctl status iptables
systemctl status ip6tables

Configure Your Rules

Add your iptables rules using the standard iptables and ip6tables commands. For example:

# Allow SSH traffic
iptables -A INPUT -p tcp --dport 22 -j ACCEPT

# Allow established connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# Drop everything else by default
iptables -P INPUT DROP

Persist Rules Across Reboot

Before saving, back up your existing configuration:

cp /etc/sysconfig/iptables /etc/sysconfig/iptables.backup.$(date +%s)
cp /etc/sysconfig/ip6tables /etc/sysconfig/ip6tables.backup.$(date +%s)

Save your current iptables and ip6tables rules:

iptables-save > /etc/sysconfig/iptables
ip6tables-save > /etc/sysconfig/ip6tables

These rules will now be restored automatically when the iptables and ip6tables services start on boot.

Verify Persistence

Reboot the system and verify your rules are loaded:

reboot

After reboot, check that your rules are in place:

iptables -L -n
ip6tables -L -n

Important Considerations

When to use iptables-services instead of FirewallD: Direct iptables management is useful for specific use cases like complex rule sets, integration with custom scripts, or legacy systems. For most modern deployments, FirewallD provides a more manageable abstraction layer.

Modifying rules: Any changes you make with iptables or ip6tables commands won’t persist across reboots unless you run iptables-save and ip6tables-save again. Make this part of your workflow.

Checking what’s loaded: View your saved rules directly:

cat /etc/sysconfig/iptables
cat /etc/sysconfig/ip6tables

Restoring from backup: If something goes wrong:

cp /etc/sysconfig/iptables.backup.TIMESTAMP /etc/sysconfig/iptables
systemctl restart iptables

IPv6 considerations: Ensure you handle both IPv4 and IPv6 rules if you’re using IPv6 on your network. Missing ip6tables rules can lead to unexpected behavior.

Troubleshooting Common Issues

When encountering problems on Linux systems, follow a systematic approach. Check system logs first using journalctl for systemd-based distributions. Verify service status with systemctl before attempting restarts. For network issues, use ip addr and ss -tulpn to diagnose connectivity problems.

Package management issues often stem from stale caches. Run dnf clean all on Fedora or apt clean on Ubuntu before retrying failed installations. If a package has unmet dependencies, try resolving them with dnf autoremove or apt autoremove.

Related System Commands

These commands are frequently used alongside the tools discussed in this article:

  • systemctl status service-name – Check if a service is running
  • journalctl -u service-name -f – Follow service logs in real time
  • rpm -qi package-name – Query installed package information
  • dnf history – View package transaction history
  • top or htop – Monitor system resource usage

Quick Verification

After applying the changes described above, verify that everything works as expected. Run the relevant commands to confirm the new configuration is active. Check system logs for any errors or warnings that might indicate problems. If something does not work as expected, review the steps carefully and consult the official documentation for your specific version.

Post Tags: #backup#Bash#CentOS#configuration#Editor#firewalld#How to#iptables#ipv6#Linux#Network#Programming#Software#SSH#System#systems#time#Tutorial#www#yum

Post navigation

Previous Previous
MySQL and MariaDB Default Data Directories on CentOS 7
NextContinue
How to Monitor Process I/O Utilization

Tutorials

  • Systems & Architecture Academy
    • Advanced Systems Path
    • Security & Cryptography Path
  • Linux & Systems Administration Academy
    • Linux Essentials Path
    • Linux System Administration Path
  • Programming Academy
  • Web3 & Crypto Academy
  • AI Engineering Hub

Categories

  • AI Engineering (4)
  • Algorithms & Data Structures (14)
  • Code Optimization (8)
  • Databases & Storage (11)
  • Design Patterns (4)
  • Design Patterns & Architecture (18)
  • Development Best Practices (104)
  • Functional Programming (4)
  • Languages & Frameworks (97)
  • Linux & Systems Administration (727)
  • Linux Manuals (56,855)
    • Linux Manuals session 1 (13,267)
    • Linux Manuals session 2 (502)
    • Linux Manuals session 3 (32,501)
    • Linux Manuals session 4 (117)
    • Linux Manuals session 5 (1,724)
    • Linux Manuals session 7 (887)
    • Linux Manuals session 8 (4,721)
    • Linux Manuals session 9 (3,136)
  • Linux System Configuration (32)
  • Object-Oriented Programming (4)
  • Programming Languages (131)
  • Scripting & Utilities (65)
  • Security & Encryption (16)
  • Software Architecture (3)
  • System Administration & Cloud (33)
  • Systems & Architecture (46)
  • Testing & DevOps (33)
  • Uncategorized (1)
  • Web Development (25)
  • Web3 & Crypto (1)

SysTutorials, Terms, Privacy

  • SysTutorials
    • Linux & Systems Administration Academy
    • Web3 & Crypto Academy
    • Programming Academy
    • Systems & Architecture Academy
  • Subscribe
  • Linux Manuals
  • Search