What is the primary purpose of a firewall?

What is the primary purpose of a firewall?

Scans all your systems for existence of virus
Records your activities on the computer
Stops you from installing software that will harm your computer
Prevents unauthorized access to your computer via internet
This question was previously asked in
UPSC CBI DSP LDCE – 2023
The correct answer is D) Prevents unauthorized access to your computer via internet.
The primary purpose of a firewall is to act as a security barrier that monitors and controls incoming and outgoing network traffic. It enforces security rules to block unauthorized connections and prevent malicious traffic from entering or leaving a network or individual computer, particularly via external networks like the internet.
Antivirus software scans for viruses. Recording activities is related to auditing or logging tools. Stopping software installation is usually managed by OS permissions or specific endpoint security software, not the primary function of a firewall.