• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

How to Configure FirewallD in CentOS Stream: From Essential to Production-Grade

March 9, 2026

FirewallD remains the recommended dynamic packet filtering frontend in CentOS Stream 9 and 10. It provides zone-based policy application, rich rule expressiveness, runtime changes without service interruption, and clean integration with nftables (the underlying backend since RHEL 8 / CentOS Stream 8).

Below is a structured progression from beginner essentials to advanced production patterns used in real environments in 2026.

Core Design Principles You Should Internalize

  • Zones are trust boundaries assigned to interfaces (or sources). Most production internet-facing servers should use drop or public as the active/default zone — never trusted unless it’s an internal-only management interface.
  • Runtime vs permanent changes: –permanent writes to /etc/firewalld/zones/. Runtime changes are immediate but lost on reload/reboot.
  • Evaluation order: rich rules → services → ports → source-based rules → interface defaults → zone policy (accept/reject/drop).
  • SELinux synergy: FirewallD decisions happen before SELinux AVC checks — both must allow traffic for successful connection.

Beginner: Getting Started Safely

  1. Confirm active state and default zone Most fresh installs default to public with ssh allowed.

  2. Minimal production baseline (internet-facing server)

    • Set default zone to drop
    • Explicitly allow only ssh + https (or http during setup)
    • Restrict ssh to known source IPs or VPN ranges

    This single decision eliminates ~95% of random internet noise.

Intermediate: Service-Centric Configuration (Recommended Default)

Always prefer –add-service over –add-port when a predefined service exists:

  • Recognized services include: cockpit, docker, freeipa-ldap, http, https, imap, ldap, mdns, mysql, nfs, openvpn, pop3, postgresql, prometheus-node-exporter, samba, smtp, ssh, vnc-server, and many more.
  • Service definitions live in /usr/lib/firewalld/services/ and can be overridden/customized in /etc/firewalld/services/.

Example pattern for a typical LAMP + admin server:

  • Allow https (port 443/tcp) from anywhere
  • Allow http (80/tcp) only from monitoring IPs or during initial setup
  • Allow ssh only from management subnet
  • Allow cockpit (9090/tcp) only from admin VPN

Advanced: Rich Rules – The Real Power

Rich rules give you conditional, ordered, logging-aware, rate-limited, and forwarding logic.

Common production patterns in 2026:

  1. Rate-limited administrative access Protect SSH / cockpit from brute-force even before fail2ban/crowdsec engages.
  2. Time-windowed maintenance ports Temporarily open rsync/nfs/sftp ports during scheduled backup windows (e.g., 02:00–04:00 daily).
  3. Geoip-like restrictions via source prefixes Combine with external threat feeds or known bad ASN ranges (requires script to update rich rules periodically).
  4. Port forwarding / DNAT Forward external 443 → internal reverse-proxy at non-standard port, or expose containerized services safely.
  5. Logging with classification Log dropped packets with meaningful prefixes for SIEM correlation (e.g., “possible-scanner-”, “brute-ssh-”).
  6. Masquerading + port-forward for edge gateways Enable NAT + forward specific external ports to internal VMs/containers.

Hardening & Observability Best Practices (2026)

  • Default zone = drop for any publicly routed interface
  • Log denied packets selectively (–set-log-denied=unicast is usually sufficient; all creates noise)
  • Avoid direct nft/iptables manipulation unless using –direct interface (breaks firewalld state tracking)
  • Backup configuration before bulk changes: tar czf firewalld-backup-$(date +%F).tar.gz /etc/firewalld
  • Runtime safety pattern
    1. Apply change runtime-only
    2. Verify from another session
    3. Make permanent
    4. Reload
  • Monitoring integration Forward firewalld journal logs to central system (rsyslog → Graylog / Loki / ELK). Look for REJECT/DROP lines with consistent prefixes from rich rules.

Quick Decision Framework for New Servers

ScenarioRecommended ZoneMust-Allow Services / RulesAdditional Controls
Internet web server (nginx/apache)public or drophttps, http (optional)Source restrict admin ports
Database server (mysql/postgres)drop3306/5432 only from app subnetRich rule + rate limit if public
Container host (docker/podman)publicPublished container ports via –publishConsider nftables passthrough if needed
Management / bastion hostpublicssh (source-restricted), cockpit (VPN only)Fail2ban/crowdsec + geo-blocking script
Internal app server (no public IP)internalhttp/https, app-specific portsMinimal external exposure

Validation & Troubleshooting Commands Worth Memorizing

  • –list-all-zones — overview of everything
  • –get-active-zones — which interfaces are where
  • –get-zone-of-interface=eth0
  • –query-service=https — is it allowed?
  • –query-rich-rule=’rule …’
  • journalctl -u firewalld -f — live denied/log traffic
  • firewall-cmd –direct –get-all-rules — low-level nft/iptables view (debug only)

Mastering zones + rich rules covers virtually every realistic firewall requirement without dropping to raw nftables syntax. For Kubernetes clusters, edge gateways, or zero-trust micro-segmentation, you may eventually layer Calico, Cilium, or eBPF-based solutions on top — but firewalld remains the reliable host-level foundation.

Leave a Reply

You must be logged in to post a comment.

Recent Posts

  • How to Configure FirewallD in CentOS Stream: From Essential to Production-Grade
  • Installing Docker on CentOS: A Practical Setup Guide (CentOS Stream 9/10 – 2026)
  • How to Secure a CentOS Server: 15 Essential Hardening Techniques (CentOS Stream 9/10 – 2026)
  • CentOS End of Life (EOL): What It Means and Migration Options in 2026
  • How to Configure a LAMP Stack on CentOS Stream for Production

Recent Comments

No comments to show.

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot