0Pricing
Linux Server Deployment & SSH Mastery · Lesson

Understanding Firewalls (UFW/firewalld)

Learn the concepts of firewalls and how to use common tools like UFW (Ubuntu) or firewalld (CentOS) to control network traffic.

Understanding Firewalls (UFW/firewalld) is a free Linux Server Deployment & SSH 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 Server Deployment & SSH Mastery learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Your Server's Digital Guard

Imagine your server as a house. A firewall acts like a security guard at the door, deciding who gets in and out. It's a critical part of server security.

Firewalls prevent unauthorized access and protect your server from malicious attacks by controlling network traffic.

How Firewalls Filter Traffic

Firewalls work by using a set of rules to inspect incoming and outgoing network traffic. These rules are based on:

  • Source/Destination IP Address: Where traffic comes from or goes.
  • Port Numbers: Specific 'doors' for services (e.g., port 22 for SSH, 80 for HTTP).
  • Protocols: Like TCP or UDP.

They either allow or deny traffic that matches these rules.

Meet UFW: Uncomplicated Firewall

On Debian-based systems like Ubuntu, the most common firewall tool is UFW, which stands for "Uncomplicated Firewall."

UFW is designed to be easy to use, making it simple for beginners to manage firewall rules without diving into complex `iptables` commands directly.

UFW's Safe Default Behavior

By default, UFW is configured for security:

  • Deny Incoming: All incoming connections are blocked unless explicitly allowed.
  • Allow Outgoing: Your server can initiate connections to the outside world.

This means you need to specifically open ports for services you want to be accessible from the internet, like a web server or SSH.

Activating UFW (Ubuntu/Debian)

Before enabling UFW, it's crucial to allow SSH access, otherwise, you might lock yourself out of your server! After allowing SSH, you can enable UFW.

Try running these commands:

sudo ufw allow ssh
sudo ufw enable
sudo ufw status verbose

Allowing Essential Services with UFW

UFW can allow traffic for common services by their name (if defined in /etc/services) or by their port number. Let's allow HTTP (web traffic) and SSH:

sudo ufw allow http
sudo ufw allow https
sudo ufw status

Custom Port Access with UFW

Sometimes you need to open a specific port that isn't a standard named service, like port 8080 for a custom application. You can specify the protocol too (TCP or UDP).

Here's how to allow TCP traffic on port 8080:

sudo ufw allow 8080/tcp
sudo ufw status

Introducing firewalld: Dynamic Firewall

On Red Hat-based systems like CentOS and Fedora, the firewall management tool is firewalld. It's a dynamic firewall daemon, meaning you can change rules without restarting the entire firewall service.

firewalld uses the concept of 'zones' to manage rules, which offers a more flexible approach to security.

Understanding firewalld Zones

firewalld organizes firewall rules into zones. Each zone has a default set of rules and can be assigned to network interfaces.

Common zones include:

  • public: For untrusted networks (default for external interfaces).
  • home/internal: For trusted networks.
  • trusted: All network connections are accepted.

This allows you to apply different security levels based on the network's trust level.

Allowing Services with firewalld

To allow services with firewalld, you specify the service, the zone, and use the --permanent flag to make the rule persist after a reboot. You then need to reload firewalld.

Let's open SSH and HTTP in the public zone:

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

Firewall Quick Check

You've learned about UFW and firewalld. Which of the following statements about these firewall tools are TRUE?

Firewalls: Your Server's Shield

Great job! You've learned about the vital role of firewalls in server security. You now understand:

  • What firewalls are and why they are essential.
  • How UFW works on Ubuntu/Debian, including enabling and allowing services.
  • How firewalld works on CentOS/RHEL, its zone concept, and adding services.

Mastering these tools is crucial for controlling network access and keeping your server secure. Next, we'll dive into managing specific ports and their security implications!

Frequently asked questions

Is the “Understanding Firewalls (UFW/firewalld)” lesson free?

Yes — the full text of “Understanding Firewalls (UFW/firewalld)” is free to read here on the web, and the Linux Server Deployment & SSH 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 Server Deployment & SSH Mastery course, upgrade to CoddyKit PRO.

What will I learn in “Understanding Firewalls (UFW/firewalld)”?

Learn the concepts of firewalls and how to use common tools like UFW (Ubuntu) or firewalld (CentOS) to control network traffic. You practise Linux Server Deployment & SSH 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 Server Deployment & SSH Mastery?

No prior experience is required. Linux Server Deployment & SSH 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 “Understanding Firewalls (UFW/firewalld)” 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 Server Deployment & SSH Mastery lesson?

Yes. Every Linux Server Deployment & SSH 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. Basic Network Configuration
  2. Understanding Firewalls (UFW/firewalld)
  3. Port Management & Security
  4. DNS Configuration and Troubleshooting
← Back to Linux Server Deployment & SSH Mastery