0Pricing
Linux Command Line Mastery · Lesson

Firewall Management: `ufw`, `firewalld`, `iptables`

Learn to configure and manage firewalls to secure your Linux system against unauthorized access.

Firewall Management: `ufw`, `firewalld`, `iptables` is a free Linux Command Line Mastery lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Linux Command Line Mastery learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What's a Firewall?

A firewall acts as a security guard for your computer or network. It controls incoming and outgoing network traffic by analyzing data packets and deciding whether to allow or block them based on a set of predefined rules.

Think of it as a filter that protects your system from unauthorized access and malicious threats.

Introducing UFW

UFW, which stands for "Uncomplicated Firewall," is a user-friendly front-end for iptables, the complex default firewall utility in Linux. It's designed to make firewall management much simpler, especially for users on Debian-based systems like Ubuntu.

UFW simplifies common tasks like opening or closing ports.

UFW Status & Control

Before making changes, it's good practice to check UFW's current status. You can also easily enable or disable it.

Try running these commands:

sudo ufw status
sudo ufw enable
sudo ufw disable

UFW: Allow Services

UFW allows you to open ports for common services by their name, which is very convenient. For example, to allow SSH or HTTP traffic, you just use the service name.

Let's try allowing SSH and HTTP:

sudo ufw allow ssh
sudo ufw allow http
sudo ufw status verbose

UFW: Allow Custom Ports

Sometimes you need to open a specific port that isn't a named service. You can do this by specifying the port number and the protocol (TCP or UDP).

Here's how to allow port 8080 for TCP and 53 for UDP:

sudo ufw allow 8080/tcp
sudo ufw allow 53/udp
sudo ufw status verbose

Introducing Firewalld

Firewalld is another popular firewall management tool, often found on Red Hat-based systems like CentOS and Fedora. Unlike UFW, Firewalld is a dynamic firewall manager.

It uses zones to define different trust levels for network connections, allowing you to apply rules based on where the connection originates.

Firewalld Status & Zones

With Firewalld, you can check its status and explore the various zones it uses. Zones like public, home, or internal have different default rules.

Check the status and active zones:

sudo systemctl status firewalld
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --get-zones

Firewalld: Manage Services

To manage services with Firewalld, you specify the zone and the service name. Changes are temporary by default; use --permanent to make them stick after a reboot, then --reload to apply.

Let's add HTTP service to the public zone permanently:

sudo firewall-cmd --zone=public --add-service=http --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-services --zone=public

Firewalld: Manage Ports

Similar to services, you can open or close specific port numbers in a Firewalld zone. Remember to specify the protocol (TCP or UDP) and use --permanent for lasting changes.

Here's how to open port 8080 for TCP permanently:

sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-ports --zone=public

Firewall Commands Check

Time for a quick check! Which of the following statements about firewall management in Linux are true?

Recap: Firewall Essentials

In this lesson, we explored how to manage firewalls on Linux systems to enhance security. We covered two main tools:

  • UFW (Uncomplicated Firewall): A simple interface for iptables, popular on Debian/Ubuntu, allowing easy control over services and ports.
  • Firewalld: A dynamic firewall manager used on RHEL/CentOS systems, which organizes rules into zones for flexible security policies.

Understanding these tools is crucial for securing your Linux server or workstation.

Frequently asked questions

Is the “Firewall Management: `ufw`, `firewalld`, `iptables`” lesson free?

Yes — the full text of “Firewall Management: `ufw`, `firewalld`, `iptables`” is free to read here on the web, and the Linux Command Line Mastery course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Linux Command Line Mastery course, upgrade to CoddyKit PRO.

What will I learn in “Firewall Management: `ufw`, `firewalld`, `iptables`”?

Learn to configure and manage firewalls to secure your Linux system against unauthorized access. You practise Linux Command Line Mastery with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Linux Command Line Mastery?

No prior experience is required. Linux Command Line Mastery on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Firewall Management: `ufw`, `firewalld`, `iptables`” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Linux Command Line Mastery lesson?

Yes. Every Linux Command Line Mastery lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Network Diagnostics: `traceroute`, `nslookup`, `dig`
  2. Firewall Management: `ufw`, `firewalld`, `iptables`
  3. Secure Shell Key Management
  4. Capturing and Inspecting Traffic with tcpdump
← Back to Linux Command Line Mastery