Firewall Fundamentals
What is a Firewall?
A firewall is a network security system designed to monitor and control incoming and outgoing network traffic based on predetermined security rules. It acts as a barrier between trusted internal networks and untrusted external networks, such as the internet.
Types of Firewalls
1. Packet Filtering Firewalls
Packet filtering firewalls examine network packets and block or allow them based on predefined rules.
graph LR
A[Incoming Packet] --> B{Firewall Rules}
B --> |Allowed| C[Network]
B --> |Blocked| D[Dropped]
2. Stateful Inspection Firewalls
These firewalls track the state of network connections and make decisions based on the context of the traffic.
3. Application Layer Firewalls
These firewalls operate at the application layer, providing more detailed filtering based on specific application protocols.
Firewall Configuration Basics
Key Firewall Parameters
Parameter |
Description |
Example |
Chain |
Network traffic chain |
INPUT, OUTPUT, FORWARD |
Policy |
Default action for traffic |
ACCEPT, DROP |
Protocol |
Network protocol |
TCP, UDP, ICMP |
UFW (Uncomplicated Firewall)
UFW is a user-friendly firewall configuration tool for Ubuntu systems.
Basic UFW Commands
## Enable UFW
sudo ufw enable
## Allow specific port
sudo ufw allow 22/tcp
## Deny incoming traffic
sudo ufw default deny incoming
## Check firewall status
sudo ufw status
iptables
A more advanced firewall configuration tool with granular control.
Sample iptables Rule
## Block incoming traffic from a specific IP
sudo iptables -A INPUT -s 192.168.1.100 -j DROP
## Allow SSH connections
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
Best Practices
- Always start with a default deny policy
- Only open necessary ports
- Regularly update firewall rules
- Monitor firewall logs
Importance of Firewalls
Firewalls are crucial in protecting networks from:
- Unauthorized access
- Malware
- Denial of Service (DoS) attacks
- Data breaches
By understanding these fundamentals, users can effectively configure and manage firewalls using tools like UFW and iptables on LabEx's Linux environments.