By the end of this lesson you can
- Predict which line of an ACL matches a packet, including the implicit deny
- Write wildcard masks for hosts, subnets and ranges
- Configure numbered and named standard and extended ACLs
- Choose the right interface and direction for each ACL
- Restrict VTY access with access-class and read match counters
How an ACL decides
An access control list is an ordered list of permit and deny lines. When a packet is checked against it, the router:
- Compares the packet with the first line, then the next, top to bottom.
- Stops at the first line that matches and does what it says. Later lines are never read for that packet.
- If no line matches, drops the packet. Every ACL ends with an invisible
deny any.
That last rule causes the classic outage: an ACL with only deny host 192.168.10.10 does block that host, and it also blocks everyone else, because nothing is permitted. If you mean "everyone except this host", add permit any at the end.
| Type | Numbers | Matches on | Place it |
|---|---|---|---|
| Standard | 1 to 99, 1300 to 1999 | Source IP only | Close to the destination, so it does not block the source from everywhere else. |
| Extended | 100 to 199, 2000 to 2699 | Protocol, source, destination, ports, some flags | Close to the source, so unwanted traffic is dropped before it crosses the network. |
On an interface you get one ACL per direction per protocol: one IPv4 ACL in, one out. "In" means packets arriving on that interface, before routing. "Out" means packets leaving it, after routing. Outbound ACLs do not filter packets the router itself generates, such as its own pings or routing updates.
Wildcard masks
ACLs (and OSPF network statements) use wildcard masks: a 0 bit means "this bit must match", a 1 bit means "ignore this bit". For a normal subnet the wildcard is the subnet mask inverted, which you can get by subtracting each octet from 255.
| To match | Address and wildcard | Shortcut |
|---|---|---|
| One host | 192.168.10.10 0.0.0.0 | host 192.168.10.10 |
| A /24 | 192.168.20.0 0.0.0.255 | |
| A /26 (64 addresses) | 192.168.20.64 0.0.0.63 | |
| A /30 | 10.0.13.0 0.0.0.3 | |
| All of 192.168.0.0 to 192.168.255.255 | 192.168.0.0 0.0.255.255 | |
| Everything | 0.0.0.0 255.255.255.255 | any |
Wildcards can also match patterns a subnet mask cannot. 192.168.1.0 0.0.254.255 matches every odd third octet (192.168.1.x, 192.168.3.x and so on). You will rarely write one, but you should recognise that a wildcard is not always a contiguous block.
Numbered, named and extended syntax
! numbered standard
R1(config)#access-list 10 deny host 192.168.10.10
R1(config)#access-list 10 permit any
! named extended, with sequence numbers
R1(config)#ip access-list extended GUEST-IN
R1(config-ext-nacl)#10 permit udp 192.168.20.0 0.0.0.255 host 10.10.10.10 eq domain
R1(config-ext-nacl)#20 permit tcp 192.168.20.0 0.0.0.255 host 10.10.10.10 eq www
R1(config-ext-nacl)#30 deny ip 192.168.20.0 0.0.0.255 192.168.0.0 0.0.255.255 log
R1(config-ext-nacl)#40 permit ip 192.168.20.0 0.0.0.255 any
! insert or delete one line later
R1(config-ext-nacl)#15 permit icmp 192.168.20.0 0.0.0.255 host 10.10.10.10 echo
R1(config-ext-nacl)#no 30
! apply
R1(config)#interface GigabitEthernet0/0/0.20
R1(config-subif)#ip access-group GUEST-IN in- Extended line order:
action protocol source [source port] destination [destination port] [options]. Ports needtcporudp. - Port operators:
eq,neq,gt,lt,range. Names likewww(80) anddomain(53) are accepted. establishedmatches TCP packets with ACK or RST set, which is a cheap way to allow replies. It is a flag check, not session tracking, so it is not a stateful firewall.- Named ACLs give each line a sequence number, so you can insert line 15 between 10 and 20 or delete one line, instead of deleting and retyping a numbered list.
Try it: walk a packet through GUEST-IN
This is the guest VLAN policy from the lab. Pick an example packet, or edit the ACL and type your own, then read the trace to see exactly which line decided.
Notice the last example. GUEST-IN only matches guest sources, so a staff packet falls through to the implicit deny. That is fine, because the ACL is applied only on the guest subinterface, but it shows why applying an ACL to the wrong interface breaks things.
Protecting the router itself
An ACL on a data interface does not protect SSH to the router from every direction. For the VTY lines use access-class, which filters who may open a remote session, whichever interface they arrive on.
R1(config)#ip access-list standard MGMT-ONLY
R1(config-std-nacl)#permit 192.168.99.0 0.0.0.255
R1(config-std-nacl)#deny any log
R1(config)#line vty 0 4
R1(config-line)#access-class MGMT-ONLY inPractise on R1
R1 already routes for VLANs 10, 20 and 99 (router on a stick, as in lesson 3.6) and reaches the server LAN on Gi0/0/1. Match counters in this console are sample numbers, standing in for real traffic.
Missions 0/12
Flashcards: do you remember?
Tap a card to flip it. Try to answer in your head first; recalling is what makes it stick.
Quick quiz
Instant feedback on every answer. Score 70% or more to pass this lesson's quiz.
Q1An ACL contains only access-list 5 deny host 10.1.1.5 and is applied. What happens to traffic from 10.1.1.6?
Nothing permits it, so the invisible deny any drops it.
Q2Which wildcard matches 172.16.8.0/22?
A /22 has 1024 addresses: 4 in the third octet, so 0.0.3.255.
Q3Where should an extended ACL that blocks guests from staff be placed?
Close to the source, so the traffic is dropped as early as possible.
Q4How do you stop non-admins reaching SSH on a router?
access-class filters sessions to the VTYs whatever interface they arrive on.
Q5permit tcp any host 10.1.1.1 eq 22 established matches:
established is a flag check for replies, not session tracking.
Q6How many IPv4 ACLs can be applied inbound on one interface?
One per interface, per direction, per protocol.
Hands-on lab
Packet Tracer lab 3.9: segment guests and lock down management
You need: Cisco Packet Tracer (free with a Cisco Networking Academy account; version 9.0.1 was the current download on the NetAcad Resource Hub when this lesson was written). Start from your lesson 3.6 router on a stick file, or build it: 1 x ISR4331, 2 x 2960, 3 x PC-PT, 1 x Server-PT. SSH from lesson 3.3 should already work on R1 and SW1.
Simulator lab, zero risk. This lab runs inside Cisco Packet Tracer, so it touches no real network. Packet Tracer is free with a Cisco Networking Academy account (netacad.com). It simulates a subset of Cisco IOS, so where support for a feature is uncertain we say so instead of promising it works.
Topology and addressing
| Device | Interface | IPv4 address / prefix | Default gateway or note |
|---|---|---|---|
| R1 | Gi0/0/0.10 / .20 / .99 | 192.168.10.1 / 192.168.20.1 / 192.168.99.1 (/24) | gateways for each VLAN |
| R1 | Gi0/0/1 | 10.10.10.1/24 | server LAN |
| SW1 | VLAN 99 | 192.168.99.2/24 | gateway 192.168.99.1 |
| PC-Staff / PC-Guest / Admin-PC | Fa0 | 192.168.10.10 / 192.168.20.10 / 192.168.99.10 | gateway .1 |
| Server-Web | Fa0 | 10.10.10.10/24 | gateway 10.10.10.1, HTTP and DNS on |
Guest policy, close to the source
ip access-list extended GUEST-IN 10 permit udp 192.168.20.0 0.0.0.255 host 10.10.10.10 eq domain 20 permit tcp 192.168.20.0 0.0.0.255 host 10.10.10.10 eq www 30 deny ip 192.168.20.0 0.0.0.255 192.168.0.0 0.0.255.255 log 35 deny ip 192.168.20.0 0.0.0.255 10.0.0.0 0.255.255.255 log 40 permit ip 192.168.20.0 0.0.0.255 any interface GigabitEthernet0/0/0.20 ip access-group GUEST-IN inManagement lockdown (R1 and SW1)
ip access-list standard MGMT-ONLY permit 192.168.99.0 0.0.0.255 deny any log line vty 0 4 access-class MGMT-ONLY inOn SW1 apply it to
line vty 0 15if that range exists in your model.Insert a line without retyping
R1(config)#ip access-list extended GUEST-IN R1(config-ext-nacl)#15 permit icmp 192.168.20.0 0.0.0.255 host 10.10.10.10 echoStandard ACL near the destination
R1(config)#access-list 10 deny host 192.168.10.10 R1(config)#access-list 10 permit any R1(config)#interface GigabitEthernet0/0/1 R1(config-if)#ip access-group 10 outTest from each PC
From PC-Guest: browse
http://10.10.10.10(works), ping 10.10.10.10 (works after step 3), ping 192.168.10.10 (fails), SSH to 192.168.99.1 (fails). From PC-Staff: browse the server (fails after step 4). From Admin-PC: SSH to R1 (works).Verify
R1#show access-lists R1#show ip interface GigabitEthernet0/0/0.20 R1#show running-config | section vty
You are done when: show access-lists shows every line with a sequence number and match counters that rise only on the lines your tests hit. show ip interface for Gi0/0/0.20 reports GUEST-IN as the inbound list. The VTY section shows access-class MGMT-ONLY in. PC-Staff cannot reach the server but PC-Guest can, because ACL 10 filters by source only.
Packet Tracer limits and notes
- Numbered and named standard and extended ACLs, sequence numbers and
access-classwork in Packet Tracer in the outline author's experience, but test in your own build. - The
logkeyword is accepted, but whether Packet Tracer actually generates log messages for ACL hits is UNVERIFIED. Rely on the match counters. - IPv6 ACLs (
ipv6 access-listwithipv6 traffic-filter) follow the same ideas but are not part of this lab. - Packet Tracer simulates a subset of IOS. If a command here is rejected in your version, note it, skip that step and carry on; the concept still applies to real Cisco gear.
Download the lab checklist (.txt) Print it or keep it open beside Packet Tracer.
Key takeaways
- First match wins, and every ACL ends with an invisible deny any.
- Standard near the destination, extended near the source.
- Wildcard = 255 minus each mask octet for normal subnets.
- Use named ACLs so you can insert and delete single lines.
- Protect the management plane with access-class, and log the denies that matter.
Finished the sections, quiz and lab? Mark the lesson complete. Progress is saved only in this browser.