IPv4 ACL Fundamentals and Wildcard Masks

An access control list is enabled on an interface in one direction, inbound or outbound, and the router reads it from the top: the first matching line's action applies and the router stops looking. Every IP ACL ends with an implicit deny any. A wildcard mask says which bits to ignore: a 0 bit means compare, a 1 bit means ignore.

In Daveth Pro (Network)16 min video

By , founder of Daveth · Updated

Opening frame of the video walkthrough of IPv4 ACL Fundamentals and Wildcard Masks

Watch this lesson

16 min · Video walkthrough

In Daveth Pro (Network)

The full 16 min walkthrough is in Daveth Pro (Network). See what the plan opens

What this page answers

How does a Cisco access list work?

The router reads it from the top; once a packet matches a line, it takes that line's action, permit or deny, and stops. A packet that matches no line meets the implicit deny any at the end. Read it in “First match, then stop”

What is a wildcard mask?

The mask that tells an ACL which parts of an address to ignore. In decimal, 0 means compare this octet and 255 means ignore it; underneath, a 0 bit means compare and a 1 bit means ignore. For a subnet, use 255.255.255.255 minus the subnet mask. Read it in the lesson

Should an ACL be inbound or outbound?

Inbound checks packets as they arrive, before the routing decision; outbound checks them after it, once the exit interface is chosen. Each interface can have one ACL in each direction. Read it in “Where it sits”

A list the router reads from the top

Friday, month seven. Maya brings Lena the question that has sat in the notebook since month one (03.1.1): which packets may cross R1? FW1 is a plan for later, but routers can filter packets today, and R3 already uses three ACLs without anyone calling them filters: ACL 1 picks the addresses its NAT translates (07.2.2), an SNMP ACL accepts polls only from NMS1 (07.3.2), and ACL 5 decides who may even reach its SSH login on the vty lines (07.3.4). Lena reads ACL 5: two lines, both permit, one for Ravi's laptop, 10.100.0.25, and one for R1's end of the R1-R3 link, 10.255.255.1. "Does that let BR1 in?"

An IPv4 access control list (ACL) gives a router a way to identify packets by values it can see in their headers: the IP, TCP and UDP headers. An ACL can match packets from source 10.100.0.25, packets to any destination in a subnet, or packets to TCP port 23 (Telnet). Its most common use is as a packet filter: with the ACL sitting in the forwarding path, the router decides for each packet whether it is discarded or continues as if the ACL weren't there. Routers use the same matching for other features too, like the NAT and SNMP ACLs above, or QoS picking out voice packets so they get better service, with less delay, than data (07.4.1).

Each line says what to look for and what to do if it's found: deny discards the packet, permit lets it continue. (Features other than filtering may read deny and permit differently.) A standard numbered ACL is built from global commands of the form access-list number {permit | deny} address [wildcard], with a number from 1 to 99 or 1300 to 1999; no number works better than another. In a numbered ACL every line carries the same number, and each line is an Access Control Entry (ACE), though many engineers just say ACL statement.

Where it sits

For filtering, an ACL is enabled on an interface, in one direction, and each interface can have one in each direction. (ACL 5 is used another way: on R3's vty lines, it decides who may log in.) Inbound, the router checks packets as they arrive, before its routing decision; outbound, it checks them after the routing decision, once it has chosen the exit interface. Here is the path Jo's print jobs take toward the Staff printer:

Network drawing: the fibre, Jo, BR1, R1, R3, HQD, Gi0/1, Gi0/0, Gi0/0/0, Gi0/1/0

Jo's print job: into BR1 on Gi0/1.10 (Jo's VLAN, on Gi0/1), out on Gi0/0 (the fibre), into R1 on Gi0/0/0, out on Gi0/1/0, into R3 on Gi0/0/0, out of R3 toward the Staff LAN, through HQD's side of head office to the printer. Not drawn: the printer, and BSW1 between Jo and BR1.

The rule to keep: to filter a packet, the ACL must be on an interface the packet passes through, in the direction it passes. Jo's print jobs cross BR1 in on Gi0/1.10 and out on Gi0/0, R1 in on Gi0/0/0 and out on Gi0/1/0, and R3 in on Gi0/0/0 and out toward the Staff LAN, and any of those could hold the filter. They go over the fibre and never touch BR1's backup line, Gi0/1/0, so an ACL there, in or out, never sees one. Once enabled, an ACL is compared with every packet crossing that interface in that direction. Applying one is the next page's job; an ACL that is written but not applied filters nothing.

A rulebook in the drawer stops nobody at the gate.

First match, then stop

An ACL is one thing, enabled where it is used, and also a list. The router reads it from the top: once a packet matches a line, the router takes that line's action and stops looking. That is first-match logic, and it holds for every kind of ACL. It also has no memory: each packet is judged on its own, which is exactly what the stateful firewall of 08.1.4 adds. If you've ever sorted post into pigeonholes, you know first match: each letter goes into the first hole whose label fits, even when a better one sits lower down. (Where it stops: a person might spot the better hole. A router never reads past the first match.)

Ravi drafts ACL 10 for the payroll server, on paper only: line 1 denies the Staff printer, 10.100.0.80, which has no business with payroll; line 2 permits the rest of the Staff LAN, 10.100.0.0/24; line 3 permits the branch.

That's why the printer line goes first. Swap lines 1 and 2 and the /24 would permit the printer before the deny was ever read. And a packet that matches nothing at all? Every IP ACL ends with a deny any that isn't in the configuration: the implicit deny. That is why ACL 5 refuses BR1.

Interactive tool: Read the list from the top The packet's source address 10.255.255.9, BR1's backup-line address 1 access-list 5 permit 10.100.0.25 compared, no match (this line: Ravi's laptop) 2 access-list 5 permit 10.255.255.1 compared, no match (this line: R1's end of the R1-R3 link), deny any the implicit deny: nothing above matched 10.255.255.9 is denied by the implicit deny: no line in ACL

The second receptionist never sees a ticket the first one already stamped.

Two follow-ons. The word any stands for every address; it is the same as the address 0.0.0.0 with the wildcard 255.255.255.255, which ignores all 32 bits. To let everything else through, end the list with permit any, which overrides the implicit deny. And some engineers end a list with an explicit deny any on purpose: it does nothing the implicit one doesn't, but the router keeps a match counter for each configured line, and the implicit deny has none.