How to Block IP Address in Ubuntu Firewall
Last time, we learned how to use the ufw Allow command to allow IP addresses through the Ubuntu Firewall. We’ll learn how to block IP addresses in Ubuntu Firewall in this UFW Tutorial.
We use the ufw deny command to block IP addresses. All network traffic can be blocked, or IP addresses on specific network ports can be blocked.
ufw deny from <Remote-IP> to <Local-IP> proto <Protocol> port <Port Number>
Examples: UFW Block IP Address
ufw deny from 192.168.1.10 to any
Block all network traffic from the IP Address 192.168.1.10.
ufw deny from 192.168.1.10 to any proto tcp port 80
The Ubuntu Firewall rule will block IP Address 192.168.1.10 on TCP port 80
ufw deny from 192.168.1.50 to any proto udp port 53
This will Block UDP port 53 from IP Address 192.168.1.50
Ubuntu Firewall evaluates rules in the order in which they are matched; if one rule matches, the others are not evaluated. Using the ufw status numbered command, you can see a list of your firewall rules organized by order number.
ufw status numbered
We learned how to use the ufw deny command to block IP addresses in the Ubuntu firewall in this tutorial.