Exam objective 4.2 for the Red Hat Certified System Administrator (EX200) credential tests your ability to control network traffic on a Linux server. Without a properly configured firewall, your server is like a house with all its doors and windows wide open — anyone on the internet can walk in, steal data, or crash the system. For the EX200, you must demonstrate that you can use firewalld, the default firewall management tool on Red Hat Enterprise Linux, to define which packets of data are allowed to enter, leave, or pass through your server.
Jump to a section
A simple way to picture Configuring the Firewall with firewalld
A gated community has a single security desk at its entrance. That security desk is the only way in or out for cars and visitors, and it operates on a strict set of rules written by the homeowners' association. The security desk checks every single person and vehicle that tries to enter. It has a clipboard with two lists: an "allowed" list for residents and approved guests, and a "blocked" list for known troublemakers. When a delivery van arrives, the guard does not just wave it through — they check the van's licence plate, the driver's ID, and the delivery company name against the clipboard. If the van matches an expected delivery for house number 42, it is allowed in. If the van claims to be from "Pizza Hut" but has no pizza smell and a rusty old car instead of a branded scooter, the guard denies entry. This is exactly how a firewall works: every network packet (the car or visitor) is inspected against a set of rules before being allowed to pass or dropped on the spot.
Now, what makes this security desk modern — like firewalld — is that the homeowners' association can change the rules without tearing down the entire booth. They can add a new rule to allow a food truck for the weekend block party, then remove it on Monday. They can set up a temporary "port forwarding" rule so that when a drone delivery lands at the back gate, the guard directs it straight to the pool. The old system (iptables) was like having a clipboard written in permanent marker — if you made a mistake, you had to rewrite the whole thing from scratch. firewalld is like having an erasable whiteboard with dynamic zones: the "home" zone gets different rules (allow Amazon delivery, block salespeople) than the "office park" zone (allow all FedEx, block all cold callers). The security desk never sleeps, never gets tired, and never forgets a rule. It just checks the clipboard, says yes or no, and logs every single attempt in a neat book for later review.
Let us start with the absolute basics. A firewall is a software or hardware barrier that sits between your computer (or internal network) and the outside world (the internet). Its job is to examine every piece of network traffic — every "packet" of data — and decide whether to let it through or block it. Think of a packet as a tiny envelope containing a message, with a source address (where it came from) and a destination address (where it is going). The firewall checks each envelope against a list of rules. If the envelope matches a "permit" rule, it passes. If it matches a "deny" rule, it is dropped (thrown away). If no rule matches, the default action is usually to deny the packet.
On Red Hat Enterprise Linux (RHEL), the firewall is managed by a service called firewalld. The "d" at the end stands for "daemon", which is a background process that runs continuously. firewalld replaced the older system called iptables. The big difference is that iptables made you reload the entire set of rules after any change, which could break active connections. firewalld allows you to make changes without interrupting existing connections, because it uses a concept called "dynamic zones".
A zone is a logical grouping of network interfaces (like your ethernet port or WiFi adapter) with a predefined set of rules. RHEL comes with several default zones: public (for untrusted networks like a coffee shop WiFi), internal (for your trusted home or office network), dmz (for servers that must be accessible from the internet but separated from your internal network), and trusted (for networks you fully trust, like a dedicated management LAN). By default, all your network interfaces are assigned to the "public" zone, which is the most restrictive.
When you enable a service through firewalld, you are telling the firewall to allow traffic that matches that service's port number and protocol. For example, HTTP web traffic uses TCP port 80, so running the command "firewall-cmd --add-service=http" tells firewalld to allow incoming connections on port 80. The system immediately opens that door, and it stays open until you remove the rule.
Port forwarding is a feature where you tell the firewall: "when a packet arrives at this port on the server, send it to a different port on a different machine." This is extremely common in business environments. For instance, you might have a web server running on port 8080 inside your office, but you want people on the internet to reach it by typing port 80 in their browser. Using firewalld port forwarding, you can redirect incoming traffic from port 80 (on your firewall's public IP) to port 8080 (on the internal server).
The three essential commands you will use with firewalld are: firewall-cmd (the command-line tool), firewall-config (a graphical interface you will rarely use in the exam), and firewall-cmd --list-all (which shows you all the current rules). The most common flags are: --add-service (allow a known service), --add-port (allow a specific port number), --remove-service (block a previously allowed service), --permanent (make the change survive a reboot), and --reload (apply all pending permanent changes without restarting the entire firewall service).
One critical concept is the difference between runtime and permanent configuration. When you run a firewall-cmd command without the --permanent flag, the change takes effect immediately but is lost when the server reboots. This is called the "runtime" configuration, and it is useful for testing. To make a change permanent, you add --permanent to the command. But here is the trap: if you only use --permanent, the change does not take effect until you either run firewall-cmd --reload or reboot the server. In an exam question, they might ask you to add a service permanently AND make it active immediately. The correct pattern is to run two separate commands: one without --permanent (for immediate effect), and one with --permanent (to survive a reboot). Alternatively, you can run the command with --permanent and then reload.
Zones also have a concept called "target". The target zone defines what happens to packets that do not match any rule. The default target for most zones is "default", which means reject packets. You can change the target to "ACCEPT" (allow all traffic) or "DROP" (silently discard packets). Changing the target is rarely done in the exam but could appear in trick questions.
Finally, note that firewalld stores its permanent configuration in XML files located in /etc/firewalld/zones/. You can edit these files directly, but the recommended method is always to use the firewall-cmd command-line tool, which is what EX200 tests.
Check the Current Firewall State
Run 'sudo systemctl status firewalld' to see if the firewall service is running and 'sudo firewall-cmd --state' to get a simple 'running' or 'not running' response. This is always the first step in any debugging scenario. If firewalld is not running, start it with 'sudo systemctl start firewalld' and enable it with 'sudo systemctl enable firewalld'.
List All Rules for the Default Zone
Run 'sudo firewall-cmd --list-all'. This shows the default zone, the interfaces assigned to it, the allowed services and ports, the masquerade setting, and any port forwarding rules. Reviewing this output tells you exactly what is currently open and what is blocked. If you suspect a specific zone, use '--zone=zonename --list-all'.
Add a Service or Port to the Firewall
Decide whether the resource you need is a standard service (like ssh, http, https) or a custom port (like 8443/tcp). For a service, run 'sudo firewall-cmd --add-service=servicename'. For a custom port, run 'sudo firewall-cmd --add-port=port/protocol'. To make the change persistent, add '--permanent' and then reload. Test with --list-all.
Configure Port Forwarding (If Needed)
Port forwarding requires a specific syntax. The general form is: 'sudo firewall-cmd --add-forward-port=port=external_port:proto=protocol:toport=internal_port:toaddr=internal_IP'. For example, to forward port 80 on your server to port 8080 on 192.168.1.10, run the command with the correct parameters. Make it permanent and reload. Verify with --list-all; the rule appears under 'forward-ports'.
Assign an Interface to a Different Zone
If a network interface (like eth1) needs different rules than the default public zone, assign it to another zone. Run 'sudo firewall-cmd --zone=internal --add-interface=eth1' to move it to the internal zone. Add '--permanent' and reload. Verify with 'sudo firewall-cmd --get-zone-of-interface=eth1'.
Imagine you are the sole IT administrator for a small company called GreenLeaf Books, which has one physical office and a single RHEL server that hosts both a company website (port 80 and 443) and an internal inventory application (port 8443) used only by employees in the office. Your boss tells you, "We got complaints that nobody can see the website from outside, and also the inventory app just stopped working." You immediately suspect the firewall.
Your first step is to SSH into the server and run "sudo firewall-cmd --list-all". This command prints the current firewall configuration for the default zone (public). You see that only the "ssh" service is listed, with no mention of http or https. That explains why the website is unreachable — the firewall is blocking incoming web traffic. You also notice that the server has two network interfaces: eth0 (connected to the internet) and eth1 (connected to the internal office switch). The public zone applies to both; that is why the inventory app on eth1 is also blocked.
To fix the website, you need to add the http and https services to the firewall. You run:
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --reload
Then you verify by running --list-all again. Now http and https appear. But the inventory app is still blocked. You cannot add a standard service for port 8443 because it is not a well-known service. So you must add the custom port directly:
sudo firewall-cmd --add-port=8443/tcp --permanent
sudo firewall-cmd --reload
Now the inventory app works. But your boss also wants the company's internal webcam system (which only uses eth1) to be completely accessible, so you decide to move eth1 to the "trusted" zone, which has no restrictions. You run:
sudo firewall-cmd --zone=trusted --add-interface=eth1 --permanent
sudo firewall-cmd --reload
Now eth1 is in the trusted zone with all traffic allowed. eth0 remains in the public zone with only ssh, http, https, and port 8443 open.
Later, you learn that the company is moving to a new office and wants to set up a remote access system. They have an internal accounting server at 192.168.1.50 that listens on port 3030, but they want employees outside the office to reach it by typing the company's public IP address on port 3030. This is a classic port forwarding scenario. You run:
sudo firewall-cmd --add-forward-port=port=3030:proto=tcp:toport=3030:toaddr=192.168.1.50 --permanent
sudo firewall-cmd --reload
Now any packet arriving at your server's public IP on port 3030 gets forwarded to that internal machine. You also need to ensure IP forwarding is enabled on the server (otherwise the forwarding will not work), but that is a separate kernel parameter.
This scenario exactly mirrors exam questions where you must configure services, open custom ports, change zones, and set up port forwarding using firewalld.
EX200 loves to test firewalld, and they do it in very specific, repetitive ways. The exam uses multiple-choice questions and performance-based items where you actually log into a virtual machine and type commands. Here is exactly what you need to know.
First, memorise the three primary command patterns: to add a service, to add a port, and to add port forwarding. The syntax must be exact. For example, adding a service is "firewall-cmd --add-service=ssh". Notice there are no spaces around the equals sign. Adding a port is "firewall-cmd --add-port=443/tcp". The protocol (tcp or udp) is mandatory. Port forwarding is "firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080:toaddr=192.168.1.10". The colons separate the different arguments.
Second, they will always test the runtime vs permanent distinction. One common question: "A user added port 8080/tcp with --permanent but the service is still unreachable. Why?" The answer is that the change was made permanent but not applied to the runtime configuration. You must run firewall-cmd --reload or the command without --permanent to activate it immediately. Another trap: they ask you to add a rule that survives a reboot. The correct answer includes --permanent. If they ask for both immediate effect and persistence, the answer uses two commands or one command plus a reload.
Third, zones are heavily tested. You must know the default zones and their purposes: public (low trust, default), internal (medium trust), dmz (isolated servers), trusted (high trust). They love to ask: "Which zone should you assign to a network interface connected to the internet?" Answer: public. "Which zone would you use for a server hosting a website accessible to everyone?" Answer: dmz.
Fourth, they test port forwarding with subtle variations. For example, they might ask you to forward traffic coming to port 80 on your server to port 8080 on the same server (using the internal IP address of the server itself). The exact syntax matters: --add-forward-port=port=80:proto=tcp:toport=8080:toaddr=127.0.0.1 (loopback address).
Fifth, the exam will ask you to list current rules. The command is "firewall-cmd --list-all". It shows the default zone, the interfaces assigned to it, the allowed services, the allowed ports, and any port forwarding rules. For a specific zone, use "firewall-cmd --zone=public --list-all".
Sixth, they test how to change the default zone. The command is "firewall-cmd --set-default-zone=internal". This changes the zone that any new interface will be assigned to. Existing interfaces remain in their current zone.
Seventh, they test adding interfaces to zones. The command is "firewall-cmd --zone=internal --add-interface=eth1".
Eighth, they test what happens when no rules match a packet. The default action is "reject", which means the packet is dropped and the sender gets a rejection message. If they want silent dropping, you change the target to "DROP".
Ninth, they test that the firewall service must be running. The command "systemctl status firewalld" shows you if the daemon is active. If it is stopped, no firewall rules apply.
Tenth, they test the difference between iptables and firewalld. firewalld uses zones and dynamic updates; iptables uses chains and requires a rule reload. firewalld is the default on RHEL 7 and later.
Trap patterns: they give you a command with a typo like "--add-service=ssh --permenant" (misspelled) and ask why it did not run. They give you a command missing the protocol (e.g., --add-port=80 without /tcp). They tell you to add a service but you must specify the zone (e.g., --zone=internal). They ask you to block a service: use --remove-service. They ask you to list specific zones: use --zone=zone-name --list-all.
The default zone on RHEL is 'public', which blocks all inbound traffic except what you explicitly allow.
Use 'firewall-cmd --add-service=http' to allow a predefined service and 'firewall-cmd --add-port=8080/tcp' to allow a custom port.
The --permanent flag makes a change survive a reboot, but you must run 'firewall-cmd --reload' to apply it to the running firewall immediately.
Port forwarding with firewalld uses the syntax '--add-forward-port=port=80:proto=tcp:toport=8080:toaddr=192.168.1.10'.
Assign a network interface to a different zone using 'firewall-cmd --zone=trusted --add-interface=eth1'.
Always check your changes with 'firewall-cmd --list-all' or 'firewall-cmd --zone=zone-name --list-all'.
The three supported protocols in firewalld are tcp, udp, and sctp — you must specify one when adding a custom port.
Zones with higher trust levels (trusted, internal) have fewer restrictions; zones with low trust (public, external) have more restrictions.
The default target for most zones is 'default' (reject unmatched packets); you can change it to 'ACCEPT' or 'DROP'.
If you cannot remember a command, use 'firewall-cmd --help' or 'man firewall-cmd' — the exam environment provides man pages.
These come up on the exam all the time. Here's how to tell them apart.
firewalld
Uses dynamic zones to group rules logically
Changes take effect without reloading the entire rule set
Default firewall service on RHEL 7 and later
iptables
Uses linear chains without zones
Requires a full rule set reload to apply any changes
Legacy firewall tool; replaced by firewalld
Runtime Configuration
Applied immediately when a command runs without --permanent
Lost after a reboot or firewalld restart
Stored in kernel memory
Permanent Configuration
Saved to XML files in /etc/firewalld/zones/
Survives reboots
Requires --reload to activate into runtime
Public Zone
Default zone for all interfaces on RHEL
Very restrictive: blocks most inbound traffic
Use for interfaces connected to the internet or untrusted networks
Trusted Zone
Assumes all traffic is safe — allows all inbound and outbound
No restrictions, suitable for isolated network segments
Use for interfaces connected to a management LAN or trusted internal network
Source NAT (SNAT)
Changes the source IP address of outgoing packets
Used for making internal machines appear as the firewall's IP
Not directly done with firewalld's simple port forwarding — requires masquerade
Destination NAT (DNAT)
Changes the destination IP and port of incoming packets
Used for port forwarding and exposing internal services
Directly done with firewalld's --add-forward-port command
Mistake
Adding a service with --permanent takes effect immediately.
Correct
Adding --permanent only saves the change to the configuration files. It does not apply the change to the running firewall. You must run 'firewall-cmd --reload' or add the same rule without --permanent to make it active now.
Beginners see the word 'permanent' and assume it means 'applied now and forever'. They do not realise that firewalld separates the running state from the saved state.
Mistake
If you add a custom port, you must use the name of a service instead of the port number.
Correct
Services are predefined sets of ports (e.g., http = 80/tcp). If no service matches your port, you add it directly with --add-port=port/protocol.
Users new to Linux expect everything to have a friendly name. They do not know that only common services have predefined names in firewalld.
Mistake
The default zone allows all outbound traffic and blocks all inbound traffic.
Correct
The default zone (public) allows all outbound traffic and blocks inbound traffic except for rules you explicitly add. But it also allows related inbound responses to your outbound connections.
People think firewalls are symmetric (block everything both ways). firewalld is stateful — it tracks outgoing connections and automatically allows the return traffic.
Mistake
Port forwarding means the firewall changes the destination address on the incoming packet and does not touch the source address.
Correct
Port forwarding with firewalld performs Destination NAT (DNAT): it changes the destination IP and port of the packet. The source address remains the original sender's IP. The internal server then sends its response directly back to the sender, not through the firewall, unless you also configure source NAT.
Beginners think the firewall acts as a proxy that stays in the middle for the entire conversation. In reality, firewalld port forwarding is a simple DNAT rule, and returning traffic may bypass the firewall entirely.
Mistake
You must restart the firewalld service after every change for it to take effect.
Correct
You only need to reload (firewall-cmd --reload) or the change takes effect immediately if you omit --permanent. Restarting the service (systemctl restart firewalld) is unnecessary and will drop all existing connections.
New admins are used to restarting services after configuration changes (like Apache or SSH). They do not know that firewalld is designed to be dynamic and does not require a full restart.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
Add '--permanent' to your firewall-cmd command. For example: 'sudo firewall-cmd --add-service=http --permanent'. Then run 'sudo firewall-cmd --reload' to apply it immediately.
'--add-service' allows traffic for a predefined service (like http or ssh) that already has a known port number and protocol associated with it. '--add-port' allows traffic for a custom port number and protocol that does not have a named service (e.g., --add-port=8080/tcp).
You forgot to use the '--permanent' flag. When you run a firewall-cmd command without '--permanent', the change only applies to the runtime configuration, which is lost on reboot. Re-run your command with '--permanent' and then reload.
Use 'sudo firewall-cmd --get-zone-of-interface=eth0' (replace eth0 with your interface name). To see all interfaces and their zones, use 'sudo firewall-cmd --list-all-zones'.
It reloads the firewall rules from the permanent configuration files (in /etc/firewalld/zones/) and applies them to the runtime configuration without dropping existing connections. It is like rebooting the firewall service but faster and without interrupting active sessions.
Yes, but it is more advanced. By default, firewalld allows all outbound traffic. To block outbound traffic, you would need to use 'direct rules' or change the zone's 'target' to 'DROP' and then explicitly add rules for allowed outbound connections. The EX200 rarely tests outbound blocking.
You've finished Configuring the Firewall with firewalld. Continue through the EX200 study guide to build a complete picture of the exam.
Done with this chapter?