Linux Firewall Rules: Master List

In the realm of Linux system security, firewall rules play a pivotal role in controlling incoming and outgoing network traffic. They serve as the first line of defense, allowing or denying connections based on predetermined security rules. This article delves into the intricacies of firewall lists and rules on Linux systems, providing a comprehensive guide to help you bolster your system's security.

18 Linux Firewall Software: Protect Your Linux System
18 Linux Firewall Software: Protect Your Linux System

Firewall rules are typically stored in plaintext files, with each rule occupying a single line. These rules are evaluated sequentially, with the first matching rule determining the action taken. Understanding how to manipulate these rules is essential for effective firewall management.

Linux Commands Cheat Sheet for Beginners 2026
Linux Commands Cheat Sheet for Beginners 2026

Understanding Firewall Lists

Firewall lists, or chains, are where rules are stored and evaluated. Linux uses the iptables or nftables utilities to manage these lists, depending on your Linux distribution. The most common firewall lists, or chains, are INPUT, OUTPUT, and FORWARD.

the linux commands for devops poster
the linux commands for devops poster

INPUT: This chain processes incoming traffic destined for the local system. OUTPUT: This chain handles outgoing traffic from the local system. FORWARD: This chain processes traffic passing through the system en route to another destination.

Default Policies

Linux Server Hardening Checklist (2026) 🔐
Linux Server Hardening Checklist (2026) 🔐

Each chain has a default policy that determines the action taken if no matching rule is found. The default policy can be ACCEPT, DROP, or REJECT. DROP silently discards the packet, while REJECT sends an error message to the sender.

To view the default policies, use the following commands:

  • iptables -L INPUT -v -n --line-numbers
  • iptables -L OUTPUT -v -n --line-numbers
  • iptables -L FORWARD -v -n --line-numbers
the fortgate firewall commands poster
the fortgate firewall commands poster

Customizing Default Policies

You can change the default policy using the -P option. For example, to set the INPUT chain's default policy to DROP, use:

iptables -P INPUT DROP

the linux firewall frontends wheel is shown with icons and symbols in it
the linux firewall frontends wheel is shown with icons and symbols in it

Remember, changing default policies can significantly impact your system's connectivity, so proceed with caution.

Crafting Effective Firewall Rules

Linux Commands Cheat Sheet for Hackers & Developers (Must Know)🔥🚀
Linux Commands Cheat Sheet for Hackers & Developers (Must Know)🔥🚀
a black and yellow flyer with linux commands
a black and yellow flyer with linux commands
the linux must know commands list is shown in this screenshote image, and shows how to use them
the linux must know commands list is shown in this screenshote image, and shows how to use them
the basic linux commands are displayed in this screenshot
the basic linux commands are displayed in this screenshot
the linux system tools list is shown in blue and red colors, with several icons on it
the linux system tools list is shown in blue and red colors, with several icons on it
a white sheet with words and pictures on it that include the names of different items
a white sheet with words and pictures on it that include the names of different items
the diagram shows how firewall works and what it is doing to work for them
the diagram shows how firewall works and what it is doing to work for them
Essential Basic Linux Commands You Should Know
Essential Basic Linux Commands You Should Know
the linux command commands list is shown in this screenshote, which shows how to use
the linux command commands list is shown in this screenshote, which shows how to use
the linux command commands are displayed in this poster
the linux command commands are displayed in this poster
Linux Terminal Cheat Sheet
Linux Terminal Cheat Sheet
Linux fundamentals explained simply for beginners (2026 guide) -Day 1–2
Linux fundamentals explained simply for beginners (2026 guide) -Day 1–2
Top 15 Kali Linux Commands Every Ethical Hacker Should Know🚀🎯
Top 15 Kali Linux Commands Every Ethical Hacker Should Know🚀🎯
a white piece of paper with writing on it and an image of a firewall diagram
a white piece of paper with writing on it and an image of a firewall diagram
the linux basics bash commands list
the linux basics bash commands list
Linux Commands you must know🔥
Linux Commands you must know🔥
LINUX
LINUX
Linux Commands
Linux Commands
the basic linux command commands are displayed in this screenshote screen shot, which shows how to use them
the basic linux command commands are displayed in this screenshote screen shot, which shows how to use them
the info sheet shows different types of linuxs and other web services, including security tools
the info sheet shows different types of linuxs and other web services, including security tools

Firewall rules are composed of several elements, including protocol, source, destination, and port. Each rule specifies an action (ACCEPT, DROP, or REJECT) to take when the rule's conditions are met.

Here's an example of a simple firewall rule that allows incoming SSH connections:

iptables -A INPUT -p tcp --dport 22 -j ACCEPT

Rule Components

Let's break down the components of the above rule:

  • -A INPUT: Appends the rule to the INPUT chain.
  • -p tcp: Specifies the protocol (in this case, TCP).
  • --dport 22: Specifies the destination port (SSH uses port 22).
  • -j ACCEPT: Specifies the action to take (accept the connection).

Rule Order and Specificity

Rule order is crucial, as iptables evaluates rules sequentially. More specific rules should come before less specific ones to ensure they're evaluated first. For example, a rule allowing connections from a specific IP address should precede a rule allowing connections from an entire subnet.

To list your current rules, use:

iptables -L -v -n --line-numbers

To save your rules, use:

iptables-save

Or, to save them as a script that can be reapplied:

iptables-save > /path/to/firewall.rules

Firewall management is an ongoing process. Regularly review and update your rules to maintain a strong security posture. Stay informed about emerging threats and adjust your rules accordingly. By mastering firewall lists and rules, you'll significantly enhance your Linux system's security.