A firewall is hardware or software that filters network traffic by allowing or denying transmission based on a set of rules to protect networks from unauthorized access. There are two main types - network layer firewalls which filter at the IP address and port level, and application layer firewalls which can filter traffic from specific applications like FTP or HTTP. A DMZ (demilitarized zone) is a physical or logical sub-network exposed to an untrusted network like the internet that contains external-facing services, protected from internal networks by firewalls. Firewalls provide security benefits like restricting access to authorized users and preventing intrusions from untrusted networks.