CSCO-121 · Lesson 7 of 12 · 23 min

Firewalls and access control lists

▶ Video coming soon A video version of this lesson is on the way.

With the bakery's zones drawn on paper, the next job was to decide what traffic each zone could send to the others. Dev Anand set Jordan an exercise before letting him near the real firewall: write the rules in plain sentences first, one rule per line, starting with "allow" or "deny". Jordan's first draft had 31 lines. Dev crossed out a third of them, merged others, and added one line at the bottom that Jordan had forgotten: deny everything else. "That last line is the most important rule you will ever write," Dev said. "Everything above it is an exception."

A firewall is a device or program that controls network traffic according to rules. An access control list, or ACL, is an ordered list of those rules. This lesson explains the kinds of firewall, how rules are evaluated, how Cisco devices express ACLs, where to place filters, and how to keep a rule set clean. The exam expects you to read a short rule list and work out what it will do to a given packet.

Kinds of firewall

A packet-filtering firewall examines each packet on its own and decides based on information in its headers: source and destination IP addresses, the protocol such as TCP, UDP or ICMP, and source and destination port numbers. It is fast and simple, but it has no memory. It cannot tell whether an incoming packet is a reply to something a user inside asked for, so rules must be written to allow replies explicitly, which tends to open more than intended. Router ACLs are the most common example of stateless packet filtering.

A stateful firewall keeps a table of active connections. When a user inside opens a connection to a website, the firewall records it, and it allows the website's replies back in because they belong to a known connection. Unsolicited packets from outside that match no connection are dropped. This makes rules simpler and safer: you write rules for who may start a connection, and replies are handled automatically. Almost every modern firewall, including the ones in small office appliances, is stateful.

Two panels. In the left panel, labelled stateless, a laptop sends a request to a web server and the reply returns through a filter that checks only addresses and ports; an unsolicited packet from an attacker using the same port also passes. In the right panel, labelled stateful, the firewall holds a small connection table with one entry; the real reply matches and passes, while the unsolicited packet matches no entry and is dropped.
A stateless filter judges each packet alone. A stateful firewall remembers connections and drops packets that do not belong to one.

An application-layer firewall, or proxy firewall, understands specific protocols such as HTTP and can inspect the content of requests, not just their headers. A next-generation firewall combines stateful filtering with application identification, so that a rule can say "allow the accounting application, block file-sharing applications" regardless of the port they use, and adds user identity, intrusion prevention and often web filtering. A web application firewall sits in front of a web application and inspects requests for attacks such as injection. A host-based firewall runs on an individual computer, such as the firewalls built into Windows, macOS and Linux, and protects that one device wherever it is.

Common firewall types.
TypeDecides usingStrengthLimitation
Packet filter (stateless)Addresses, protocol, ports of each packetFast, simpleNo memory of connections; replies need explicit rules
Stateful firewallHeader fields plus a connection tableReplies handled safely; simpler rulesLimited view of application content
Application-layer or proxyProtocol content, such as HTTP requestsDeep inspectionSlower; protocol-specific
Next-generation firewallApplications, users, threats and stateRich policy, built-in IPSCost and complexity
Web application firewallWeb requests to one applicationBlocks common web attacksProtects only web traffic
Host-based firewallTraffic to and from one deviceProtects the device anywhereMust be managed on every device

How rules are evaluated

Rule lists are processed from the top down, and the first rule that matches a packet decides what happens to it. Later rules are never checked for that packet. This simple principle has two consequences. First, order matters: a broad "allow" near the top can make a careful "deny" further down useless, because packets never reach it. Specific rules usually go above general ones. Second, every list needs a decision for packets that match nothing. On Cisco devices and most firewalls, that decision is an implicit deny at the end of the list: anything not explicitly allowed is dropped.

The principle of default deny, sometimes called deny by default or an allow list approach, says that traffic should be blocked unless there is a known reason to allow it. The opposite approach, allow everything and block known bad things, is easier at first and fails badly, because attackers simply use something that has not been blocked yet. Dev's crossed-out draft reflected this: many of Jordan's lines were denies for things that the final deny-everything rule already covered.

