Catalog / Firewall Configuration Cheatsheet
Firewall Configuration Cheatsheet
A comprehensive cheat sheet covering essential firewall configurations, rules, and best practices for various operating systems and network environments. This guide provides quick references and examples to help secure your systems effectively.
Firewall Fundamentals
Basic Concepts
What is a Firewall? |
Types of Firewalls:
|
Key Functions:
|
Default Policy:
Default Deny is generally more secure. |
Firewall Rule Components
Source IP Address |
The IP address or address range from which the traffic originates. |
Destination IP Address |
The IP address or address range to which the traffic is directed. |
Source Port |
The port number from which the traffic originates. |
Destination Port |
The port number to which the traffic is directed. |
Protocol |
The communication protocol used (e.g., TCP, UDP, ICMP). |
Action |
The action to take when a rule matches (e.g., ALLOW, DENY, REJECT). |
iptables (Linux)
iptables Commands
|
List all current rules in all tables. |
|
List rules in a specific table (e.g., |
|
Append a new rule to the end of a chain (e.g., |
|
Insert a new rule at the beginning of a chain. |
|
Delete a rule by its number in the chain. Use |
|
Flush all rules in the current table. |
|
Delete a user-defined chain. |
|
Set the default policy for a chain (e.g., |
|
Display all rules in iptables using the command syntax. |
Example iptables Rules
Allow SSH traffic: |
Allow HTTP traffic: |
Allow HTTPS traffic: |
Drop all ICMP traffic: |
Allow established and related connections: |
Drop all other incoming traffic (Default Deny): |
Saving iptables Rules
To save iptables rules on Debian/Ubuntu: |
To save iptables rules on CentOS/RHEL: |
firewalld (Linux)
firewalld Basics
firewalld is a dynamic firewall management tool with support for network/firewall zones to define the trust level of network connections. |
Key Concepts:
|
firewalld Commands
|
Check the status of firewalld. |
|
Get the default zone. |
|
Set the default zone (e.g., |
|
List active zones. |
|
List all settings for a zone. |
|
List all available services. |
|
Add a service to a zone permanently. |
|
Remove a service from a zone permanently. |
|
Add a port to a zone permanently. |
|
Reload firewalld to apply changes. |
Example firewalld Configurations
Allow SSH traffic in the public zone: |
Allow HTTP and HTTPS traffic in the public zone: |
Allow a custom port (e.g., 8080) in the public zone: |
Remove a service (e.g., http) from the public zone: |
ufw (Ubuntu Firewall)
ufw Basics
ufw (Uncomplicated Firewall) is a user-friendly frontend for iptables, designed to simplify firewall management. |
ufw provides a command-line interface for managing firewall rules, making it easier to configure common firewall settings. |
ufw Commands
|
Enable the firewall. |
|
Disable the firewall. |
|
Check the status of the firewall. |
|
Set the default incoming policy to deny. |
|
Set the default outgoing policy to allow. |
|
Allow traffic on a specific port. |
|
Deny traffic on a specific port. |
|
Allow traffic for a specific service (e.g., ssh, http, https). |
|
Delete a specific rule. |
|
Reload the firewall to apply changes. |
Example ufw Configurations
Allow SSH traffic: |
Allow HTTP traffic: |
Allow HTTPS traffic: |
Allow traffic on port 8080: |
Deny traffic on port 25: |
Delete a rule allowing port 8080: |