Firewall and Security Group


Firewall

A Firewall is a network security device that monitors incoming and outgoing network traffic and decides whether to allow or block specific traffic based on a defined set of security rules.

Think of a Firewall as the Security Guard (or Bouncer) of your network.

1. The Core Concept: The Club Bouncer

Imagine your computer network is an exclusive club.

  • The Internet is the street outside (full of strangers, some good, some bad).

  • The Firewall is the bouncer at the door.

Every time someone (a data packet) tries to enter, the bouncer stops them and checks a list of rules:

  1. "Are you on the guest list?" (Allowed IP address)

  2. "What kind of business do you have here?" (Port number/Service)

  3. "Are you carrying any weapons?" (Malware scanning - simpler firewalls don't do this, but advanced ones do).

If the packet meets the criteria, the gate opens. If not, the packet is Dropped (ignored) or Rejected (sent back with a "No Entry" notice).

2. How it decides: The Rules

Firewalls operate on "Access Control Lists" (ACLs). These are simple logic statements: If X, then Y.

  • Rule A: IF traffic comes from https://www.google.com/search?q=Google.com, THEN Allow.

  • Rule B: IF traffic comes from 'Hacker-IP-Address', THEN Block.

  • Rule C (The most common): IF traffic is trying to access Port 80 (Web Browsing), THEN Allow.

  • Default Rule: If I don't recognize you, THEN Block Everything. (This is called "Implicit Deny" and is a best practice).

3. Visualizing the Firewall

Here is a diagram showing traffic flowing from the Internet to your Local Network (LAN). Notice how the "Malicious" traffic is stopped at the wall.

4. Types of Firewalls (Stateful vs. Stateless)

To understand firewalls deeply, you must understand "State." This is the most common interview question regarding firewalls.

A. Stateless (Packet Filtering) - The "Dumb" Guard

This guard checks every single person individually without memory.

  • Scenario: You leave the building to get lunch. When you come back, the guard stops you. "Who are you? Are you on the list?" He doesn't remember that you just left.

  • Technical: It looks at Layer 3 (IP) and Layer 4 (Ports) of each packet in isolation.

B. Stateful Inspection - The "Smart" Guard

This guard remembers context.

  • Scenario: You leave for lunch. When you return, the guard waves you through immediately. "Oh, I saw him leave 10 minutes ago, so he must be allowed back in."

  • Technical: If your computer initiates a connection (e.g., you request a website), the firewall remembers this "State." When the website replies with data, the firewall automatically lets it in because it was requested, without checking the rules list again.

5. Where does it sit in the OSI Model?

Using the model we just discussed:

  • Traditional Firewalls: Operate at Layer 3 (Network) and Layer 4 (Transport). They look at IP addresses and Port numbers.

  • Next-Generation Firewalls (NGFW): Operate all the way up to Layer 7 (Application). They can look inside the data. They can say, "I see this traffic is going to Facebook (Layer 7), but I am configured to block Social Media, so I will stop it."


Security Group

A Security Group is essentially a Cloud Firewall.

If you are working with cloud providers like AWS (Amazon Web Services) or Azure, you will hear this term constantly. While a traditional firewall usually protects an entire building (network), a Security Group protects a single room (a specific server or "instance").

Here is the breakdown of how it differs from the standard firewall concept we just discussed.

1. The Analogy: Gated Community vs. House Door

To understand where Security Groups fit in, imagine a Gated Community (a Cloud Network/VPC):

  1. Network ACL (Traditional Firewall): This is the Main Gate to the community. It checks everyone entering the neighborhood. If the Main Gate says "No," you can't even get on the street.

  2. Security Group: This is the Front Door Lock on your specific house. Even if the Main Gate lets someone in, they still need a key to get into your specific living room.

2. Key Characteristics of Security Groups

  • Instance Level: They operate directly on the server (virtual machine). You can have 10 servers in the same network, but Server A allows web traffic (HTTP) and Server B allows only database traffic (SQL).

  • Stateful: Just like the "Smart Guard" we discussed earlier. If your server sends a request out to download an update, the Security Group automatically lets the update file back in. You don't need to create a rule for the return trip. This means that if outbound traffic is allowed, the return inbound traffic is automatically allowed

  • "Allow" Rules Only: This is a major difference. In most Security Groups (like AWS), you cannot create a "Deny" rule.

    • Firewall: "Block that specific hacker IP."

    • Security Group: You can't say "Block IP X." Instead, the Security Group blocks everyone by default, and you only list the people who are allowed.

3. Visualizing the Layers of Defense

Here is how a request from the internet has to pass through the Network Firewall (often called a NACL in the cloud) and the Security Group to reach your application.

4. Comparison: Network ACL vs. Security Group

In a cloud environment (like AWS), you often use both. Here is how they compare:

Feature

Network Firewall (NACL)

Security Group

Protection Scope

Protects the whole Subnet (Neighborhood).

Protects the Specific Instance (House).

Rule Type

Can Allow AND Deny.

Can only Allow. (Everything else is denied implicitly).

Memory (State)

Stateless: You must explicitly allow return traffic.

Stateful: Return traffic is automatically allowed.

Order

Rules are processed in number order (1, 2, 3...).

All rules are evaluated before deciding.

In summary: A Security Group is a personal, highly specific, smart firewall attached directly to your virtual server.


Last updated