VLAN and ACL Design
The zone design of the previous lesson has to become something switches and routers can enforce. Inside a building that usually means VLANs (one per zone, so the zones are separate broadcast domains on shared switches), an address plan (one subnet per VLAN, so every address tells you its zone), and ACLs (access control lists) on the layer-3 device that routes between the VLANs. How VLANs and 802.1Q tags work, and how they are attacked, is in VLANs, 802.1Q Tags and Trunks and VLAN Hopping. This lesson is about designing them so that the network enforces the policy.
An address plan that encodes the zones
A good plan makes the zone readable from the address: the lab company uses 10.10.Z.0 for zone Z and VLAN id 100 + Z (DMZ: VLAN 101, 10.10.1.0/24; servers: VLAN 102, 10.10.2.0/24; staff: VLAN 103, 10.10.3.0/24), the same prefixes as the zone figure of the previous lesson. That makes ACLs short (one prefix per zone), logs readable, and mistakes visible.
Move c to see which zone an address belongs to, and the prefix slider to see what a summary route covers: 10.10.0.0/16 covers every zone at once, which is what an over-broad ACL entry does by accident.
The program builds the plan, checks that no two subnets overlap, and computes what Cisco-style ACLs need: the wildcard mask (the inverse of the netmask, where 1 bits mean "don't care").
import ipaddress
from itertools import combinations
site = ipaddress.ip_network("10.10.0.0/16")
plan = { # VLAN id: (zone, network as written in the design document)
1: ("unused (native, parked)", None),
101: ("dmz", "10.10.1.0/24"), 102: ("servers", "10.10.2.0/24"), 103: ("staff", "10.10.3.0/24"),
105: ("management", "10.10.5.0/26"), 109: ("guest", "10.10.9.0/22"), 199: ("switch management", "10.10.5.64/28"),
}
subnets = {}
for vlan, (zone, text) in plan.items():
if text is None:
continue
net = ipaddress.ip_network(text, strict=False) # what a device would store
subnets[vlan] = (zone, net)
for vlan, (zone, net) in subnets.items():
wildcard = ipaddress.ip_address(int(net.hostmask))
print(f"VLAN {vlan:3} {zone:18} {str(net):16} hosts {net.num_addresses - 2:5} mask {net.netmask} wildcard {wildcard}")
clash = [(a, b) for (a, (_, na)), (b, (_, nb)) in combinations(subnets.items(), 2) if na.overlaps(nb)]
print("inside the site block:", all(n.subnet_of(site) for _, n in subnets.values()))
print("overlaps:", clash or "none")VLAN 101 dmz 10.10.1.0/24 hosts 254 mask 255.255.255.0 wildcard 0.0.0.255
VLAN 102 servers 10.10.2.0/24 hosts 254 mask 255.255.255.0 wildcard 0.0.0.255
VLAN 103 staff 10.10.3.0/24 hosts 254 mask 255.255.255.0 wildcard 0.0.0.255
VLAN 105 management 10.10.5.0/26 hosts 62 mask 255.255.255.192 wildcard 0.0.0.63
VLAN 109 guest 10.10.8.0/22 hosts 1022 mask 255.255.252.0 wildcard 0.0.3.255
VLAN 199 switch management 10.10.5.64/28 hosts 14 mask 255.255.255.240 wildcard 0.0.0.15
inside the site block: True
overlaps: none
The guest line is a deliberate mistake: the guest network needs about a thousand addresses, and someone wrote 10.10.9.0/22. A /22 must start at a multiple of 4 in the third octet, so strict=False (like many devices) silently turned it into 10.10.8.0/22, which covers 10.10.8.0–10.10.11.255. The guest zone now also owns 10.10.8.x, 10.10.10.x and 10.10.11.x, addresses the design reserved for later zones. Misaligned prefixes are a common source of ACLs that cover more (or less) than intended; always print the network a device actually stored.
ACLs between VLANs
On a layer-3 switch or router, an ACL applied inbound on each VLAN interface (the "SVI") filters what that zone may send. The program turns the zone matrix into extended ACL lines in Cisco IOS style, using the plan's wildcard masks, and ends each list with an explicit logged deny.
import ipaddress
NET = {"dmz": "10.10.1.0/24", "servers": "10.10.2.0/24", "staff": "10.10.3.0/24", "management": "10.10.5.0/26"}
ALLOW = { # from zone: [(to zone, proto, port)]
"staff": [("dmz", "tcp", 443), ("servers", "tcp", 445), ("servers", "udp", 53)],
"dmz": [("servers", "tcp", 5432)],
"management": [("servers", "tcp", 22), ("dmz", "tcp", 22)],
}
def addr(zone):
n = ipaddress.ip_network(NET[zone])
return f"{n.network_address} {ipaddress.ip_address(int(n.hostmask))}"
for src, rules in ALLOW.items():
print(f"ip access-list extended FROM-{src.upper()}")
seq = 10
for dst, proto, port in rules:
print(f" {seq} permit {proto} {addr(src)} {addr(dst)} eq {port}")
seq += 10
if src == "dmz":
print(f" {seq} permit tcp {addr(src)} any established"); seq += 10
elif src != "management":
print(f" {seq} deny ip {addr(src)} {addr('management')} log"); seq += 10
print(f" {seq} deny ip any any log")
print("!")ip access-list extended FROM-STAFF
10 permit tcp 10.10.3.0 0.0.0.255 10.10.1.0 0.0.0.255 eq 443
20 permit tcp 10.10.3.0 0.0.0.255 10.10.2.0 0.0.0.255 eq 445
30 permit udp 10.10.3.0 0.0.0.255 10.10.2.0 0.0.0.255 eq 53
40 deny ip 10.10.3.0 0.0.0.255 10.10.5.0 0.0.0.63 log
50 deny ip any any log
!
ip access-list extended FROM-DMZ
10 permit tcp 10.10.1.0 0.0.0.255 10.10.2.0 0.0.0.255 eq 5432
20 permit tcp 10.10.1.0 0.0.0.255 any established
30 deny ip any any log
!
ip access-list extended FROM-MANAGEMENT
10 permit tcp 10.10.5.0 0.0.0.63 10.10.2.0 0.0.0.255 eq 22
20 permit tcp 10.10.5.0 0.0.0.63 10.10.1.0 0.0.0.255 eq 22
30 deny ip any any log
!
Two details to notice. A plain router ACL is stateless (Stateless versus Stateful Filtering): the DMZ list needs a line for return traffic (established matches TCP segments with ACK or RST set), which is weaker than a stateful firewall's connection tracking. That is one reason trust boundaries to and from the DMZ usually go through a stateful firewall, while ACLs on the core switch handle the simpler internal boundaries. And every list ends with deny ip any any log: IOS ACLs already end with an implicit deny, but the explicit one logs.
Layer-2 rules that make VLANs trustworthy
- Access ports in exactly one VLAN, trunking disabled on them (no DTP auto-negotiation); trunks carry only the VLANs they need.
- The native VLAN on trunks set to an unused VLAN (the plan parks VLAN 1 unused), or native tagging on, so double-tagging hops fail.
- Switch management in its own VLAN (199 above), reachable only from the management zone.
- DHCP snooping, dynamic ARP inspection and IP source guard on user VLANs (ARP Spoofing, Rogue DHCP).
- 802.1X (port-based network access control) so a device is placed in its VLAN after authenticating, and unknown devices land in a quarantine or guest VLAN (Asset Inventory).
How the design is verified
- Export the switch configurations and check: every access port's VLAN, every trunk's allowed list and native VLAN, ACLs applied in the right direction on every SVI.
- Scan from one host in each VLAN to the others (within scope) and compare with the matrix.
- Review ACL hit counters (
show access-lists) like firewall counters: zero-hit lines and unexpected hits on the final deny.
Pitfalls
- An ACL written but not applied, or applied
outinstead ofin. - Subnets misaligned to their prefix, as above.
- Inter-VLAN routing on a second device (a firewall and a switch both routing between the same VLANs) so one path bypasses the ACLs.
- "Permit ip any any" added during an outage and never removed.
Practice
1. What is the wildcard mask of a /26, and which addresses does 10.10.5.0 0.0.0.63 match?
The /26 netmask is 255.255.255.192, so the wildcard is 0.0.0.63; it matches 10.10.5.0–10.10.5.63, the management zone.
2. Why can't the staff ACL simply say permit tcp 10.10.3.0 0.0.0.255 any eq 445?
It allows SMB from staff to any destination, including other staff workstations and the DMZ, which is how worms spread. Name the file server's subnet (or host) as the destination.
3. Fix the guest network so that it stays out of the addresses reserved for other zones.
Give the guests an aligned block that no other zone needs, for example 10.10.12.0/22 (12–15) and document it, or 10.10.9.0/24 if 254 addresses are enough. The point is that the stored prefix and the documented one agree.
Test yourself
What is the wildcard mask for a /22 such as 10.10.8.0/22?
- 255.255.252.0
- 0.0.1.255
- 0.0.0.255
- 0.0.3.255
Why does a router ACL from the DMZ need an established line?
- For speed
- ACLs are stateless, so return traffic for allowed connections must be permitted explicitly
- To log drops
- For IPv6
What did ip_network('10.10.9.0/22', strict=False) produce?
- 10.10.9.0/22
- 10.10.8.0/22
- An error
- 10.10.12.0/22
What should the native VLAN of a trunk be?
- VLAN 1, the default
- The users' VLAN
- An unused VLAN (or native tagging enabled)
- The management VLAN