I know how to delete a route from a routing table providing all of the route's details (ip r d ...).

Is there any way to list routing table with some kind of indexes and then delete from its positions by the index?

  • are you looking for a guided delete operation ? Like it gives you some numbered lines with one route on each and you select the line number to delete ? If so, it is not available by widely used system tools. But writing a small script should not be too hard I suppose – MelBurslan May 4 '16 at 13:57
  • script will do the trick – MolbOrg May 4 '16 at 14:37
  • @MelBurslan yes, that's what I am looking for. Looks like writing a script is the way to go. – syntagma May 4 '16 at 18:53

Here's a simple bash script which takes advantage of the builtin select command to present a menu.

mapfile -t routes <<<"$(ip route)"
select var in "${routes[@]}"
do   [ -n "$var" ] && sudo ip route del $var

It reads the current routes into array routes, then select presents these in a menu, eg:

1) default via dev p4p1 
2) dev p4p1  scope link  metric 1002 
3) dev p4p2  scope link  metric 1003 

To the prompt #? you type the line to delete, eg 1 and return. This sets var to the string shown next to the 1), to which is prepended the sudo ip route del command. Type an end-of-file control-d to end.

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.