USD ($)
$
United States Dollar
Euro Member Countries
India Rupee

Basic Firewall Concepts

Lesson 41/49 | Study Time: 20 Min

A firewall is a fundamental security mechanism that controls incoming and outgoing network traffic based on predetermined rules. In Linux, firewalls help protect systems by permitting or blocking traffic, thereby preventing unauthorized access and defending against network attacks. 

What is a Firewall?

A firewall is a security system that functions as a barrier between internal trusted networks and external untrusted networks, such as the Internet. It monitors and filters network packets according to configured security rules, controlling the flow of data.

Firewalls can filter traffic based on criteria such as IP addresses, ports, protocols, and connection states, helping to protect networks from unauthorized access and potential threats.

Key Firewall Components

The main components of a firewall include elements that determine how data packets are processed and controlled.


1. Packets: Units of data traveling across networks.

2. Rules: Criteria defining whether packets are allowed or blocked.

3. Chains: Ordered lists of rules to check packets.

4. Tables: Collections of chains for different packet processing tasks (filtering, NAT, etc.).

5. Zones: Groupings of interfaces and associated rules for different trust levels (in tools like firewalld).

Linux Firewall Tools

Linux offers a variety of firewall tools that cater to different skill levels and security requirements.


1. iptables: Traditional command-line firewall utility leveraging Netfilter framework. It uses tables (filter, nat, mangle) and chains (INPUT, OUTPUT, FORWARD). However, complex but powerful for granular control.

2. firewalld: Modern dynamic firewall management service using zones and simplified rules. It is easier to manage, supports runtime and permanent configurations.

3. UFW (Uncomplicated Firewall): User-friendly frontend for iptables, popular on Ubuntu.

Common Rule Types

The following are essential rule types that help define how firewalls handle network packets.


1. Allow: Permits traffic matching the rule.

2. Deny: Blocks traffic and notifies sender.

3. Drop: Silently discards traffic.

4. Reject: Blocks traffic with an error response.

5. Limit: Rate limits connections to prevent abuse such as brute force attacks.

Basic Firewall Operations

Firewalls rely on a few fundamental operations to regulate network traffic and prevent unauthorized access.


1. Set default policies: Decide whether to accept or reject traffic by default. Best practice: Deny all incoming by default and explicitly allow required traffic.

2. Allow/deny ports and services: Control access to network services like SSH (port 22), HTTP (port 80).

3. Block IP addresses or networks: Restrict traffic from suspicious sources.

4. Logging: Record firewall activity for auditing and troubleshooting.

Example iptables Commands


  • Allow incoming SSH traffic:
text
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT


  • Block incoming ping (ICMP) requests:
text
sudo iptables -A INPUT -p icmp -j DROP


  • Set default policy to DROP all inbound traffic:
text
sudo iptables -P INPUT DROP

Firewalld Concept of Zones

Zones categorize interfaces with predefined trust levels.


Examples:


1. public: Default, limited inbound services allowed (e.g., ssh, dhcp).

2. drop: Blocks all incoming connections silently.

3. trusted: Allows all connections.


Configure with commands like:

text
sudo firewall-cmd --zone=public --add-service=ssh --permanent
sudo firewall-cmd --reload
Samuel Wilson

Samuel Wilson

Product Designer
Profile

Class Sessions

1- What is Linux and Operating System Concepts 2- Linux History and Evolution 3- Linux Distributions and Their Purposes 4- Open Source Software and Licensing 5- Graphical User Interface (GUI) and Desktop Environments 6- Terminal Access and Command-Line Fundamentals 7- Getting Help and Command Documentation 8- File System Hierarchy and Directory Structure 9- Navigating Directories and Listing Contents 10- Creating, Copying, and Moving Files and Directories 11- Deleting Files and Directories 12- Symbolic and Hard Links 13- Understanding File Permissions Model 14- Modifying Permissions and Ownership 15- User and Group Management 16- Sudo and Privilege Escalation 17- Text Searching and Pattern Matching 18- Text Processing and Stream Editing 19- Compressing and Archiving Files 20- Text Editing and File Creation 21- Package Management Systems Overview 22- Installing and Updating Software with APT 23- Installing and Updating Software with YUM/DNF 24- Managing Software from Non-Repository Sources 25- Understanding Processes and Process Management 26- Viewing Running Processes 27- Process Control and Termination 28- Task Scheduling with Cron 29- Networking Concepts and IP Addressing 30- Viewing and Configuring Network Interfaces 31- Basic Network Troubleshooting 32- Shell Script Basics 33- Variables and Data Types 34- Conditional Logic in Scripts 35- Loops and Iteration 36- Functions and Code Reuse 37- Input/Output and User Interaction 38- System Authentication and Access Control 39- File System Security 40- Software Updates and Patching 41- Basic Firewall Concepts 42- System Information and Monitoring 43- Service and Daemon Management 44- System Boot Process and Runlevels 45- System Backup and Disaster Recovery 46- Comprehensive File System Management 47- System Automation Workflows 48- Multi-Concept Troubleshooting Scenarios 49- Continued Learning Pathways

Sales Campaign

Sales Campaign

We have a sales campaign on our promoted courses and products. You can purchase 1 products at a discounted price up to 15% discount.