Zones, DMZs and Trust Boundaries
The fix for the flat network of Inadequate Segmentation is not "more VLANs". It is a design: decide which groups of systems trust each other to the same degree, put each group in its own zone, and control every connection that crosses from one zone to another at a trust boundary. The oldest and best-known zone is the DMZ (demilitarised zone): the place for servers the Internet must reach, so that a compromised web server lands the attacker in a small, watched network instead of next to the database.
Zones for the lab company
| Zone | Contains | Trust | Typical inbound |
|---|---|---|---|
| Internet | everyone | none | – |
| DMZ | public web server, mail relay, reverse proxy, VPN endpoint | low: exposed to attack | from the Internet on published ports only |
| Servers (internal) | databases, file and mail stores, internal DNS, directory | high | from DMZ hosts and staff on specific ports |
| Staff | workstations, laptops | medium: users click links | almost nothing |
| Management | admin workstations, bastion, BMCs, switch and firewall management | highest | from nowhere except VPN users with MFA landing on the bastion |
| Guest / IoT | visitors' devices, cameras, TVs | none | nothing; outbound to the Internet only |
Three rules give the DMZ its value:
- The Internet reaches only the DMZ, and only on published ports.
- The DMZ reaches the internal servers only on the specific ports its services need (the web server to the database on 5432), never "any".
- Internal zones may reach the DMZ, but nothing in the DMZ starts connections to staff or management.
A mail relay in the DMZ that forwards to an internal mail store, a reverse proxy in the DMZ in front of an internal application: these "two-hop" designs keep the internal systems unreachable from the Internet even if the DMZ host is fully compromised, because the firewall still decides what it may reach.
The policy as a matrix
A zone design is written down as a zone policy matrix: for every pair (from, to), what is allowed. It is the single document reviews, scans and firewall rules are checked against, and it can generate the rules.
MATRIX = { # (from, to): [(proto, ports, comment)]
("internet", "dmz"): [("tcp", "80,443", "public web"), ("tcp", "25", "inbound mail to relay")],
("dmz", "servers"): [("tcp", "5432", "www -> db"), ("tcp", "25", "relay -> mail store")],
("staff", "dmz"): [("tcp", "80,443", "staff use the website")],
("staff", "servers"): [("tcp", "143,587,445", "mail, files"), ("udp", "53", "dns")],
("management", "dmz"): [("tcp", "22", "admin via bastion")],
("management", "servers"): [("tcp", "22", "admin via bastion")],
("guest", "internet"): [("tcp", "80,443", "web only")],
("staff", "internet"): [("tcp", "80,443", "web via proxy")],
}
NETS = {"dmz": "10.10.1.0/24", "servers": "10.10.2.0/24", "staff": "10.10.3.0/24",
"management": "10.10.5.0/24", "guest": "10.10.9.0/24"}
IFACE = {"internet": "wan0", "dmz": "dmz0", "servers": "srv0", "staff": "staff0", "management": "mgmt0", "guest": "guest0"}
print("table inet zones {")
print(" chain forward {")
print(" type filter hook forward priority filter; policy drop;")
print(" ct state established,related accept")
print(" ct state invalid drop")
for (src, dst), allows in MATRIX.items():
for proto, ports, comment in allows:
p = f"{{ {ports.replace(',', ', ')} }}" if "," in ports else ports
print(f' iifname "{IFACE[src]}" oifname "{IFACE[dst]}" {proto} dport {p} accept comment "{comment}"')
print(' counter log prefix "zone-drop: " drop')
print(" }")
print("}")
zones = list(IFACE)
denied = [(a, b) for a in zones for b in zones if a != b and (a, b) not in MATRIX]
print(f"# {len(MATRIX)} zone pairs allowed, {len(denied)} denied by default, e.g. dmz->staff:",
("dmz", "staff") in denied, " guest->servers:", ("guest", "servers") in denied)table inet zones {
chain forward {
type filter hook forward priority filter; policy drop;
ct state established,related accept
ct state invalid drop
iifname "wan0" oifname "dmz0" tcp dport { 80, 443 } accept comment "public web"
iifname "wan0" oifname "dmz0" tcp dport 25 accept comment "inbound mail to relay"
iifname "dmz0" oifname "srv0" tcp dport 5432 accept comment "www -> db"
iifname "dmz0" oifname "srv0" tcp dport 25 accept comment "relay -> mail store"
iifname "staff0" oifname "dmz0" tcp dport { 80, 443 } accept comment "staff use the website"
iifname "staff0" oifname "srv0" tcp dport { 143, 587, 445 } accept comment "mail, files"
iifname "staff0" oifname "srv0" udp dport 53 accept comment "dns"
iifname "mgmt0" oifname "dmz0" tcp dport 22 accept comment "admin via bastion"
iifname "mgmt0" oifname "srv0" tcp dport 22 accept comment "admin via bastion"
iifname "guest0" oifname "wan0" tcp dport { 80, 443 } accept comment "web only"
iifname "staff0" oifname "wan0" tcp dport { 80, 443 } accept comment "web via proxy"
counter log prefix "zone-drop: " drop
}
}
# 8 zone pairs allowed, 22 denied by default, e.g. dmz->staff: True guest->servers: True
The generated ruleset is readable as the policy: one line per allowed flow, nothing between other zone pairs, replies allowed by connection tracking, everything else logged and dropped. Generating rules from the matrix (rather than editing rules by hand) keeps the two in sync; Reading and Writing nftables Rulesets explains each line.
How boundary violations are detected
- Drop logs at each boundary:
zone-drop:lines fromdmz0tostaff0mean a DMZ host is trying to reach inside, which is one of the strongest signals of a compromised DMZ server. - Scans from each zone compared with the matrix (the assessment check of Topology Mapping).
- Allowed-flow monitoring: unusual volume or new peers on an allowed path (the web server suddenly sending gigabytes to the database zone).
How the design is kept honest
- Every exception goes into the matrix with an owner and a reason, not straight into the firewall.
- The DMZ hosts are hardened more than internal ones: minimal services, no outbound Internet except what they need (updates through a proxy), host firewalls too.
- The management zone has the smallest set of entry points; see Bastion Hosts.
Pitfalls
- A DMZ host with a second interface into the internal network: the zone boundary is bypassed (the
backuphost of the topology lesson). - "DMZ to internal any" to make an application work: the DMZ becomes pointless.
- Putting the VPN's users into the server zone: VPN users are staff devices from outside and belong in a staff-like zone.
- Zones without monitoring: a boundary nobody logs is a boundary nobody notices being crossed.
Practice
1. Where does a public API gateway go, and where does the API's database go?
The gateway (reverse proxy) in the DMZ; the database in the internal server zone, reachable from the gateway (or the application tier) only on its port. If the application servers are separate, they form their own zone between DMZ and data.
2. Add a rule to the matrix so the management zone can reach the firewalls' and switches' management on HTTPS. Where do those interfaces live?
In the management zone itself (dedicated management interfaces or VLAN), so the rule is within the zone; or add ("management", "servers"): ("tcp", "443", ...) for devices that only have in-band interfaces. Never from staff.
3. A log shows zone-drop: IN=dmz0 OUT=staff0 SRC=10.10.1.10 DST=10.10.3.5 DPT=445. What does it mean?
The web server tried to open an SMB connection to a staff workstation. Web servers have no reason to do that: treat it as a possible compromise of 10.10.1.10 and start incident response.
Test yourself
What is the purpose of a DMZ?
- To speed up the web server
- To hold Internet-facing servers in a separate zone, so their compromise doesn't give access to internal networks
- To store backups
- To host guest Wi-Fi
Which flow should never be allowed in a classic DMZ design?
- Internet → DMZ on 443
- DMZ web server → internal DB on 5432
- DMZ → staff workstations
- Staff → DMZ on 443
In the generated ruleset, what happens to traffic from guest to servers?
- Accepted
- Logged and dropped by the final rule
- Rejected with ICMP
- Forwarded to the DMZ