Expert · Network security · topic 43 of 57 · 35 min
Access control lists (ACLs)
Explanation
What an ACL does
An access control list (ACL) is a list of rules, each saying permit or deny for a kind of traffic. Applied to an interface, it filters packets: the router checks each packet against the list and forwards or drops it. ACLs are also used just to match traffic for other features, for example to say which addresses NAT should translate or which traffic QoS should prioritise. In that case "permit" means "this traffic is selected", not "this traffic passes".
Standard and extended ACLs
| Standard | Extended | |
|---|---|---|
| Numbers | 1 to 99 and 1300 to 1999 | 100 to 199 and 2000 to 2699 |
| Matches | Source IP address only | Protocol, source IP, destination IP, and TCP or UDP ports |
| Where to place | Close to the destination | Close to the source |
Named ACLs use a name instead of a number, such as GUEST-IN. They work the same way but are easier to read and easier to edit. Most engineers use named ACLs today.
Wildcard masks, host and any
ACLs use a wildcard mask instead of a subnet mask. In a wildcard mask, a 0 bit means "this bit must match" and a 1 bit means "ignore this bit". So it is the inverse of the subnet mask: subtract each octet of the mask from 255. For 255.255.255.0 the wildcard is 0.0.0.255, so 192.168.10.0 0.0.0.255 matches every address from 192.168.10.0 to 192.168.10.255.
- host 10.0.0.5 is short for 10.0.0.5 0.0.0.0: exactly one address.
- any is short for 0.0.0.0 255.255.255.255: every address.
- For a /26 (255.255.255.192) the wildcard is 0.0.0.63.
How the router reads an ACL
- Rules are checked top-down, in order of sequence number.
- The first rule that matches decides: permit or deny. The rest are not checked.
- If no rule matches, the packet hits the implicit "deny any" at the end, which you never see in the configuration.
Writing and applying ACLs
! Standard named ACL: only the IT subnet may reach the server LAN
R1(config)# ip access-list standard IT-ONLY
R1(config-std-nacl)# permit 192.168.50.0 0.0.0.255
R1(config-std-nacl)# exit
R1(config)# interface gigabitEthernet0/2
R1(config-if)# ip access-group IT-ONLY outip access-group NAME in checks packets as they arrive on the interface; out checks them as they leave. You can have only one ACL per interface, per direction, per protocol: one IPv4 inbound, one IPv4 outbound (and IPv6 has its own). Applying a second ACL in the same direction replaces the first.
Worked example: guests must not reach finance
An office has a guest VLAN 30 (192.168.30.0/24) and a finance server at 10.10.10.20. Guests should use the internet but never reach the finance server. An extended ACL can match the destination, so we place it close to the source: inbound on the guest VLAN gateway interface.
R1(config)# ip access-list extended GUEST-IN
R1(config-ext-nacl)# 10 deny ip 192.168.30.0 0.0.0.255 host 10.10.10.20
R1(config-ext-nacl)# 20 deny ip 192.168.30.0 0.0.0.255 10.0.0.0 0.255.255.255
R1(config-ext-nacl)# 30 permit udp 192.168.30.0 0.0.0.255 any eq 53
R1(config-ext-nacl)# 40 permit tcp 192.168.30.0 0.0.0.255 any eq 443
R1(config-ext-nacl)# 50 permit tcp 192.168.30.0 0.0.0.255 any eq 80
R1(config-ext-nacl)# exit
R1(config)# interface gigabitEthernet0/1.30
R1(config-subif)# ip access-group GUEST-IN inWhy not use a standard ACL? It can only look at the source. Placed near the guests, it would block guests from everything, including the internet. That is why standard ACLs go close to the destination and extended ones close to the source: extended ACLs can be precise, so they drop unwanted traffic early before it crosses the network.
Editing and checking
Named ACL rules have sequence numbers (10, 20, 30 by default). To insert a rule between 10 and 20, enter the ACL and type 15 followed by the rule. To remove one, type no 20. show access-lists lists every rule with a hit counter, such as "(42 matches)", which shows which rules are really used. clear access-list counters resets them.
R1# show access-lists GUEST-IN
Extended IP access list GUEST-IN
10 deny ip 192.168.30.0 0.0.0.255 host 10.10.10.20 (12 matches)
20 deny ip 192.168.30.0 0.0.0.255 10.0.0.0 0.255.255.255 (3 matches)
30 permit udp 192.168.30.0 0.0.0.255 any eq domain (880 matches)
40 permit tcp 192.168.30.0 0.0.0.255 any eq 443 (5120 matches)
50 permit tcp 192.168.30.0 0.0.0.255 any eq www (97 matches)Common mistakes
- A broad rule above a specific one: "permit ip any any" at line 10 makes every later deny useless. Put specific rules first.
- Wrong direction: an inbound ACL applied out (or the reverse) matches the wrong traffic. Picture the packet arriving at or leaving the router.
- Using a subnet mask instead of a wildcard: 192.168.10.0 255.255.255.0 means something very different. Write 0.0.0.255.
- Forgetting the implicit deny, and blocking DNS so "the internet is down" even though web traffic is permitted.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Access control lists (ACLs) · 1/7
An access control list is an ordered list of permit and deny rules that a router checks against packets.
Prefer a video by a teacher? Find free videos on “CCNA standard extended named ACL wildcard mask tutorial” on YouTube ↗
In real life: A bank branch separates customer Wi-Fi from core banking
A private bank branch in Jaipur offers free Wi-Fi to customers while they wait. The customer VLAN must never reach the core banking terminals or the branch server. An extended ACL on the router subinterface for the customer VLAN denies all traffic to the internal 10.0.0.0/8 range, then permits only DNS and web traffic to the internet. The hit counters on the deny line are reviewed every month as part of the branch security check.
Practice (0/3 done)
Write wildcard(mask) that turns a dotted subnet mask into an ACL wildcard mask by subtracting each octet from 255. Example: wildcard("255.255.255.0") returns "0.0.0.255".
Write evaluate(rules, packet), a small ACL checker. Each rule is a tuple (action, src, dst, proto, port): action is "permit" or "deny"; src and dst are a network like "192.168.30.0/24" or "any"; proto is "ip" (matches every protocol), "tcp" or "udp"; port is a number or None (None matches any port). packet is a dict with keys src, dst, proto and port. Check the rules top-down. Return (action, rule_number) for the FIRST match, with rule_number counted from 1. If nothing matches, return ("deny", 0) for the implicit deny. Use the ipaddress module.
You must stop VLAN 20 users from reaching one web server, but allow everything else. Which ACL type and placement is best?
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Layer 2 security: port security, DHCP snooping, DAINetwork security · same module
- Security basics: threats, CIA and AAANetwork security · same module
- Access control lists (ACLs)Linux and Red Hat (RHCSA to RHCE) · Permissions, users and sudo
- VPC security and connectivityCloud Computing (AWS, Azure, Google Cloud) · Networking and databases: VPC and RDS
- Validating addresses and checking the same subnetIPv4 addressing
- How a router forwards: the routing tableRouting: static routes and OSPF
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
What is the wildcard mask for the subnet 172.16.8.0/22?
Answer: 0.0.3.255
A /22 mask is 255.255.252.0; 255 minus each octet gives 0.0.3.255.
An ACL has two lines: "deny host 10.1.1.5" and "deny host 10.1.1.6". What happens to a packet from 10.1.1.7?
Answer: It is denied by the implicit deny any
No line matches 10.1.1.7, so the hidden deny any at the end drops it.
Which number range is an extended IPv4 ACL?
Answer: 2000 to 2699
Extended ACLs use 100 to 199 and 2000 to 2699; standard ACLs use 1 to 99 and 1300 to 1999.
An interface already has ip access-group A in. You type ip access-group B in. What is the result?
Answer: B replaces A
Only one ACL per interface, per direction, per protocol. The new one replaces the old one.
Which command shows how many packets matched each ACL rule?
Answer: show access-lists
show access-lists prints each rule with its matches counter.
Which command shows the ACL of a file?Related
Where does Cisco IOS expect a wildcard mask instead of a subnet mask?Related
Answer: In access-list statements and the OSPF network command
Interfaces take subnet masks. ACLs and OSPF network statements take wildcard masks.
Which statement about network ACLs is true?Related
Answer: They are stateless and evaluated in rule-number order
NACLs are stateless subnet firewalls; the lowest numbered matching rule decides.
Is 192.168.0.255/23 a usable host address?Related
Answer: Yes, the subnet runs from 192.168.0.0 to 192.168.1.255
In a /23 the broadcast is 192.168.1.255. 192.168.0.255 is in the middle of the range, so it is a normal host.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 2 more topics in “Network security” before its exam: Layer 2 security: port security, DHCP snooping, DAI, Firewalls, IPS and VPNs.
- Module 9 exam: Network security · 13 questions · 25 min, without help. 5 topics of this module still to finish first.
- Then the next module, Wireless networking. 57 topics left in the course before the final exam.