Firewalls
Access control list
An ordered list of permit and deny lines a router checks each packet against, applied to a card in or out.
An access control list (ACL) is an ordered list of permit and deny lines a router checks packets against. The first match decides; a packet matching none meets the implicit deny at the end. A standard ACL matches only the source address; an extended one also matches destination, protocol and port. It acts only once applied to a card, in or out, and is stateless: replies need their own line.
How an access control list works, step by step
An ACL is an ordered list of permit and deny lines, applied to a router interface in one direction. For every packet that crosses that interface in that direction, the router does this:
- Start at the top. Compare the packet with the first line: source address, and for an extended list the destination, the protocol and the ports.
- First match wins. The first line that matches decides, permit or deny, and the router stops reading. Lines further down never see that packet, even if they would match it better.
- No match, denied. Every list ends with an invisible implicit deny: a packet that matches no line is dropped. A list with only deny lines blocks everything.
- Count. Each line counts its matches, which is how you prove what a list did.
Two kinds of list, two places to put them:
| Standard | Extended | |
|---|---|---|
| Matches | source address only | source, destination, protocol, ports, TCP flags |
| IOS numbers | 1–99, 1300–1999 | 100–199, 2000–2699, or a name |
| Place it | near the destination, so it blocks only that | near the source, to drop traffic early |
Direction matters too. In checks a packet as it arrives on the interface, before the routing decision; out checks it after routing, as it leaves. An interface takes one list per direction per protocol.
IOS writes address ranges with a wildcard mask, the subnet mask inverted: a 0 bit must match, a 1 bit is free.
10.0.1.16 0.0.0.15 matches .16 to .31, the same block as 10.0.1.16/28.
A plain ACL is stateless. It judges each packet on its own, so a list that denies the servers from reaching the
office also drops the replies to connections the office opened. Replies need their own line (established matches
TCP segments with ACK or RST set) or a stateful firewall.
What it looks like on a Linux machine
Linux has no access-list command, but an iptables chain is the same machine: rules in order, first match
wins, RETURN or ACCEPT for permit and DROP for deny. In the router ACLs lab the policy
"only the layout desk may reach the press, and only on port 8080" is an extended list, in IOS:
ip access-list extended NEWS-IN
permit tcp host 10.42.0.10 host 10.42.1.10 eq 8080
deny ip any 10.42.1.0 0.0.0.255
permit ip any any
interface newsroom
ip access-group NEWS-IN in
and on the Linux router, as iptables -S prints it:
-N NEWS-IN
-A FORWARD -i newsroom -j NEWS-IN
-A NEWS-IN -s 10.42.0.10/32 -d 10.42.1.10/32 -p tcp -m tcp --dport 8080 -j RETURN
-A NEWS-IN -d 10.42.1.0/24 -j DROP
An iptables chain that runs out of rules returns to its caller, so the Linux list needs no permit ip any any, and
the implicit deny must be written out when you want one. A permit says RETURN, not ACCEPT, so the packet still
meets the list hung on the card it leaves by. The counters are IOS's show access-lists: on the list guarding the
press hall, the deny line has counted a guest's tries.
$ iptables -L PRESS-OUT -v -n --line-numbers
Chain PRESS-OUT (1 references)
num pkts bytes target prot opt in out source destination
1 6 400 RETURN 0 -- * * 10.42.0.0/24 0.0.0.0/0
2 3 180 DROP 0 -- * * 0.0.0.0/0 0.0.0.0/0
What goes wrong, and how you see it
A line in the wrong order. A broad deny above a specific permit wins every time. Read the list top-down and check which line's counter rises.
A standard list near the source. It can only name who sends, so it blocks that host from everything, not just the one network you meant. The lab shows it on the guests' card, where a list naming only the sender cuts the guests off the internet too.
The forgotten implicit deny. A new list with one permit line for a single service cuts off everything else on that interface, routing protocol traffic included.
Replies dropped. A stateless deny for traffic from the servers also catches the servers' answers. The client sees timeouts on connections that should work.
Wrong direction or interface. A list applied in where out was meant, or on the wrong interface, matches
nothing. Its counters stay at zero.
Questions people ask
What is the difference between an ACL and a firewall? A basic ACL is stateless and checks each packet alone. A
stateful firewall tracks connections, so replies pass without rules of their own. Linux iptables does both: plain
rules act like an ACL, and -m conntrack --ctstate ESTABLISHED,RELATED adds state.
Where should an extended ACL go? As close to the source as possible, so unwanted traffic is dropped before it crosses the network.
Can I edit a line in the middle of an ACL? In a named IOS list, yes: lines have sequence numbers (10, 20, 30), so
15 deny … goes between two. In iptables, -I CHAIN 2 inserts at a position.
Read next
- Wildcard mask A mask turned inside out, as Cisco ACLs and OSPF use it: 0 bits must match, 1 bits are free.
- Firewall Rules deciding, packet by packet, what may reach or cross a device.
- Stateful firewall A firewall that remembers connections, so it can allow replies while refusing new connections in.
- Security groups and network ACLs The cloud's two firewalls: stateful allow rules on each instance, and stateless numbered rules on each subnet.