Jump to content

UFW:Reordering UFW Firewall: Difference between revisions

From Wiki
Created page with "If you're interested in reordering your UFW rules, this is one way to do it. <syntaxhighlight lang="bash"> sudo ufw status numbered </syntaxhighlight> To Action From -- ------ ---- [ 1] 22 ALLOW IN Anywhere [ 2] 80 ALLOW IN Anywhere [ 3] 443 ALLOW IN Anywhere [ 4] 22 (v6) ALLOW IN Anywhere (v6)..."
 
No edit summary
 
Line 33: Line 33:
==Source==
==Source==
*[https://serverfault.com/questions/484475/ufw-firewall-rules-ordering serverfault.com]
*[https://serverfault.com/questions/484475/ufw-firewall-rules-ordering serverfault.com]
[[Category:Server]]
[[Category:Linux]]
[[Category:Tutorial]]
[[Category:Security]]
[[Category:Firewall]]

Latest revision as of 22:15, 23 November 2022

If you're interested in reordering your UFW rules, this is one way to do it.

sudo ufw status numbered
     To                         Action      From
     --                         ------      ----
[ 1] 22                         ALLOW IN    Anywhere
[ 2] 80                         ALLOW IN    Anywhere
[ 3] 443                        ALLOW IN    Anywhere
[ 4] 22 (v6)                    ALLOW IN    Anywhere (v6)
[ 5] 80 (v6)                    ALLOW IN    Anywhere (v6)
[ 6] 443 (v6)                   ALLOW IN    Anywhere (v6)
[ 7] Anywhere                   DENY IN     [ip-to-block]

Say you accidentally added a rule to the end, but you wanted up top.

First you will have remove it from the bottom (7) and add it back.

sudo ufw delete 7

Note, be careful of removing multiple rules one after another, their position can change!

Add back your rule to the very top (1):

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

Source