Linux handles a lot of network traffic, and the firewall takes the first look at those packets before the system does anything with them. It checks what’s coming in, what’s going out, and drops the packets that don’t line up with the rules you set. That first check decides everything, and the packet doesn’t reach the rest of the system until the firewall is done with it.
Trusted and unknown traffic move through the same path, which is why the firewall matters in the first place. It gives you a predictable line between the two. Your rules shape that line, and they decide what the system accepts or refuses. Sometimes the difference is only a single rule.
This guide covers the basics of Linux firewalls from a beginner’s angle. How packets pass through the kernel, how rule layers work, and what the core filtering pieces actually do. It’s enough to set a foundation before you move into anything more detailed.
A Linux firewall reviews packets as they move through the system and decides whether to allow them or stop them. It follows the rules you create, and those rules shape how the machine handles connections. When people talk about a firewall on Linux, they are usually referring to this filtering layer in the kernel.
The firewall sits at a trust line. Traffic from outside gets inspected first, but even local traffic passes through the same checkpoints. This keeps the system’s behavior steady, especially when the network gets noisy.
Netfilter does the heavy lifting inside the kernel. It handles inspection, rule matching, and connection tracking. The tools you use on top are just different ways to manage Netfilter without touching the low-level commands.
Packet filtering is the core job of a packet filtering firewall. The idea is simple. The firewall looks at the details inside each packet and makes a decision based on the rules you set.
Packets move through several checkpoints called chains. Each one covers a different stage in the packet’s path. The firewall reads the packet, tries to match it, and applies the first rule that fits.
Linux supports stateless and stateful filtering. Stateless filtering checks packets one by one. Stateful filtering uses conntrack to remember active connections so the firewall knows which packets belong together.
Linux firewalls read rules from top to bottom, and the first match wins. Once a rule matches, the firewall applies that action and stops looking. This shapes how every packet is handled.
Rule order drives a lot of behavior. A rule placed too early can override the one you meant to use. If no rule matches, the default policy takes over. Beginners often miss that and end up puzzled by traffic that gets dropped or allowed unexpectedly. If you want a simple, high-level explanation of why order matters, you can review our beginner’s guide to firewall rule ordering for a clearer look at how priorities work.
Direction matters as well. Incoming and outgoing packets follow different chains, and each interface has its own context. A rule meant for one interface will not touch another. This is a common point of confusion when people start working with linux firewall rules.
Linux gives you a few main tools for managing firewall rules. They look different, but they all rely on the same filtering engine in the kernel. A quick breakdown helps beginners see where each tool fits.
These tools line up with different comfort levels. Some people want full control. Others want a short command that just works. If you want a quick comparison of the ecosystem, you can check the types of Linux firewalls and see how these layers stack up.
Inbound filtering controls traffic coming into the system. Most beginners stop there, since blocking unwanted inbound traffic feels like the main job of a firewall. It does help, but it is only half of the picture.
Outbound filtering shapes what the system is allowed to send. This matters because a machine can make unsafe connections without you noticing. A simple mistake or a small misconfiguration can let traffic out that never should have left the system. Outbound filtering helps catch that early.
This is why Egress filtering gets attention in security work. It is a basic part of account hygiene, but many new users skip it because they only think of the firewall as a shield for incoming traffic.
Many beginners start with UFW because it comes preinstalled on Ubuntu and Debian. It gives you a short set of commands that handle the common cases. Allow this port. Deny that service. Check your rules. Nothing more complicated than that.
UFW hides the lower layers, so you do not have to deal with chains or rule tables. It is meant for simple setups and small systems. If you just want a basic firewall that works without much tuning, UFW fits that need.
It also lines up cleanly with how Linux manages packet filtering underneath. UFW writes rules for you and lets Netfilter do the rest. If you want a short introduction to how it works, you can review the UFW firewall and see how the commands map to the filtering engine.
Beginners hit the same set of problems when they first work with Linux firewalls. The issues look small at a glance, but each one can throw traffic off in ways that take time to sort out.
These are common first-run errors, and catching them early makes troubleshooting much easier down the line.
These are the questions that show up early when someone starts working with Linux firewalls. They help you build a basic map before you start tuning anything.

iptables is the older interface. It’s everywhere and still works fine. nftables replaces it with a cleaner rule format that the kernel handles more efficiently. Same engine underneath, just a better way to speak to it.
Yes. The ufw firewall is a simple front end that writes the underlying rules for you. It strips out the noise so you can focus on basic allow or deny decisions. Most beginners stick with it until they need more control.
Only if you want zones or expect rules to shift while services stay up, some distros enable it by default, but plenty of setups run cleanly without it. It depends more on your workflow than the tool.
They use different chains. One handles inbound packets, the other handles outbound, and each chain applies its own set of rules. Once you watch the traffic flow a bit, the pattern settles in.
UFW is the usual starting point. The commands stay short, and you don’t need to understand the whole rule stack. It covers the basics and keeps you from wrestling with the lower layers too early.
At this point, you know how Linux handles packets, how the rule layers fit together, and where the main tools sit. That’s the core of it. Everything else builds on those pieces, and they don’t change much across distributions.
Most people take a bit of time to get comfortable reading their own rules. That’s normal. You add a rule, check the behavior, and adjust if something feels off. Over time, the flow makes sense, and the rule set starts to match the system instead of working against it.
If you want to move further, you can review an advanced guide to Linux firewall configuration. It expands on what you learned here, but the basics stay the anchor.