1. The 3-Layer Firewall Architecture
The Linux firewall system operates like a company with three distinct tiers: [1]
+--------------------------------------------------------+ | 1. HIGH LEVEL: User Interface (The Manager)        | |    - Examples: firewalld (firewall-cmd), UFW     | +--------------------------------------------------------+                           |                           v  (Sends configuration rules) +--------------------------------------------------------+ | 2. MIDDLE LEVEL: Command-Line Tools (The Translators) | |    - Legacy: iptables, ip6tables, arptables       | |    - Modern: nft (nftables tool), iptables-nft     | +--------------------------------------------------------+                           |                           v  (Interacts via Netlink sockets) +--------------------------------------------------------+ | 3. LOW LEVEL: Kernel Subsystem (The Security Guard)   | |    - Netfilter (Core packet processing engine)     | +--------------------------------------------------------+
Layer 1: High Level (The Manager)
  • What it is: Frontends like firewalld.
  • Role: It provides an easy, human-readable abstract concept (like Zones or Services). You tell it: "Allow HTTP traffic in the Public zone."
  • Action: It does not inspect packets. It simply translates your high-level intent into technical commands for the middle layer. [1, 2, 3, 4, 5]
Layer 2: Middle Level (The Translators)
  • What it is: Command-line utilities like iptables or nft.
  • Role: They act as translators between user space and kernel space.
  • Action: They parse specific command syntax and compile them into a bytecode format that the operating system kernel can understand. [1, 2, 3]
Layer 3: Low Level (The Security Guard)
  • What it is: Netfilter. This is built directly into the Linux Kernel.
  • Role: The actual data-plane engine.
  • Action: It inspects every single packet passing through your network card. It matches them against the compiled rules and decides to ACCEPT, DROP, or REJECT them. [1, 2, 3, 4, 5]

2. Why Low-Level Rules Work When firewalld is Stopped
To understand this, look at how the layers interact when the daemon stops:
  1. Rule Persistence: When firewalld runs, it sends rules down to Layer 2, which loads them into Layer 3 (Netfilter inside the kernel memory). [1, 2]
  2. Stopping the Service: When you run sudo systemctl stop firewalld, you are only killing the Layer 1 Management Daemon.
  3. Kernel Memory Remains Active: The compiled rules already sitting inside the Layer 3 kernel memory do not automatically disappear. Netfilter keeps executing those active memory rules on every incoming packet.
  4. Flushing Rules: If you want to completely clear out the rules after stopping firewalld, you have to explicitly flush the kernel tables using a middle-level tool (e.g., sudo iptables -F or sudo nft flush ruleset).

3. How CentOS and AlmaLinux Handle the Translation
The architecture shifted between OS versions because Red Hat changed how Layer 2 talks to Layer 3:
Operating System
Layer 1 (High)
Layer 2 (Middle)
Layer 3 (Low / Kernel)
CentOS 7
firewalld
Legacy iptables binary
Netfilter (using old iptables structures)
CentOS 8 / AlmaLinux 8
firewalld
iptables-nft (A translation tool)
Netfilter (using modern nftables structures)
AlmaLinux 9
firewalld
Native nft command
Netfilter (pure modern nftables subsystem)
The iptables-nft Trick in Version 8
In CentOS 8 and AlmaLinux 8, running an iptables command doesn't actually touch the old legacy architecture. It uses a modern utility called iptables-nft. This utility takes your old iptables command syntax, translates it under the hood into modern nftables syntax, and pushes it directly into the new kernel subsystem. [1, 2, 3, 4]
To help optimize your system or troubleshoot an active issue, could you tell me:
  • Are you currently troubleshooting a specific network issue where rules are behaving unexpectedly?
  • Do you need to migrate legacy configurations from an older CentOS 7 server over to AlmaLinux 9?
20 sites
Show all
ok let us talk only layer1(high) list below command for centos 7 8 and almalinux 8 9 1) how to list how many zones are there, how to view all rules in layer1, 2)how to CURD rules in layer1 .
Here is the single command-line guide for managing Layer 1 (firewalld) rules.
Because CentOS 7, CentOS 8, AlmaLinux 8, and AlmaLinux 9 all use firewalld as their primary Layer 1 manager, the exact same firewall-cmd commands work identically across all four operating systems.

1. List Zones and View Rules
How to list how many zones are there
  • List all available zone names:
    bash
    sudo firewall-cmd --get-zones
    Use code with caution.
  • List only the active zones (zones currently assigned to a network interface):
    bash
    sudo firewall-cmd --get-active-zones
    Use code with caution.
