Firewall Fundamentals: Network Security and Configuration
Learn firewall types, architectures, rule configuration, and best practices for network security and traffic filtering.
Configuring Firewalls for Network Defense
Firewalls are your first line of network defense, but a misconfigured firewall is worse than none at all. Whether you are setting up iptables rules on a Linux server or designing a segmented network architecture, understanding firewall types and rule logic is essential. This guide covers firewall fundamentals from a configuration and operations standpoint.
Types of Firewalls
Packet Filtering Firewalls
The most basic type, examining packets individually and filtering based on source/destination IP, port, and protocol. They operate at the network layer (Layer 3) and are fast but cannot inspect packet contents.
Stateful Inspection Firewalls
Maintain a state table tracking active connections. They understand the context of traffic, allowing return traffic for legitimate outbound connections while blocking unsolicited inbound traffic. This provides better security than simple packet filtering.
Proxy Firewalls (Application Gateway)
Act as intermediaries between clients and servers. They terminate connections and create new ones, inspecting application-layer traffic. They provide deep inspection but can introduce latency.
Next-Generation Firewalls (NGFW)
Combine traditional firewall capabilities with intrusion prevention, application awareness, SSL/TLS inspection, and threat intelligence integration. NGFWs can identify and control applications regardless of port or protocol.
Web Application Firewalls (WAF)
Specifically protect web applications by filtering HTTP/HTTPS traffic. WAFs detect and block common web attacks including SQL injection, XSS, and CSRF.
How Firewalls Work
Firewalls use Access Control Lists (ACLs) to define rules specifying allowed or denied traffic. Rules are evaluated in order, with the first matching rule determining the action. Each rule typically includes source IP, destination IP, protocol, source port, destination port, and action (allow/deny).
iptables/nftables Basics
Linux firewalls use iptables (legacy) or nftables (modern replacement):
# Allow SSH (port 22)
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Allow HTTP and HTTPS
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# Drop all other inbound traffic
iptables -A INPUT -j DROP
# Save rules
iptables-save > /etc/iptables/rules.v4
nftables uses a more modern syntax:
nft add rule inet filter input tcp dport 22 accept
nft add rule inet filter input tcp dport {80, 443} accept
nft add rule inet filter input drop
Firewall Architectures
Screened Subnet (DMZ)
Creates a demilitarized zone between internal and external networks. Public-facing servers are placed in the DMZ, so if compromised, the internal network remains protected.
Multi-tier Firewall
Uses multiple firewalls to create security zones: internet → external firewall → DMZ → internal firewall → internal network.
Best Practices
Default Deny: Block all traffic by default, then allow only what is necessary. This is the most secure approach.
Least Privilege: Allow only the minimum required traffic for each system or service.
Rule Order: Place more specific rules before general ones. Rules are evaluated top to bottom.
Regular Audits: Review firewall rules regularly, removing unused or overly permissive rules. Document the purpose of each rule.
Change Management: Use formal change control processes for firewall modifications, including review and approval.
Logging and Monitoring: Enable logging for denied traffic and monitor for suspicious patterns. Correlate firewall logs with other security tools.
Firewalls are essential components of network security, but they are not sufficient alone. Combine them with intrusion detection systems, endpoint protection, and security awareness training for comprehensive defense.
References
{@ref rfc2827}
{@ref nist-csf}