Skip to content

Expert · Network security · topic 43 of 57 · 35 min

Access control lists (ACLs)

Explanation

An access control list (ACL) is an ordered list of permit and deny rules that a router checks against each packet. Standard ACLs match only the source address; extended ACLs match protocol, source, destination and ports. The first matching rule wins, and an invisible "deny any" sits at the end. You apply an ACL to an interface in one direction with ip access-group.

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".

Think of it like this: An ACL is like the guest list at a wedding hall gate. The guard reads the list from the top. The first line that fits you decides: "family: allow", "anyone with a camera crew pass: allow". If your name matches nothing, you are not let in. The guard never reads past the first match.

Standard and extended ACLs

StandardExtended
Numbers1 to 99 and 1300 to 1999100 to 199 and 2000 to 2699
MatchesSource IP address onlyProtocol, source IP, destination IP, and TCP or UDP ports
Where to placeClose to the destinationClose 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

  1. Rules are checked top-down, in order of sequence number.
  2. The first rule that matches decides: permit or deny. The rest are not checked.
  3. If no rule matches, the packet hits the implicit "deny any" at the end, which you never see in the configuration.
Careful: Because of the implicit deny, an ACL with only deny lines blocks everything. Always end a list that is mainly "deny" with a permit line (for example permit ip any any), or every other user loses access too.

Writing and applying ACLs

output
! 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 out
Cisco IOS: a standard ACL applied outbound on the interface that leads to the servers (close to the destination).

ip 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.

output
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 in
Cisco IOS: guests are blocked from the finance server and the internal 10.x network, but can use DNS and web browsing. Everything else hits the implicit deny.

Why 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.

output
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)
Cisco IOS: hit counters show the finance block is working (12 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

Access control lists

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)

Task 1 · Code · Python

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".

Task 2 · Code · Python

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.

Task 3 · Question

You must stop VLAN 20 users from reaching one web server, but allow everything else. Which ACL type and placement is best?

Quick quiz

Question 1

1.What is the wildcard mask for the subnet 172.16.8.0/22?

Question 2

2.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?

Question 3

3.Which number range is an extended IPv4 ACL?

Question 4

4.An interface already has ip access-group A in. You type ip access-group B in. What is the result?

Question 5

5.Which command shows how many packets matched each ACL rule?

Read more (free)

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

Answer: getfacl

getfacl prints all ACL entries.

From Access control lists (ACLs)

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.

From Subnet masks, prefix length and 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.

From VPC security and connectivity

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.

From Network, broadcast and usable host range

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

  1. 2 more topics in “Network security” before its exam: Layer 2 security: port security, DHCP snooping, DAI, Firewalls, IPS and VPNs.
  2. Module 9 exam: Network security · 13 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Wireless networking. 57 topics left in the course before the final exam.

← Previous: Securing device access: secrets and SSH