How to view all rules in Layer 1
  • View rules for the default active zone:
    bash
    sudo firewall-cmd --list-all
    Use code with caution.
  • View rules for a specific zone (e.g., public):
    bash
    sudo firewall-cmd --zone=public --list-all
    Use code with caution.
  • View absolutely all rules across every single zone:
    bash
    sudo firewall-cmd --list-all-zones
    Use code with caution.

2. CRUD Operations in Layer 1
firewalld has two states: Runtime (active right now, but resets on reboot) and Permanent (saved to disk, applies after reload/reboot). To make a rule permanent, you must use the --permanent flag, and then run firewall-cmd --reload.
Create (Add Rules)
  • Add a port (Runtime only - temporary):
    bash
    sudo firewall-cmd --zone=public --add-port=8080/tcp
    Use code with caution.
  • Add a port permanently (Best practice):
    bash
    sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
    Use code with caution.
  • Add a predefined service permanently (e.g., http, https, ssh):
    bash
    sudo firewall-cmd --zone=public --add-service=https --permanent
    Use code with caution.
Read (Query Rules)
  • Check if a specific port is currently allowed:
    bash
    sudo firewall-cmd --zone=public --query-port=8080/tcp
    Use code with caution.
  • Check if a specific service is currently allowed:
    bash
    sudo firewall-cmd --zone=public --query-service=https
    Use code with caution.
Update (Modify Rules)
firewalld does not have a direct "edit" command. To update a rule, you change the configuration and then reload the system to apply it.
  • Apply permanent changes to the active system (Crucial after any permanent add/remove):
    bash
    sudo firewall-cmd --reload
    Use code with caution.
  • Change an interface to a different zone:
    bash
    sudo firewall-cmd --zone=internal --change-interface=eth0 --permanent
    Use code with caution.
Delete (Remove Rules)
  • Remove a port permanently:
    bash
    sudo firewall-cmd --zone=public --remove-port=8080/tcp --permanent
    Use code with caution.
  • Remove a service permanently:
    bash
    sudo firewall-cmd --zone=public --remove-service=https --permanent
    Use code with caution.
If you want to practice or deploy this, let me know:
  • What specific port numbers or application services (like MySQL, Nginx, or SSH) you need to configure right now.
  • If you need a quick automation script containing these commands to instantly secure a fresh server.
AI can make mistakes, so double-check responses
how to allow all port to be visited , are there any default rules only allow white list port , which rules is it
To allow traffic on all ports, you can configure firewalld to change its default behavior, as it natively operates on a whitelist approach that blocks everything by default. [1, 2, 3]

1. How to Allow All Ports to Be Visited
You can achieve this in two ways using Layer 1 (firewalld).
Method A: Change the Default Zone Target to ACCEPT (Recommended)
By default, the public zone drops or rejects all traffic unless explicitly whitelisted. Changing the target to ACCEPT turns it into an "allow-all" zone. [1, 2, 3, 4]
bash
# 1. Change the target permanently sudo firewall-cmd --zone=public --set-target=ACCEPT --permanent # 2. Reload to apply changes sudo firewall-cmd --reload
Use code with caution.
Method B: Open All Port Ranges (Alternative)
You can explicitly tell the firewall to whitelist every single valid port number (from port 1 to 65535) for both TCP and UDP traffic. [1, 2, 3]
bash
# 1. Add the full port ranges permanently sudo firewall-cmd --zone=public --add-port=1-65535/tcp --permanent sudo firewall-cmd --zone=public --add-port=1-65535/udp --permanent # 2. Reload to apply changes sudo firewall-cmd --reload
Use code with caution.

2. Where is the Whitelist Rule Located?
Yes, firewalld strictly enforces a whitelist policy out of the box. If a port or service is not explicitly added to the active zone configuration, it is automatically blocked. [1]
Which rule enforces this?
This behavior is controlled by the target: default setting inside your zone configuration. [1, 2]
  • In a fresh installation of CentOS or AlmaLinux, the default zone is public.
  • A target of default for the public zone translates under the hood to REJECT (or DROP) for any incoming packet that does not match an allowed exception. [1, 2, 3]
How to view your current whitelist rules
To see exactly what ports and services are currently whitelisted on your system, run:
bash
sudo firewall-cmd --zone=public --list-all
Use code with caution.
Look closely at the output of that command:
  • target: default → This is the rule enforcing the whitelist behavior. It catches all unmatched traffic and blocks it.
  • services: cockpit dhcpv6-client ssh → These are the default factory exceptions. Only administrative traffic for SSH, Cockpit web console, and DHCPv6 are allowed through. Everything else is blocked.
  • ports: → This will be blank by default, showing that no raw port numbers have been whitelisted yet. [1, 2, 3, 4, 5]
