Using "ip route show" Command (with examples)
1: Display the routing table
ip route show
Motivation: This command is used to display the routing table on a Linux system. It provides a detailed overview of the different routes that packets can take to reach their destination.
Explanation: The command “ip route show” is used to display the routing table. It shows the destination network, gateway, netmask, and interface for each route in the table.
Example output:
default via 192.168.1.1 dev eth0 proto static
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10
2: Display the main routing table
ip route show main|254
Motivation: This command is useful when you want to display the main routing table specifically. The main routing table is the default table used by the system unless otherwise specified.
Explanation: The argument “main” or the number “254” is used to specify the main routing table. This command will only display the routes in the main table.
Example output:
default via 192.168.1.1 dev eth0 proto static
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10
3: Display the local routing table
ip route show table local|255
Motivation: The local routing table contains entries for local addresses and interfaces. This command is helpful when you want to view the routes in the local table, which are used for communication between applications on the same system.
Explanation: The argument “local” or the number “255” is used to specify the local routing table. This command will only display the routes in the local table.
Example output:
local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1
local 192.168.1.10 dev eth0 proto kernel scope host src 192.168.1.10
4: Display all routing tables
ip route show table all|unspec|0
Motivation: By default, the system has multiple routing tables. This command is useful when you want to display all the routing tables available on the system, including the unspecified and the table with number “0”.
Explanation: The argument “all”, “unspec”, or “0” is used to specify all the routing tables. This command will display routes from all the tables.
Example output:
default via 192.168.1.1 dev eth0 proto static table main
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10 table main
5: List routes from a given device only
ip route show dev eth0
Motivation: Sometimes, you may want to view the routes associated with a specific network interface on the system. This command allows you to list routes from a given device, in this case, “eth0”.
Explanation: The argument “dev eth0” is used to specify the network device. This command will only display the routes associated with the specified device.
Example output:
default via 192.168.1.1 dev eth0 proto static
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10
6: List routes within a given scope
ip route show scope link
Motivation: Scopes define the visibility and reachability of routes. This command is useful when you want to view the routes within a specific scope, such as link-local.
Explanation: The argument “scope link” is used to specify the scope. This command will only display the routes within the specified scope.
Example output:
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10
7: Display the routing cache
ip route show cache
Motivation: The routing cache is used to optimize routing performance by storing frequently used routes. This command allows you to view the contents of the routing cache.
Explanation: The command “ip route show cache” is used to display the routing cache. It shows the cached routes and their associated information.
Example output:
local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1
8: Display only IPv6 or IPv4 routes
ip -6|-4 route show
Motivation: Depending on your network configuration, you may want to display only IPv6 or IPv4 routes. This command allows you to specify whether you want to display IPv6 or IPv4 routes.
Explanation: The option “-6” or “-4” is used to specify IPv6 or IPv4 routes, respectively. This command will only display routes of the specified IP version.
Example output (for “-4”):
default via 192.168.1.1 dev eth0 proto static
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10