How to Dump All Routes of All Tables with iproute2

bashiproute2

I want to save all routes of all routing tables.

I have this script:

#!/bin/bash

DUMP=dump.log

for i in `seq 0 255`;
do
    routes="`ip route show table ${i}`"
    if [ ! -z "${routes}" ];then
        echo "table: ${i}" >> ${DUMP}
        echo "${routes}" >> ${DUMP}
        echo "" >> ${DUMP}
    fi
done

the problems I have with this script are:

  1. it iterates on all tables, and assume that the only valid table numbers are 0-255, is this a valid assumption?
  2. is there a simple 1 liner for getting all routes for all tables?

Thanks

Best Answer

ip route list table all

It's written in ip route help.