I am working on a bash script that use de ip rule...
command to add and remove some rules. But I am having problems removing them. For example ip rule show
output looks like this:
0: from all lookup local
32764: from all fwmark 0x3022 lookup 12322
32765: from 10.10.10.1 lookup 12322
32766: from all lookup main
32767: from all lookup default
All the info I have is the table id (12322) and I need to remove all the rules that lookup that table.
I tried these commands: ip rule del table 12322
and ip rule del lookup 12322
, but both commands remove always the first rule, and not the first rule that lookup 12322, I mean the first rule from all lookup local
. If I run any of those commands 5 times I end up with no rules.
How can I remove all the rules that lookup 12322
in one command?
You can delete using "from 0/0 to 0/0" but that will remove only ONE rule. To remove them all use something like this:
while ip rule delete from 0/0 to 0/0 table 12322 2>/dev/null; do true; done
This will delete all the rules until there are no more.
Does the following work?
ip rule delete from 0/0 to 0/0 table 12322
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With