Step 1:
Backup existing firewall rules
sudo cp /etc/ufw/before.rules /etc/ufw/before.rules_backup
Step 2 :
Actual task is to replace Accept with Drop in firewall rules as below
![](https://haneefputtur.com/wp-content/uploads/2020/11/task.jpg)
Step 3:
Run below sed command to find and replace
sudo sed -i '/ufw-before-input.*icmp/s/ACCEPT/DROP/g' /etc/ufw/before.rules
![](https://haneefputtur.com/wp-content/uploads/2020/11/task_2.jpg)
If firewall already enabled then use reload command . If not enabled then use enable command as follows
sudo ufw enable or sudo ufw reload