Skip to content

Expert · Network security · topic 45 of 57 · 30 min

Firewalls, IPS and VPNs

Explanation

A firewall controls traffic between zones such as inside, outside and DMZ. A stateful firewall remembers connections, so replies to inside users come back in while unrequested traffic is blocked. An IPS sits in the traffic path and blocks attacks it recognises; an IDS only watches and alerts. VPNs carry private traffic safely across the internet: site-to-site IPsec joins offices, and remote-access VPNs connect single users.

Why firewalls?

Routers move packets as fast as they can. A firewall is a device (or software) whose main job is to decide which traffic is allowed between parts of the network, based on a security policy. It usually sits at the internet edge, and often between internal zones too, such as between the staff network and the data centre.

Zones

Firewalls think in zones: groups of interfaces with the same trust level. A typical design has an inside zone (staff, trusted), an outside zone (the internet, untrusted) and a DMZ (demilitarised zone) for public servers like the company website. The usual policy: inside may start connections to outside and DMZ; outside may reach only specific services in the DMZ; nothing from outside may start a connection to inside.

Packet filter vs stateful firewall

A packet filter, such as a router ACL, looks at each packet on its own: addresses, protocol and ports. It does not remember anything. To let replies come back to inside users, you would have to permit wide ranges of inbound traffic, which is risky.

A stateful firewall keeps a state table (also called a connection table) of every session that started from the inside: source and destination address, ports and protocol. When a reply arrives from outside, the firewall checks the table. If it matches a known session, it is allowed; if not, it is dropped. So inbound traffic is allowed only when an inside user asked for it.

Think of it like this: A stateful firewall is like a housing society guard with a visitor book. When you order food, the guard notes "flat 302 expects a delivery". The delivery person is let in because the book says so. A stranger who just turns up is stopped. A plain packet filter is a guard with no book, who can only say "all delivery uniforms allowed" or "none".

Next-generation firewalls (NGFW)

A next-generation firewall adds deeper checks on top of stateful filtering: application awareness (recognising WhatsApp, YouTube or a database protocol even on unusual ports), user identity (rules by user or group, not just IP), URL filtering, an integrated IPS, malware and file checks, and often TLS decryption for inspection. Cisco Secure Firewall, Palo Alto Networks and Fortinet FortiGate are common examples.

IDS and IPS

IDS (Intrusion Detection System)IPS (Intrusion Prevention System)
PositionOff to the side; gets a copy of traffic (for example from a SPAN port)Inline: traffic passes through it
ActionDetects and alertsDetects and blocks in real time
Effect on trafficNone; it cannot stop the first packetCan drop attack packets; adds a little delay

Both detect attacks with signatures (patterns of known attacks, updated like antivirus) and with anomaly detection (traffic very different from normal). A false positive is normal traffic wrongly flagged; tuning the rules reduces them.

VPNs: private traffic over a public network

Leased private lines between offices are expensive. A VPN (Virtual Private Network) builds an encrypted tunnel across the internet instead. Each packet is wrapped inside another packet: outsiders see only the outer header between the two VPN endpoints, and the content is encrypted.

  • Site-to-site VPN: a permanent tunnel between two offices' routers or firewalls. Users do nothing special; the devices handle it. Example: bank branches connecting to the head office data centre.
  • Remote-access VPN: one user's laptop or phone connects to the office using a VPN client, with TLS/SSL (for example Cisco Secure Client, formerly AnyConnect) or IPsec. Used by staff working from home or travelling.

What IPsec provides

IPsec is a set of standards for protecting IP packets, used for most site-to-site VPNs. It provides four things:

  • Confidentiality: the data is encrypted (for example with AES), so it cannot be read.
  • Integrity: a hash (for example SHA-256) shows if a packet was changed on the way.
  • Authentication: each end proves who it is, with a pre-shared key or certificates.
  • Anti-replay: sequence numbers stop an attacker re-sending old captured packets.

IKE (Internet Key Exchange, UDP 500, or UDP 4500 when NAT is in the path) sets up the keys. ESP (Encapsulating Security Payload) then carries the protected traffic and gives all four protections. AH (Authentication Header) gives integrity and authentication but no encryption, so ESP is what you normally use.

GRE: a tunnel without a lock

GRE (Generic Routing Encapsulation) also wraps packets in a tunnel, and it can carry multicast and routing protocol traffic such as OSPF, which plain IPsec tunnels cannot. But GRE has no encryption by itself. So designs often run GRE inside IPsec (GRE over IPsec): GRE for flexibility, IPsec for security.

