UFW Cheat Sheet – Add new allow rules, block IP addresses

Add a Port

$ sudo ufw allow 33/tcp

Tips: When looking at rules, use ufw status numbered because it gives line numbers with output that may be used later.

Block an IP address

$ sudo ufw insert 1 deny from [ip-to-block] to any

The 1 above shows the order of the insert.

You can insert a rule without an order numeric:
sudo ufw deny from [ip-to-block]


ufw deny from a.b.c.0/24 to any

If you’ve already inserted a rule and it doesn’t work, check the order as per the sequence below:

Show all rules

$ sudo ufw status numbered

Delete Rule

First Show all rules

$ sudo ufw delete 19

See Also




Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top