# Firewall Security
## Firewalls in Network Security
A firewall is a security system that monitors and controls incoming and outgoing network traffic based on predetermined security rules. It creates a barrier between trusted internal networks and untrusted external networks such as the internet. Firewalls are one of the most fundamental components of network security. They work by examining each packet and deciding whether to allow it to pass or to block it based on the configured rules. Firewalls can be hardware appliances, software applications running on general-purpose computers, or both.
## Packet Filtering
Packet filtering firewalls, also called stateless firewalls, examine individual packets in isolation based on criteria such as source IP address, destination IP address, source port, destination port, and protocol. Each packet is checked against a list of rules and either allowed or denied. Packet filtering is fast and efficient but limited because it cannot track the state of connections. For example, a packet filtering firewall might allow inbound TCP packets to port 80 for web traffic, but it cannot distinguish between legitimate responses to outbound connections and unsolicited inbound connections on port 80.
## Stateful Inspection
Stateful inspection firewalls track the state of network connections. They maintain a state table that records established connections. When an outbound connection is established, the state table records it. When an inbound packet arrives that belongs to an established outbound connection, it is automatically allowed. Unsolicited inbound packets that do not match any established connection are blocked. This allows firewall rules to be simpler because the administrator does not need to explicitly allow all return traffic.
## Application Layer Firewalls
Application layer firewalls, also called proxy firewalls or next-generation firewalls, can examine the actual content of network traffic at the application layer. They understand specific application protocols and can make decisions based on the content of web requests, detect and block specific types of attacks, and identify applications based on their behavior rather than just their port numbers. Application layer inspection allows blocking specific file types, detecting malware in downloads, and enforcing web content policies.
## Firewall Rule Design
Effective firewall rule design follows the principle of least privilege. By default, all traffic should be blocked. Rules should explicitly allow only the traffic that is necessary for business operations. Rules should be as specific as possible. The order of rules matters because rules are evaluated in sequence and the first matching rule determines the action. Firewall rules should be regularly reviewed and rules that are no longer needed should be removed.Back to Subject