The routing table in Linux contains essential information about how data packets are directed across networks. It helps determine the path that packets take to reach their destination. The routing table is stored in the Routing Information Base (RIB), which manages all the network routes within the system.

Older Linux systems used the route and netstat commands to display routing information. However, these commands are part of the now-deprecated net-tools package. Modern Linux distributions have transitioned to the iproute2 suite, which offers more advanced features for managing and viewing network routes.

Most Linux systems come pre-installed with iproute2. If not, it can be installed through your system's package manager. This suite provides the tools needed to view and manipulate the routing table effectively.

Steps to check the routing table in Linux:

  1. Open a terminal on your Linux system.
  2. Install iproute2 if it's not already installed.
    $ sudo apt update && sudo apt install --assume-yes iproute2 # Ubuntu and Debian

    Most modern Linux distributions, including Ubuntu, come with iproute2 pre-installed.

  3. Display the full routing table using the ip command.
    $ ip route list
    default via 192.168.111.2 dev ens33 proto dhcp src 192.168.111.128 metric 100
    192.168.111.0/24 dev ens33 proto kernel scope link src 192.168.111.128
    192.168.111.2 dev ens33 proto dhcp scope link src 192.168.111.128 metric 100

    The command lists all routes in the routing table, including default routes and network-specific routes.

  4. View routing information for a specific network segment.
    $ ip route list 192.168.111.0/24
    192.168.111.0/24 dev ens33 proto kernel scope link src 192.168.111.128

    Replace `192.168.111.0/24` with the specific network segment you want to view.

  5. Filter and display a particular route using the grep command.
    $ ip route list | grep ^default
    default via 192.168.111.2 dev ens33 proto dhcp src 192.168.111.128 metric 100

    This is useful for people who are used to grep rather than having to memorize all the switches for the ip route command.

Discuss the article:

Comment anonymously. Login not required.