LinuxCommandLibrary

ip-route-show

Show the system's routing table

TLDR

View documentation for the original command

$ tldr ip route list
copy

SYNOPSIS

ip route show [ SELECTOR ]

PARAMETERS

SELECTOR
    A placeholder for various filtering options to narrow down the displayed routes.

dev IFNAME
    Displays routes associated with a specific network interface (e.g., eth0, enp0s3).

table TABLE_ID
    Shows routes from a specified routing table. Common tables include main (default), local (for local and broadcast addresses), and default (a synonym for main). Custom tables can also be specified by ID or name.

type TYPE
    Filters routes by their type, such as unicast (default), local, broadcast, nat, unreachable, prohibit, or blackhole.

scope SCOPE_ID
    Displays routes with a specific scope: global (reachable anywhere), link (reachable only on the local link), or host (only on the local host).

proto PROTO_ID
    Filters by the routing protocol that installed the route. Examples include kernel (routes added by the kernel itself), static (manually added), boot, dhcp, ospf, bgp, etc.

src ADDRESS
    Filters routes by the source IP address that would be used when sending traffic over this route.

to ADDRESS | PREFIX
    Filters routes destined for a specific IP address or network prefix (e.g., 192.168.1.0/24).

via ADDRESS
    Filters routes that use a specific gateway IP address.

iif IFNAME
    Filters routes matching packets coming in via the specified interface.

oif IFNAME
    Filters routes matching packets going out via the specified interface.

exact
    When used with to or from, ensures an exact match on the address/prefix length, rather than a longest-prefix match.

DESCRIPTION

The ip route show command is a fundamental tool within the iproute2 suite, used to display the kernel's IP routing tables. It provides a comprehensive view of how your Linux system forwards network packets. Unlike older utilities like route, ip route show offers more detailed and granular control over routing information, including support for multiple routing tables (e.g., main, local), policy routing, and various filtering options. Understanding its output is crucial for network troubleshooting, verifying connectivity, and validating network configurations. The command's output typically includes the destination network, gateway, output device, protocol by which the route was learned, and scope. It's an essential command for any network administrator or power user working with Linux systems.

CAVEATS

While ip route show generally does not require root privileges to display the main routing table, certain advanced operations or access to specific non-default routing tables might. The output can be extensive, especially on complex networks, making it beneficial to pipe the output to tools like grep, awk, or less for easier readability and filtering. It's important to have a basic understanding of IP networking concepts to fully interpret the command's output.

UNDERSTANDING OUTPUT COLUMNS

The output of ip route show typically includes several columns:

  • default or a network prefix: The destination network or host.
  • via GATEWAY_IP: The IP address of the next-hop gateway for reaching the destination.
  • dev IFNAME: The outgoing network interface used for this route.
  • proto PROTOCOL: Indicates how the route was learned (e.g., kernel for directly connected networks, static for manually added routes, dhcp, ospf, etc.).
  • scope SCOPE: Defines the reachability of the destination (e.g., link for directly connected, global for publicly routable).
  • src SOURCE_IP: The preferred source IP address used for packets leaving this interface via this route.
  • metric VALUE: A cost associated with the route; lower values are preferred.

ROUTING TABLES

Linux kernels can maintain multiple independent routing tables. By default, ip route show displays entries from the main table. Other common tables include local (for routes to local addresses and broadcast addresses) and default (often an alias for main). Users can define custom routing tables for policy routing, which allows for more complex routing decisions based on various criteria (e.g., source IP, application). These tables are typically defined in /etc/iproute2/rt_tables.

HISTORY

The ip route show command is part of the iproute2 utility suite, which was developed to replace older, less powerful network configuration tools like ifconfig and route. Initiated by Alexey Kuznetsov, iproute2 provides a more robust and modern interface for managing network configurations in Linux. It leverages advanced kernel features such as policy routing, multiple routing tables, and comprehensive traffic control. Its adoption marked a significant shift in how network administrators manage Linux networking, offering greater flexibility and control over the network stack, particularly beneficial for complex network environments and IPv6.

SEE ALSO

ip(8), ip-route(8), route(8), netstat(8), ifconfig(8), ss(8), ping(8), traceroute(8)

Copied to clipboard