A firewall acts as a barrier between a trusted internal network and untrusted external networks, monitoring and filtering incoming and outgoing traffic to block unauthorized connections. While it helps secure a system, blocking specific viruses within files is typically the job of antivirus software rather than a network firewall.