Block an IP address or subnet with ufw
ufw block ip address | ufw deny from subnet | ufw insert deny rule first | ufw | firewall | banCaution: This command changes the system. Understand what it does before you run it.
ufw insert 1 deny from 203.0.113.0/24Inserts a deny rule at position 1 so it is checked before all allow rules. ufw evaluates rules from top to bottom, so a plain ufw deny at the end would be overridden by an existing port rule. The rule survives reboots and is removed with ufw delete deny from <quelle>.
Note: insert 1 fails if no rule exists yet, in that case simply use ufw deny from <quelle>. IPv6 addresses are sorted in separately before the first IPv6 rules.
Also searched as
- ufw block ip address
- ufw deny from subnet
- ufw insert deny rule first