To help make sure your server stays secure, tell me:
  • Is this server exposed directly to the public internet, or is it safely inside a private local network?
  • Are you opening all ports just for a temporary connection test, or do you need a permanent open-port configuration?
20 sites
Show all
how many zones does it have, and what is the meaning of each zone, can i remove orginal zones ?
By default, firewalld comes pre-configured with 9 standard zones.

1. What Each Zone Means
The zones are ordered below from least trusted (most secure/strict) to most trusted (least secure/open). [1]
Zone Name
Trust Level
Default Behavior
Best Use Case
drop
Lowest
Drops all incoming packets without any response.
High-attack environments.
block
Very Low
Rejects all incoming packets with an ICMP error message.
Disconnecting untrusted networks.
public
Low
(Default) Blocks all traffic except explicitly allowed ports/services.
Public Wi-Fi or internet-facing servers.
external
Low
Blocks traffic; enables NAT masquerading for routers/gateways.
Your WAN interface on a router.
dmz
Medium-Low
Isolated zone with limited access to your internal network.
Public-facing servers (Web, Mail, DNS).
work
Medium
Trusts most computers; shields against unrequested traffic.
Office networks where colleagues are nearby.
home
Medium-High
Trusts most computers; designed for helpful local discovery.
Home networks with trusted family devices.
internal
Medium-High
Identical to the home zone configuration.
Private side of a corporate local network.
trusted
Highest
Accepts all network traffic automatically.
Local testing or a totally isolated private link.

2. Can You Remove the Original Zones?
No, you cannot delete the 9 default pre-configured zones. [1]
They are hardcoded system defaults. If you try to run a command like sudo firewall-cmd --delete-zone=public --permanent, the system will return an error stating that it is a built-in zone.
What you can do instead:
If you want to clean up or customize your zone layout, use these workarounds:
  • Ignore them: Unused zones do absolutely nothing and consume no system resources unless you explicitly bind a network interface or IP address to them.
  • Create custom zones: You can build your own fully customized zones from scratch:
    bash
    sudo firewall-cmd --new-zone=my-secure-zone --permanent sudo firewall-cmd --reload
    Use code with caution.
  • Delete custom zones: Any zone you create yourself can be deleted:
    bash
    sudo firewall-cmd --delete-zone=my-secure-zone --permanent sudo firewall-cmd --reload
    Use code with caution.
    [1]
To help tailor the next steps, tell me:
  • Do you want to change which zone is your active default (e.g., switching from public to trusted to quickly open everything)?
  • Are you setting up a server with multiple network cards that need to be separated into different zones?
how to set different NIC to different zone, is it a good practice? are there any good practice in manage zones and rules
Binding different Network Interface Cards (NICs) to different zones is an industry best practice
. It enforces the security concept of Network Segmentation. [1]
For example, if you have a database server, you do not want the public internet reaching the same database port that your internal application server uses. Separating your interfaces ensures that a breach on one network card does not easily expose the rest of the machine.

1. How to Assign Different NICs to Different Zones
Assume your server has two network cards: eth0 (connected to the public internet) and eth1 (connected to your private internal network). [1]
Step 1: Assign the Internet interface to the public zone
bash
sudo firewall-cmd --zone=public --add-interface=eth0 --permanent
Use code with caution.
Step 2: Assign the Internal interface to the internal zone
bash
sudo firewall-cmd --zone=internal --add-interface=eth1 --permanent
Use code with caution.
Step 3: Apply the changes
bash
sudo firewall-cmd --reload
Use code with caution.
Step 4: Verify your assignments
bash
sudo firewall-cmd --get-active-zones
Use code with caution.
(The output will show both zones active, listing eth0 under public and eth1 under internal.)

2. Best Practices for Managing Zones and Rules
To keep your firewall secure, clean, and easy to maintain, follow these foundational strategies:
1. The Principle of Least Privilege
  • Default to Block: Keep your default zone (public) set to its native target. Never use the trusted zone for an internet-facing NIC.
  • Open Explicitly: Only whitelist the exact ports or services required for your applications to function. [1, 2, 3]
2. Prefer Services Over Ports
  • Good: sudo firewall-cmd --zone=public --add-service=ssh --permanent
  • Bad: sudo firewall-cmd --zone=public --add-port=22/tcp --permanent
  • Why: Services are human-readable. If an administrative service uses multiple ports, firewalld manages them as a single logical unit, making your configuration audit much easier to read.
