Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 37 ยท Firewalls and Segmentation

Network Segmentation, VLANs and the DMZ

Learn how to split a network into security zones with VLANs, subnets, a DMZ and microsegmentation, and verify zone-to-zone policy with a runnable Python matrix.

On a flat network, every device can talk to every other device. That is simple, and dangerous. If an attacker compromises a receptionist's laptop, a flat network lets them reach the file server, the cameras and the database directly. Network segmentation divides the network into smaller zones and controls what may cross between them. The attacker who owns one laptop now stands in a small room with a locked door, not in an open-plan building.

Segmentation is the main answer to the lateral movement stage of the kill chain, and it limits blast radius when things go wrong: malware, misconfigurations and mistakes. This lesson explains the building blocks (subnets, VLANs, DMZs, microsegmentation), shows a typical zone design, and lets you check a segmentation policy as a matrix.

Why segment?

  • Contain compromises. One infected machine cannot easily reach the rest.
  • Protect high-value assets. Payment systems, domain controllers and databases sit in zones with strict rules.
  • Reduce broadcast and noise, improving performance and making monitoring easier.
  • Meet compliance. Standards such as PCI DSS expect payment systems to be isolated.
  • Control guests and untrusted devices. Visitors, IoT gadgets and personal phones go into zones with internet access only.

Building blocks

Subnets and routing

A subnet is an address range (for example 10.10.20.0/24) with its own gateway. Traffic between subnets must pass a router or firewall, which is exactly where you can filter. Separate subnets alone do not create security; you must put filtering at the router or firewall that joins them. A router that forwards everything between subnets is just a bigger flat network.

VLANs

A VLAN (virtual LAN, IEEE 802.1Q) splits one physical switch into several separate layer-2 networks. Ports are assigned to VLANs, and frames carry a VLAN tag (a number from 1 to 4094) when they travel over a trunk link between switches. Devices in different VLANs cannot communicate except through a layer-3 device, so each VLAN usually maps to one subnet.

Typical VLAN plan:

VLAN Name Subnet Purpose
10 Staff 10.10.10.0/24 Employee laptops
20 Servers 10.10.20.0/24 Internal applications
30 Voice 10.10.30.0/24 IP phones
40 Guest 10.10.40.0/24 Visitors, internet only
50 IoT 10.10.50.0/24 Cameras, printers, sensors
99 Management 10.10.99.0/24 Switch and firewall admin interfaces

VLAN hardening tips: do not use VLAN 1 for anything, disable unused ports and put them in an unused "parking" VLAN, set trunk ports explicitly (no automatic trunk negotiation), restrict which VLANs a trunk carries, and prune the native VLAN. The classic VLAN hopping attacks (switch spoofing and double tagging) rely on lax defaults, so these settings matter.

The DMZ

A demilitarised zone (DMZ) is a segment for systems that must be reachable from the internet, such as web servers, mail gateways and reverse proxies. They are placed between two firewalls (or on a separate firewall interface) so that:

  • the internet may reach only specific ports on specific DMZ hosts,
  • DMZ hosts may reach internal systems only through narrow, specific rules (for example web server to one database port),
  • internal users may reach the DMZ,
  • nothing from the DMZ may initiate connections into the internal network in general.

If a DMZ host is compromised, the attacker is still outside your core network.

flowchart TB
    I["Internet"] --> FW["Firewall (3 interfaces)"]
    FW --> DMZ["DMZ: web, mail relay"]
    FW --> STAFF["Staff VLAN 10"]
    FW --> SRV["Servers VLAN 20"]
    FW --> GUEST["Guest VLAN 40"]
    FW --> MGMT["Management VLAN 99"]

All inter-zone traffic crosses the firewall, where the policy is enforced.

Microsegmentation

In data centres and clouds, even servers in the same zone should not trust each other. Microsegmentation applies policy per workload (each virtual machine, container or pod), using host firewalls, hypervisor-level firewalls, cloud security groups or Kubernetes network policies. The rule becomes "the web tier may talk to the app tier on port 8080; nothing else", regardless of where the machines sit physically. It is the practical form of the zero trust idea you will meet later.

Designing a zone policy

Start from needs, not from rules. Ask: which zones exist, and which flows are genuinely required? Write them as a matrix: rows are source zones, columns destination zones, cells are what is allowed. Everything not written is denied.

Typical principles:

  • Staff may reach servers on specific application ports, not everything.
  • Servers should not initiate connections to staff machines.
  • Guest and IoT zones reach the internet only, never internal zones.
  • Management is reachable only from a few admin workstations (a "jump host").
  • The DMZ cannot initiate connections to the internal zones except for named flows.

Verifying a policy as a matrix

A matrix is easy to review and easy to test. The program below defines a zone policy and a set of "must be true" checks, then reports which checks fail. Replace the flows with your own to review a design.

Python Check a zone-to-zone policy

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Three requirements fail on purpose: servers may call back to staff, staff may SSH to servers, and so SSH is not limited to the management zone. Fix the matrix and re-run. Writing requirements as tests, and re-running them after every firewall change, catches accidental openings the same way unit tests catch bugs.

Counting how far an attacker can go

Segmentation is about reachability. Treat the allowed flows as a graph and ask: starting from a compromised zone, which zones can be reached by some chain of allowed connections? The answer is the real blast radius, including indirect paths that nobody drew on the diagram.

Python Blast radius from a compromised zone

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that a compromise of the DMZ reaches servers and, through the reverse flow, staff machines too. Removing one rule shrinks the blast radius considerably. This is why every flow needs a business reason.

Practical tips

  • Start with what is easiest: guest Wi-Fi, IoT devices and printers into their own zones; then servers; then fine-grained rules.
  • Observe before enforcing. Log allowed flows for a few weeks to discover what really talks to what, then write rules.
  • Document zones and owners in one place, kept with your configuration.
  • Do not forget management planes: switch, firewall and hypervisor admin interfaces belong in a dedicated zone.
  • Test from each zone, using authorised checks, to confirm the policy works in practice.

VLANs separate traffic logically, not physically. If a switch is misconfigured or compromised, VLAN isolation can fail. For the highest-value zones, add a firewall between them and, where required, physical separation.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What must you add between two subnets to get security, not just separation?

    Separate subnets only create routing boundaries. The security comes from the policy enforced where traffic crosses between them.
  2. 2. What is the purpose of a DMZ?

    A DMZ keeps exposed servers apart from internal systems, so a compromised public server does not give direct access to the core network.
  3. 3. Which VLAN hardening practice reduces VLAN hopping risk?

    Hopping attacks rely on automatic trunking and native VLAN defaults. Explicit configuration and unused-port shutdown remove those openings.
  4. 4. What does microsegmentation add beyond VLANs and subnets?

    Microsegmentation lets you restrict traffic between individual servers, containers or VMs, limiting lateral movement even inside one segment.
  5. 5. In the blast radius program, what does one questionable reverse flow (servers to staff) do?

    Reachability is transitive. An extra allowed flow can extend the attacker's reach far beyond the zone they started in.

Summary

  • Segmentation divides a flat network into zones and filters between them, limiting lateral movement and blast radius.
  • Subnets give routing boundaries, VLANs split switches into layer-2 networks, a DMZ isolates internet-facing servers, microsegmentation protects individual workloads.
  • Harden VLANs: explicit trunks, no VLAN 1, disable unused ports.
  • Write the zone policy as a matrix, test it as requirements and compute reachability.
  • Start with guest, IoT and servers, observe real flows first, and protect the management plane.

Next: NAT, Proxies and Egress Filtering