A flowchart. A packet enters at the top. It is compared with rule 1; if it matches, the action of rule 1 is applied and processing stops. If not, it moves to rule 2, then rule 3. After the last numbered rule is a box labelled implicit deny, which drops the packet. A side note reads first match wins.
Top-down, first-match processing of an access control list, ending with the implicit deny.
rules = [  # (action, source zone, destination zone, port)
    ("allow", "pos",   "processor", 443),
    ("allow", "staff", "internet",  443),
    ("allow", "staff", "internet",  80),
    ("deny",  "guest", "staff",     None),
    ("allow", "guest", "internet",  443),
]
def decide(src, dst, port):
    for n, (act, s, d, p) in enumerate(rules, 1):
        if s == src and d == dst and p in (None, port):
            return f"{act} (rule {n})"
    return "deny (implicit)"
for pkt in [("pos", "processor", 443), ("guest", "staff", 445),
            ("guest", "internet", 443), ("pos", "internet", 443)]:
    print(pkt, "->", decide(*pkt))
Output
('pos', 'processor', 443) -> allow (rule 1)
('guest', 'staff', 445) -> deny (rule 4)
('guest', 'internet', 443) -> allow (rule 5)
('pos', 'internet', 443) -> deny (implicit)

The program simulates first-match processing for a few of the bakery's planned rules. The last packet, a point-of-sale terminal trying to reach an arbitrary website, matches no rule and is dropped by the implicit deny. That is exactly the behaviour the bakery wants: card terminals should talk to the payment processor and nothing else.

Cisco access control lists

Cisco routers and switches use ACLs to filter traffic on interfaces. A standard ACL matches only the source IP address. An extended ACL can match source and destination addresses, protocol, and source and destination ports. ACLs can be identified by number or, more readably, by name. Each ACL is applied to an interface in one direction: inbound, for packets arriving on that interface, or outbound, for packets leaving it. Only one ACL per interface, per direction and per protocol is allowed.

Cisco ACLs describe address ranges with a wildcard mask rather than a subnet mask. A wildcard mask is the inverse of a subnet mask: a 0 bit means the address bit must match, and a 1 bit means it does not matter. To match the subnet 10.20.20.0 with subnet mask 255.255.255.0, the wildcard is 0.0.0.255. A quick way to find it is to subtract each octet of the subnet mask from 255. The keyword host matches a single address, the same as a wildcard of 0.0.0.0, and any matches every address.

An extended named ACL for the bakery's point-of-sale VLAN, shown for reading. It is applied inbound on the POS subinterface, so packets from the terminals are checked as they arrive.
ip access-list extended POS-OUT
 remark Card terminals may reach only the payment processor over HTTPS
 permit tcp 10.20.20.0 0.0.0.255 host 203.0.113.10 eq 443
 deny   ip  10.20.20.0 0.0.0.255 any log
!
interface GigabitEthernet0/1.20
 ip access-group POS-OUT in

Reading the example: the first line allows TCP from any address in 10.20.20.0/24 to the single host 203.0.113.10, the payment processor, on port 443. The second line denies everything else from that subnet and logs it. Even without the explicit deny, the implicit deny would drop the traffic, but writing it with the log keyword makes blocked attempts visible, which helps troubleshooting and detection. The remark line documents the purpose, which Marisol would approve of.

Host-based firewalls

The firewalls built into Windows, macOS and Linux are often overlooked. On a laptop that travels, they are the only firewall that is always present. Brightline's standard laptop build turns the host firewall on for every network profile, blocks inbound connections by default, and allows only the management agent's traffic from Brightline's tools. A common support mistake is to turn the host firewall off to fix an application problem and forget to turn it back on. The better fix is a specific rule for the application, with a ticket explaining why.

Worked problem

Finding a wildcard mask

Dev wants an ACL entry that matches the bakery's guest network, 10.20.30.0 with subnet mask 255.255.255.192. What wildcard mask should he use?

Show solution
  1. Subtract each octet of the subnet mask from 255.
  2. 255 − 255 = 0, 255 − 255 = 0, 255 − 255 = 0, and 255 − 192 = 63.
  3. The wildcard mask is 0.0.0.63, matching addresses 10.20.30.0 to 10.20.30.63.

Answer: Use 10.20.30.0 0.0.0.63 in the ACL entry.

Where to place filters

Cisco's traditional guidance is to place extended ACLs as close as possible to the source of the traffic being filtered, so that unwanted packets are dropped before they cross the network, and to place standard ACLs as close as possible to the destination, because a standard ACL matches only the source address and placing it near the source could block that source from reaching everything. On a zone-based firewall, the question becomes which zone pair the rule belongs to, and the rule is written for traffic from one zone to another.

