Firewalls
A packet filter checks each packet against an ordered list of rules on addresses, protocol and ports, the first match deciding, and a stateful firewall remembers connections started from inside so it can let their replies in while denying everything else by default.