How to block (filter) an ip address with UFW
So because i've searched long time till I found the proper answer about how to block an ip address with UFW i thought it might be useful for newcomers to get it right. So long story short, to block an IP with UFW (uncomplicated firewall) you have to issue this command as root:
# ufw insert 1 deny out from any to x.x.x.x
where x.x.x.x is the ip you want to block, you can use ip ranges cidr format too like x.x.x.x/10
So this will do as follow: 1) will make this rule first so any more permissive rule would be ignored, 2) any traffic originating from any local ip (from your host) toward specified ip will be filtered (in n00bs terms blocked so use filtered instead;) 3) To test if your desired ip was filtered try to ping it "ping x.x.x.x" if you make it right ping will fail
It's enough to block only outgoing traffic as UFW blocks by default incoming traffic that was not requested by your machine. This would work for desktop pc but if you wanna run a server you have to filter incoming traffic too like like this
# ufw insert 1 deny from x.x.x.x to any
Hope i'm not missing anything on this topic anyone feel free to improve this. Cheers!