월. 8월 4th, 2025

Introduction

Firewalls are essential guardians for Linux systems, controlling network traffic via predefined rules. Two primary tools dominate this space: iptables (the legacy standard) and firewalld (a modern dynamic alternative). This guide compares their architectures, use cases, and provides practical usage examples for sysadmins and developers.


1. What is iptables?

iptables is a classic, low-level firewall utility that interacts directly with the Linux kernel’s netfilter framework. It processes rules in sequential order, making it powerful but complex.

Key Characteristics:

  • Rule-Based: Filters traffic via chains (INPUT, OUTPUT, FORWARD).
  • Stateless: Treats each packet in isolation (unless paired with conntrack).
  • Persistence: Rules vanish after reboot unless saved (via iptables-save > file).

2. What is firewalld?

firewalld is a dynamic, zone-based firewall manager with D-Bus integration. It modifies rules without restarting services and simplifies abstractions like “zones” and “services.”

Key Characteristics:

  • Zone-Centric: Assigns interfaces to zones (e.g., public, trusted).
  • Runtime & Permanent Settings: Temporary runtime changes vs. saved configurations.
  • Rich Language: Supports complex rules (e.g., rich rules for IP/port filtering).

3. Critical Differences

Feature iptables firewalld
Configuration Direct /etc/sysconfig/iptables edits XML files (e.g., /etc/firewalld/)
Dynamic Updates Requires full restart (service iptables restart) Applies changes instantly (no restart)
Complexity Steeper learning curve User-friendly abstractions
Backend Direct kernel interaction Uses nftables or iptables as backend
Use Case Granular control, embedded systems Servers/desktops needing flexibility

4. Practical Usage Examples

iptables

  • Allow SSH:
    iptables -A INPUT -p tcp --dport 22 -j ACCEPT  
  • Block an IP:
    iptables -A INPUT -s 192.168.1.100 -j DROP  
  • Save Rules:
    iptables-save > /etc/sysconfig/iptables  # RHEL/CentOS  

firewalld

  • Allow HTTP Service:
    firewall-cmd --zone=public --add-service=http --permanent  
    firewall-cmd --reload  
  • Open Custom Port:
    firewall-cmd --zone=public --add-port=8080/tcp --permanent  
  • Rich Rule (Block IP):
    firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.100" reject' --permanent  

5. Which Should You Choose?

  • Use iptables if:
    • You need granular packet-level control.
    • Working on lightweight/legacy systems without D-Bus.
  • Use firewalld if:
    • Managing dynamic environments (e.g., cloud VMs).
    • Prefer human-readable “services” and “zones.”
    • Require hot-reloads (e.g., containers/VPNs).

6. Conclusion

While iptables offers raw precision, firewalld provides agility for modern infrastructures. For new deployments, start with firewalld for simplicity, but master iptables for deep troubleshooting. Both tools enforce the same kernel security—only their management philosophies differ.

> Pro Tip: Use nftables (successor to iptables) for future-proof scripting on Linux 5.10+ kernels!

🔧 Next Step: Test rules in a sandbox VM before production!

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다