Placement also includes the internet edge. Inbound rules at the edge should deny traffic that claims to come from addresses that should never appear on the internet, such as the organization's own internal ranges and private address ranges, which blocks a class of spoofing. Outbound rules matter too. Egress filtering, limiting what internal devices may send out, makes it harder for malware to contact its controllers or send stolen data, and stops the bakery's thermostat from being used to attack someone else.

Keeping rule sets healthy

Firewall rule sets tend to grow. Each new request adds a rule, and nobody wants to remove an old one in case something breaks. Over time the list fills with rules that are too broad, rules for servers that no longer exist, and rules that duplicate or shadow each other. A shadowed rule is one that can never match because an earlier rule already catches every packet it would match. Overly broad rules, such as allowing any source to reach any destination on any port, are the most dangerous, because they undo segmentation entirely.

Good practice includes a change process with a ticket for every rule, a stated business reason and an owner; a remark or description on each rule; least privilege, allowing only the specific source, destination and port needed; a regular review, often every six or twelve months, to remove rules that are no longer needed; logging of denied traffic and of important allowed traffic; and backups of the configuration. Brightline's plan for the bakery includes a rule review in March 2027, three months after the new zones go live, to remove temporary rules added during the cutover.

Worked problem

Spotting a shadowed rule

A rule list reads: 1. allow staff to any destination, any port. 2. deny staff to the POS zone, any port. 3. allow staff to the internet on port 443. Which rule is a problem, and what should the order be?

Show solution
  1. Rule 1 matches all staff traffic, including traffic to the POS zone.
  2. Because the first match wins, rule 2 can never take effect: it is shadowed by rule 1. Rule 3 is also never reached.
  3. Rule 1 is also too broad: it violates least privilege.
  4. Better: 1. deny staff to the POS zone; 2. allow staff to the internet on ports 443 and 80; then let the implicit deny handle the rest.

Answer: Rule 1 shadows rules 2 and 3 and should be removed or narrowed; specific rules go first, with default deny at the end.

Common mistakes

  • MistakePutting broad allow rules at the top.

    InsteadFirst match wins; specific rules go above general ones.

  • MistakeForgetting the implicit deny.

    InsteadTraffic that matches no rule is dropped; write allows for everything that is needed.

  • MistakeUsing a subnet mask in a Cisco ACL.

    InsteadCisco ACLs use wildcard masks, the inverse of subnet masks.

  • MistakeFiltering only inbound traffic.

    InsteadEgress filtering limits malware and data theft.

  • MistakeNever removing old rules.

    InsteadReview rule sets regularly and remove rules without a current owner and reason.

Summary and key terms

  • Firewalls control traffic by rules; types include stateless packet filters, stateful firewalls, application-layer firewalls, next-generation firewalls, web application firewalls and host-based firewalls.
  • Stateful firewalls track connections and allow replies automatically.
  • Rules are evaluated top down; the first match wins; an implicit deny ends the list.
  • Cisco standard ACLs match source addresses; extended ACLs match addresses, protocols and ports; wildcard masks invert subnet masks.
  • Place extended ACLs near the source and standard ACLs near the destination; filter both inbound and outbound at the edge.
  • Healthy rule sets follow least privilege, have documented owners and reasons, and are reviewed regularly.
ACL
Access control list, an ordered list of permit and deny rules.
Stateful firewall
A firewall that tracks connections and allows matching replies.
Implicit deny
The rule at the end of an ACL that drops anything not explicitly allowed.
Default deny
The principle of blocking traffic unless it is specifically allowed.
Wildcard mask
A Cisco mask in which 0 bits must match and 1 bits are ignored.
Extended ACL
A Cisco ACL that matches source, destination, protocol and ports.
Egress filtering
Controlling traffic leaving a network.
Shadowed rule
A rule that can never match because an earlier rule catches its traffic.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Why can a stateful firewall use simpler rules than a stateless filter?

    Show answer

    It allows replies to known connections automatically.

  2. What happens to a packet that matches no rule in a Cisco ACL?

    Show answer

    It is dropped by the implicit deny.

  3. What is the wildcard mask for subnet mask 255.255.255.240?

    Show answer

    0.0.0.15.

  4. Where should an extended ACL usually be placed?

    Show answer

    As close as possible to the source of the traffic.

  5. What is egress filtering?

    Show answer

    Limiting what traffic may leave the network.

  6. What is a shadowed rule?

    Show answer

    A rule that can never match because an earlier rule already catches its traffic.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz