Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ip rule: deleting all rules from table

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?

like image 363
user3571891 Avatar asked Dec 05 '22 05:12

user3571891


2 Answers

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.

like image 195
mlasevich Avatar answered Dec 06 '22 19:12

mlasevich


Does the following work?

ip rule delete from 0/0 to 0/0 table 12322
like image 37
Si289 Avatar answered Dec 06 '22 17:12

Si289