Skip the “show ip route” legend

Are you as upset as I am with the constant display of the legend in front of the routes displayed with the show ip route command? Two output filters can help you. The easier one is show ip route parameters ¦ begin Gateway (as there is always a line starting with Gateway of last resort ...) before the actual IP routes:
a1#show ip route 172.16.0.0 longer ¦ begin Gateway
Gateway of last resort is not set

172.16.0.0 255.255.0.0 is variably subnetted, 4 subnets, 2 masks
O 172.16.0.21 255.255.255.255
[110/51] via 172.18.1.2, 00:04:56, Serial0/0/0.100
O 172.16.0.12 255.255.255.255
[110/65] via 172.18.1.6, 00:04:56, Serial0/1/0
C 172.16.0.11 255.255.255.255 is directly connected, Loopback0
O 172.16.1.4 255.255.255.252
[110/113] via 172.18.1.6, 00:04:56, Serial0/1/0
A slightly more complex one matches the first line that has a digit after the leading white space.
a1#show ip route 172.16.0.0 longer ¦ begin ^ +[0-9]+
172.16.0.0 255.255.0.0 is variably subnetted, 4 subnets, 2 masks
O 172.16.0.21 255.255.255.255
[110/51] via 172.18.1.2, 00:08:55, Serial0/0/0.100
O 172.16.0.12 255.255.255.255
[110/65] via 172.18.1.6, 00:08:55, Serial0/1/0
C 172.16.0.11 255.255.255.255 is directly connected, Loopback0
O 172.16.1.4 255.255.255.252
[110/113] via 172.18.1.6, 00:08:55, Serial0/1/0

If only IOS would have more decent regular expressions, like \s and \d ...

7 comments:

  1. Another, shorter use of pipes to do the same thing:

    PE12#show ip route | ex -

    Gateway of last resort is 0.0.0.0 to network 0.0.0.0

    C 192.168.12.0/24 is directly connected, FastEthernet0/1
    5.0.0.0/24 is subnetted, 1 subnets
    C 5.2.2.0 is directly connected, Loopback0
    7.0.0.0/24 is subnetted, 1 subnets
    C 7.0.0.0 is directly connected, FastEthernet0/0
    S* 0.0.0.0/0 is directly connected, FastEthernet0/0

    Great blog BTW.
  2. Great out-of-the-box thinking, I've completely missed it. Thanks :)
  3. There's "| section" also to get a more compact output :

    #sh ip route | s net
    Gateway of last resort is 10.48.77.1 to network 0.0.0.0
    1.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
    C 1.1.1.1/32 is directly connected, Virtual-Access1.1
    C 1.1.1.0/24 is directly connected, Virtual-Access1.1
    2.0.0.0/32 is subnetted, 1 subnets
    C 2.2.2.2 is directly connected, Loopback0
    210.23.147.0/30 is subnetted, 1 subnets
    C 210.23.147.236 is directly connected, ATM1/0.1600042
    10.0.0.0/24 is subnetted, 1 subnets
    C 10.48.77.0 is directly connected, GigabitEthernet0/2
  4. Thanks, Xavier, great idea ;). Your comment made me wonder how the section filter really works. I thought I knew how a section is defined, but obviously I was wrong. My impression was the a section is something that starts with a non-blank character in the first line, but your tip suggests the IOS actually knows which lines are related. Interesting ... is there any (semi)official explanation on this?

    BTW, your filter does not include non-subnetted major networks, like

    O 192.168.0.0 255.255.255.0
    [110/51] via 172.16.1.2, 00:03:40, Serial0/0/0.100
    [110/51] via 10.0.0.6, 00:03:40, FastEthernet0/0
  5. You're right :-)

    Here's the official documentation about the section keyword:
    Show Command Section Filter

    It's not very detailed but at least, I've found that we can do | section exclude regexp. For example, sh run | s e ^int|!" might be useful when you have a lot of interfaces.
  6. Why does the output of "show ip route" command, sometimes show a particular network as varaibly subnetted and sometimes just subnetted? Also the line shows "x" subnets but the x does not match the number of subnets
  7. what command dispaly the shutdown routes?
Add comment
Sidebar