Ravindra BagaleCourses & study guides

32. Linux and Network Hardening

32.3 Host Firewall: firewalld and ufw

A security group filters traffic outside the instance; a host firewall filters it inside the OS – a second layer.

firewalld (Amazon Linux, RHEL, CentOS):

sudo yum install -y firewalld
sudo systemctl enable firewalld
sudo service firewalld start
sudo firewall-cmd --get-default-zone
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --permanent --remove-service=cockpit     # remove what you do not need
# Allow MySQL only from the web server IP
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.1.25" port port="3306" protocol="tcp" accept'
sudo firewall-cmd --reload
sudo firewall-cmd --list-all

ufw (Ubuntu, Kali):

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 80,443/tcp
sudo ufw enable
sudo ufw status verbose

Ravindra Bagale's Tip

--permanent lavla pan --reload visarla – rule lagu ch hot nahi, ani students gondhaltat. Ulta, --permanent nasel tar reboot nantar rule jato. Donhi lakshat theva: permanent + reload. Aani SSH allow kelyashivay firewall chalu karu naka!

Lab

Enable firewalld on your lab web server allowing only SSH, HTTP and HTTPS. From Kali run nmap -p- 192.168.56.20 (Chapter 19) before and after, and compare the open ports.