Lab 4: Firewall Configuration
Objective:
- To understand and practice firewall configuration on a Linux system.
Topics Covered:
- Introduction to iptables
- Basic iptables Commands
- Configuring Firewall Rules
- Persistent iptables Rules
- Monitoring and Troubleshooting
Lab Exercises:
Exercise 1: Introduction to iptables
Exercise 2: Basic iptables Commands
# View current iptables rules
sudo iptables -L
# Flush existing rules (start with a clean slate)
sudo iptables -F
# Set default policies
sudo iptables -P INPUT DROP
sudo iptables -P FORWARD DROP
sudo iptables -P OUTPUT ACCEPT
Exercise 3: Configuring Firewall Rules
# Allow incoming SSH connections
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Allow incoming connections on a custom service/port (e.g., web server)
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
# Deny incoming connections on a specific port
sudo iptables -A INPUT -p tcp --dport 1234 -j DROP
Exercise 4: Persistent iptables Rules
# Install iptables-persistent for Ubuntu/Debian
sudo apt-get install iptables-persistent
# Save current rules to be persistent across reboots
sudo iptables-save > /etc/iptables/rules.v4
Exercise 5: Monitoring and Troubleshooting
# View real-time packet counters
sudo watch iptables -L -n -v
# Troubleshoot issues by logging denied packets
sudo iptables -A INPUT -j LOG --log-prefix "iptables-dropped: " --log-level 7
Lab Documentation:
Provide detailed instructions for each exercise, including command syntax and expected outcomes. Include explanations of the purpose behind each task.