Careful: Common mistakes: believing a GRE tunnel is private (it is not encrypted), mixing up IDS and IPS (only an IPS is inline and can block), and opening wide inbound rules on a stateless ACL when a stateful firewall would allow replies automatically. Also, a VPN protects data in transit only; it does not make an infected laptop safe.

Where zero trust fits

Older designs trusted anything inside the network. Zero trust means "never trust, always verify": every user and device must prove who it is, and is checked for health, before it gets access to each application, wherever it is. VPNs, firewalls, 802.1X and MFA are still the building blocks; zero trust changes the mindset from "inside is safe" to "check every request".

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

Firewalls, IPS and VPNs · 1/8

Firewalls, IPS, VPN

This lesson covers firewalls, intrusion prevention and VPNs, the devices that guard the edges of a network.

Prefer a video by a teacher? Find free videos on “CCNA firewalls IPS IDS site-to-site IPsec remote access VPN explained” on YouTube ↗

In real life: Bank branches linked to head office

A co-operative bank in Maharashtra has 60 branches. Each branch has a small firewall with an internet link and a 4G backup. A site-to-site IPsec tunnel runs from every branch to the data centre in Mumbai, so teller terminals reach the core banking system encrypted, even over the public internet. The data centre firewall is stateful with an IPS turned on, and the internet banking servers sit in a DMZ. Officers working from home use a remote-access VPN with MFA.

Practice (0/3 done)

Task 1 · Question

Which device sits inline and can drop attack traffic as it passes?

Task 2 · Code · Javascript

Simulate a tiny stateful firewall. Write firewall(packets). Each packet is an object { dir, src, sport, dst, dport, proto } where dir is "out" (inside to outside) or "in" (outside to inside). - Every "out" packet is allowed, and its session is remembered. - An "in" packet is allowed only if it is the reply to a remembered session: its src and sport equal the session's dst and dport, its dst and dport equal the session's src and sport, and the proto is the same. Return an array of "allow" or "drop", one per packet, in order.

Task 3 · Practice

A company has a head office in Bengaluru and two branch offices, plus 30 sales staff who travel. Write a short plan (6 to 8 lines) for how they should connect securely, naming the VPN types and what IPsec protects.

Quick quiz

Question 1

1.What lets a stateful firewall allow a reply from a web server back to an inside user?

Question 2

2.Where should a company place its public web server in a firewall design?

Question 3

3.Which of these does GRE provide by itself?

Question 4

4.Which IPsec service stops an attacker from re-sending captured packets later?

Question 5

5.An employee working from a hotel connects her laptop to the office. What type of VPN is that?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

What lets a stateful firewall allow a reply from a web server back to an inside user?

Answer: Its state table of sessions started from the inside

The firewall remembers the outgoing session and allows only matching replies.

Where should a company place its public web server in a firewall design?

Answer: DMZ

A DMZ lets the internet reach the server while keeping it separate from the trusted inside network.

Which of these does GRE provide by itself?

Answer: A tunnel that can carry multicast and routing protocols

GRE encapsulates traffic, including multicast, but has no encryption; it is often run over IPsec.

Which IPsec service stops an attacker from re-sending captured packets later?

Answer: Anti-replay

Anti-replay uses sequence numbers so old packets are rejected.

An employee working from a hotel connects her laptop to the office. What type of VPN is that?

Answer: Remote-access

A single user connecting with a VPN client uses a remote-access VPN.

A VPN that permanently joins two offices is…Related

Answer: Site-to-site

Site-to-site VPNs link networks, usually with IPsec.

From Network segmentation, zero trust and VPNs

Which device can block traffic as well as alert?Related

Answer: IPS

An IPS is inline and can drop malicious packets.

From Intrusion detection and prevention (IDS/IPS)

Which option gives a dedicated private line from your data centre to AWS?Related

Answer: AWS Direct Connect

Direct Connect is a dedicated connection through a partner location. VPN runs over the public internet.

From VPC security and connectivity

What does a stateful firewall add over a stateless packet filter?Related

Answer: It tracks connections, allowing replies to permitted traffic automatically

It remembers connection state, so you do not need separate rules for replies.

From Firewalls

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. This is the last topic of “Network security”. The module exam comes next.
  2. Module 9 exam: Network security · 13 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Wireless networking. 57 topics left in the course before the final exam.

← Previous: Layer 2 security: port security, DHCP snooping, DAI