0

I'm setting marks with iptables like this

iptables -t mangle -A POSTROUTING -d 192.168.1.143 -j MARK --set-mark 10

if I want to clear what I do is remove all with

iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

instead of removing all the rules to clear this, how to remove a mark only?

2 Answers 2

6

You could just delete that one rule.

iptables -L -t mangle --line-numbers

will give you a number for each rule in your mangle table, then use

iptables -t mangle -D POSTROUTING x

where x is the rule number where you defined the mark.

5

You can also use this syntax:

iptables -t mangle -D POSTROUTING -d 192.168.1.143 -j MARK --set-mark 10

(Note the -A changed to -D, everything else the same)

This format it useful if it is in your recent history which makes it easy to scroll back and change the A to a D. (ie, when you're testing a rule)

3
  • I have this code iptables -t mangle -A wlan0_Outgoing -m mac --mac-source ${mac} -j MARK --set-mark 2. Does change -A to a -D would remove this rule? Aug 9, 2018 at 10:19
  • @Reigel Yes....
    – fukawi2
    Aug 9, 2018 at 23:03
  • Note that this does not match the mark ID you provided with --set-mark when deleting the rule with -D. Any mark ID will delete the rule if everything else matches. Tested with Linux kernel 5.8.
    – famzah
    Mar 5, 2021 at 10:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .