Computer Networks Essentials / Network Security

Firewalls

πŸ€” What is a Firewall? (Basic Idea)

When a network is connected to the Internet 🌍, it is exposed to:

  • Hackers πŸ•΅οΈ

  • Malware 🦠

  • Unauthorized users 🚫

πŸ“Œ A firewall acts like a security guard between your network and the outside world.


🧠 Simple Definition

πŸ“Œ A firewall is a hardware or software-based security system that monitors and controls incoming and outgoing network traffic based on predefined security rules.


🧠 Real-Life Analogy

πŸšͺ Security Gate Example

  • Only authorized people are allowed inside

  • Guards check ID before entry

πŸ‘‰ Firewall:

  • Checks data packets

  • Allows or blocks them based on rules


🧭 Where is a Firewall Placed?

A firewall is usually placed:

  • Between internal network and Internet

  • Between trusted and untrusted networks

πŸ“Œ It acts as a barrier.


🎯 Why Firewalls Are Needed

Firewalls help to:

  • πŸ” Protect internal network

  • 🚫 Block unauthorized access

  • πŸ›‘οΈ Prevent attacks

  • πŸ“œ Enforce security policies

  • πŸ“Š Monitor traffic

πŸ“Œ Without firewall β†’ network is exposed ❌


🧩 How a Firewall Works (Simple Flow)

1️⃣ Packet enters firewall

2️⃣ Firewall checks rules

3️⃣ If rule matches β†’ Allow

4️⃣ If rule violates β†’ Block

πŸ“Œ Decision happens in milliseconds ⚑


🧱 Types of Firewalls

Firewalls are classified based on how they inspect traffic.

🧾 1. Packet Filtering Firewall

🧠 What is Packet Filtering?

  • Checks packet headers only

  • Based on:

    • Source IP

    • Destination IP

    • Port number

    • Protocol

πŸ“Œ Works at Network Layer & Transport Layer.

βœ… Advantages

  • Simple

  • Fast

  • Low cost

❌ Disadvantages

  • No payload inspection

  • Vulnerable to spoofing


πŸ”„ 2. Stateful Inspection Firewall

🧠 What is Stateful Firewall?

  • Tracks state of connections

  • Maintains a state table

πŸ“Œ Knows whether a packet is:

  • New

  • Part of an existing connection

βœ… Advantages

  • More secure than packet filtering

  • Blocks fake packets

❌ Disadvantages

  • More resource usage


πŸ§‘β€πŸ’» 3. Application Layer Firewall (Proxy Firewall)

🧠 What is Application Firewall?

  • Works at Application Layer

  • Inspects actual data content

πŸ“Œ Acts as an intermediary (proxy).

βœ… Advantages

  • Very secure

  • Blocks malicious content

❌ Disadvantages

  • Slower

  • Complex configuration


🌐 4. Next-Generation Firewall (NGFW)

🧠 What is NGFW?

Combines:

  • Packet filtering

  • Stateful inspection

  • Application awareness

  • Intrusion prevention

πŸ“Œ Used in modern enterprise networks.

βœ… Features

  • Deep packet inspection

  • Malware protection

  • Application control


🧠 Hardware vs Software Firewalls

🧱 Hardware Firewall

  • Physical device

  • Used in organizations

  • Protects entire network

πŸ’» Software Firewall

  • Installed on individual systems

  • Protects single device

πŸ“Œ Example: Windows Firewall


βš–οΈ Firewall Types Comparison

Type

Layer

Security

Speed

Packet Filtering

L3/L4

Low

Very Fast

Stateful

L3/L4

Medium

Fast

Application

L7

High

Slow

NGFW

Multi-layer

Very High

Moderate


🚫 What Firewalls Can Do

  • Allow or block traffic βœ”οΈ

  • Control ports & protocols βœ”οΈ

  • Log traffic βœ”οΈ


❌ What Firewalls Cannot Do

  • Cannot stop internal attacks ❌

  • Cannot prevent malware already inside ❌

  • Cannot replace antivirus ❌

πŸ“Œ Firewall is one layer of security, not complete protection.


πŸ›‘οΈ Firewall Rules Example

ALLOW TCPfrom192.168.1.0/24toany port80
DENYall incoming traffic

πŸ“Œ Rules are evaluated top to bottom.


🧠 Memory Tricks

  • Packet Filter = Header only πŸ“¦

  • Stateful = Remembers πŸ”

  • Proxy = Middleman 🀝

  • NGFW = All-in-one 🧠


⭐ One-Line Summary

πŸ”Ή A firewall protects a network by filtering traffic based on security rules and preventing unauthorized access.