3. Use "Rich Rules" for Granular Source Control
  • Opening a port to the entire public zone exposes it to the whole world. If a service (like database access on port 3306) must be accessed from the outside, restrict it to a specific IP address using a Rich Rule:
    bash
    sudo firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.50" port port="3306" protocol="tcp" accept' --permanent sudo firewall-cmd --reload
    Use code with caution.
    [1]
4. Always Test Rules Before Making Them Permanent
  • When configuring firewalls remotely, it is easy to accidentally lock yourself out of SSH.
  • The Safe Workflow: Run your command without the --permanent flag first. Test your connection. If something breaks, simply reboot the server (or wait for a timeout) to restore your previous configuration. Once verified, run the command again with --permanent and reload.
If you want to configure this now, tell me:
  • How many NICs your server has, and what networks they connect to.
  • What specific applications (e.g., web server, database, file share) run on this machine.
I can write out the exact multi-NIC zone configurations and rules tailored to your environment.
are there text ui to wizard to CURD rules ,
On CentOS 7, there used to be an official built-in Text User Interface (TUI) wizard for firewalls, but it was deprecated and removed in CentOS 8 and AlmaLinux 8/9. [1]
The current landscape for text-based menu interfaces across these OS versions offers specific options to manage rules cleanly.

1. The Legacy Built-in TUI (CentOS 7 Only)
CentOS 7 included a lightweight ncurses console wizard tool called system-config-firewall-tui. [1]
  • How to get it:
    bash
    sudo yum install system-config-firewall-tui sudo system-config-firewall-tui
    Use code with caution.
  • How it looks: It opens a blue terminal-based screen where you use your keyboard arrow keys and Tab to check/uncheck common services (SSH, HTTP) and add custom ports.
  • Why you shouldn't use it now: This tool was designed for the older iptables service. Running it on CentOS 7 will frequently conflict with Layer 1 firewalld. It does not exist on CentOS 8 or AlmaLinux 8/9. [1]

2. The Modern Alternative: Cockpit (Web-based Console Wizard)
Because Red Hat removed terminal-based wizards, they replaced them with Cockpit. Cockpit is a lightweight, responsive server management dashboard that runs locally and is accessible via any web browser. It serves as an excellent visual wizard for CRUD operations.
Cockpit comes pre-installed on CentOS 8 and AlmaLinux 8/9, but you can explicitly enable it across all variations:
Step 1: Install and Enable Cockpit
bash
# On CentOS 7 sudo yum install cockpit -y sudo systemctl enable --now cockpit.socket # On CentOS 8 / AlmaLinux 8 & 9 sudo dnf install cockpit -y sudo systemctl enable --now cockpit.socket
Use code with caution.
Step 2: Access the UI Wizard
  1. Open your web browser and navigate to: https://<YOUR_SERVER_IP>:9090
  2. Log in using your server’s root or admin credentials.
  3. Click on the Networking tab in the sidebar menu.
  4. Click on Firewall (or Firewall Active).
Step 3: Performing CRUD via Cockpit Wizard
  • Create: Click the Add Services or Custom Ports button. A modal pop-up box will prompt you for the port, protocol, or pre-defined service wrapper.
  • Read: The dashboard displays all active zones, current whitelisted services, and open port strings in a single scannable screen.
  • Update/Delete: Next to any active rule or port entry, there is a simple Trash/Delete Icon or edit toggle to immediately modify runtime and permanent rulesets.

3. What if you absolutely need a pure SSH Terminal UI?
If you are strictly bound to a command-line terminal over SSH with no browser access, firewalld does not offer a native modern TUI wizard tool. In that exact scenario, administrators rely on interactive shell syntax tricks to act like a wizard.
For instance, you can combine interactive prompts (read) into a quick terminal macro to handle rule additions step-by-step:
bash
echo "=== Firewalld Rule Wizard ===" read -p "Enter Port Number (e.g., 8080): " port read -p "Enter Protocol (tcp/udp): " proto read -p "Enter Zone (default public): " zone zone=${zone:-public} sudo firewall-cmd --zone=$zone --add-port=$port/$proto --permanent sudo firewall-cmd --reload echo "Successfully added $port/$proto to $zone zone!"
Use code with caution.
Would you like me to build a fully interactive bash script tool that acts like a custom terminal wizard menu (letting you press 1 to Add, 2 to List, 3 to Delete) for your servers?
1 site
  • 21 Nov 2015 — You can also try these steps: 1. Disabled firewalld with `systemctl stop firewalld.service` 2. Installed and configured system-con...
    Unix & Linux Stack Exchange
