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:
- Open a terminal on your Linux system.
- 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.
- 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.
- 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.
- 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.
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Comment anonymously. Login not required.