A firewall controls the flow of network traffic into and out of a network. It protects networks from attacks like probing, crashing services/computers, and unauthorized access. There are different types of firewalls including edge firewalls that protect individual devices, appliance firewalls that are dedicated firewall devices, and network firewalls that protect entire networks. Firewalls work by blocking or allowing packets based on criteria like source/destination IP addresses and ports. Firewall rules must be properly configured to allow desired traffic while blocking unwanted traffic. Logs record firewall activity and potential attacks but too much or too little logging has downsides.