yes, go on, only, it best if it can mange port ranges
Here is a complete, production-ready interactive Bash script that acts as a pure terminal Text UI (TUI) wizard.
It handles single ports, port ranges (e.g., 8000-8080), and handles all CRUD operations across CentOS 7/8 and AlmaLinux 8/9.
Step 1: Save the Wizard Script
Create a new file on your server named fw-wizard.sh:
bash
nano fw-wizard.sh
Use code with caution.
Paste the following code into the file:
bash
#!/bin/bash # Ensure the script runs with root/sudo privileges if [ "$EUID" -ne 0 ]; then  echo "❌ Error: Please run this script using sudo or as root."  exit 1 fi while true; do  clear  echo "============================================="  echo "     🔥 FIREWALLD INTERACTIVE TUI WIZARD 🔥  "  echo "============================================="  echo " 1) [READ]   List All Rules & Zones"  echo " 2) [CREATE] Add a Port / Port Range"  echo " 3) [DELETE] Remove a Port / Port Range"  echo " 4) [RELOAD] Apply & Reload Firewall Settings"  echo " 5) [EXIT]   Exit Wizard"  echo "============================================="  read -p "Choose an option [1-5]: " choice  case $choice in    1)      clear      echo "=== ACTIVE ZONES AND CURRENT RULES ==="      echo "--------------------------------------"      sudo firewall-cmd --list-all-zones | grep -E '^[a-zA-Z0-9]|ports:|services:|interfaces:'      echo "--------------------------------------"      read -p "Press [Enter] to return to menu..." temp      ;;    2)      clear      echo "=== CREATE: ADD PORT OR RANGE ==="      read -p "Enter Target Zone (Default: public): " zone      zone=${zone:-public}            echo "👉 Format Examples: Single port [8080] | Range [8000-8050]"      read -p "Enter Port or Port Range: " port            read -p "Enter Protocol (tcp/udp) (Default: tcp): " proto      proto=${proto:-tcp}            echo "--------------------------------------"      echo "Adding $port/$proto to '$zone' zone..."      sudo firewall-cmd --zone=$zone --add-port=$port/$proto --permanent            if [ $? -eq 0 ]; then        echo "✅ Rule added successfully to configuration!"        echo "💡 Note: You must select Option 4 (Reload) to activate it."      else        echo "❌ Failed to add rule. Please verify the port format or zone name."      fi      read -p "Press [Enter] to return to menu..." temp      ;;    3)      clear      echo "=== DELETE: REMOVE PORT OR RANGE ==="      read -p "Enter Target Zone (Default: public): " zone      zone=${zone:-public}            echo "👉 Format Examples: Single port [8080] | Range [8000-8050]"      read -p "Enter Port or Port Range to remove: " port            read -p "Enter Protocol (tcp/udp) (Default: tcp): " proto      proto=${proto:-tcp}            echo "--------------------------------------"      echo "Removing $port/$proto from '$zone' zone..."      sudo firewall-cmd --zone=$zone --remove-port=$port/$proto --permanent            if [ $? -eq 0 ]; then        echo "✅ Rule removed successfully from configuration!"        echo "💡 Note: You must select Option 4 (Reload) to activate changes."      else        echo "❌ Failed to remove rule. Ensure the rule exists in that zone."      fi      read -p "Press [Enter] to return to menu..." temp      ;;    4)      clear      echo "=== RELOADING SYSTEM FIREWALL ==="      sudo firewall-cmd --reload      if [ $? -eq 0 ]; then        echo "🚀 Changes are now LIVE!"      else        echo "❌ Reload failed."      fi      read -p "Press [Enter] to return to menu..." temp      ;;    5)      clear      echo "Goodbye! 👋"      exit 0      ;;    *)      echo "❌ Invalid choice. Please pick an option from 1 to 5."      sleep 1.5      ;;   Museumesac done
Use code with caution.
Step 2: Make it Executable
Give the script permissions to run:
bash
chmod +x fw-wizard.sh
Use code with caution.
Step 3: Run Your Custom Wizard
Launch the menu using sudo:
bash
sudo ./fw-wizard.sh
Use code with caution.
How to use the port range feature in this wizard:
  • When choosing Option 2 (Create) or Option 3 (Delete), the script asks you for a port string.
  • For a single port, type: 8080
  • For an entire port range, simply separate the starting and ending numbers with a hyphen, like this: 9000-9100
  • Hit enter, type tcp or udp, and the system handles the range orchestration behind the scenes.
If you want to expand this script, let me know:
  • Should I add an option to manage predefined services (like ssh or http) alongside raw port ranges?
  • Do you need an option to whitelist specific IP addresses using rich rules?