I have a PBX (phone system called Astersik) that works with udp and tcp. Sometimes I get invalid request from some IP addresses that I will like to block. I cannot block those requests until I reboot my computer. I think the reason is because UFW will not block established connections.
Let's pretend I am getting malicious request from the ip address 1.2.3.4. I then need to block those request by executing the command:
sudo ufw insert 1 deny from 1.2.3.4 to any
I need the insert 1 so that the rule is executed before the other ones.
Anyways even though I execute that command I still see that my computer replies back to 1.2.3.4. The problem is because there is already an establish connection therefore ufw will not drop those packets until those connections are closed.
I found a temporary solution:
1) I open nano /etc/ufw/before.rules
2) Comment the lines:
(In the picture the lines are not commented. But comment everything that is inside the red circle)
3) Restart firewall ufw disable then ufw enable
If I comment those lines then my firewall will work like I want. It will block connections right away!
The problem is that commenting those lines causes my dns to stop working In other words now when I execute ping google.com I see uknown host google.com
Why dns stops working when I comment those lines? In short I need that when I execute sudo ufw insert 1 deny from 1.2.3.4 to any I get no more requests from that IP!. I cannot afford to reboot the computer every time I want to block an ip address.
