1

I have a number of rules in table mytable chain mychain:

> sudo nft -a list table mytable
table ip mytable { # handle 8
        chain mychain { # handle 1
                type filter hook input priority filter; policy accept;
                tcp dport 5550 accept # handle 18
                tcp dport 5551 accept # handle 19
                tcp dport 5552 accept # handle 20
                tcp dport 5553 accept # handle 21
                tcp dport 5554 accept # handle 22
        }
}

According to nftables wiki it should be possible to remove all rules from the specified chain. However the following command returns error:

> sudo nft delete rule mytable mychain
Error: syntax error, unexpected newline, expecting handle
delete rule mytable mychain
                           ^

What is the proper command to remove all rules from mychain without iterating over rule handles?

2

There are still some errors lurking in the nftables wiki. The actual syntax is quite logical:

  • to remove everything

    nft flush ruleset
    
  • to empty a table (with ip as family by default if not specified). Eg for my table

    nft flush table mytable
    
  • to delete a table (which also empties it first). Eg for mytable

    nft delete table mytable
    
  • to empty a chain (ditto). Eg for mytable mychain

    nft flush chain mytable mychain
    
  • to delete a chain (ditto). Eg for mytable mychain

    nft delete chain mytable mychain
    
  • to delete a rule (this can still be done only by the handle reference). Eg for tcp dport 5550 accept # handle 18

    nft delete rule mytable mychain handle 18
    

The thing to remember is what the action is done unto. If you want to do an operation at the chain level, then it's normal there's the chain keyword.

In case of doubt, the nft manpage is usually more accurate, but of course one has to know in advance the information is in the CHAINS section rather than the RULES section:

CHAINS

{add | create} chain [family] table chain [ { type type hook hook [device device] priority priority ; [policy policy ;] } ]
{delete | list | flush} chain [family] table chain
delete chain [family] table handle handle
rename chain [family] table chain newname

[...]
flush Flush all rules of the specified chain.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.