Note

All commands must be run with sudo.

# adding a rule
ufw {allow | deny | limit} [port]/[proto]
ufw {allow | deny | limit} [from ip/host] [to ip/host] [port portnum]
 
# showing rules
ufw status [numbered]
 
# deleting rules
ufw delete [full rule]
ufw delete [rulenum]

Examples:

# allowing http/https traffic
ufw allow 80/tcp
ufw allow 443/tcp
 
# allowing wireguard
ufw allow 51820/udp
 
# limiting ssh traffic
ufw limit 22/tcp
 
# limiting ssh traffic from specific ip only
ufw limit from 172.16.99.11 proto tcp to any port 22