In today’s article, we will cover how to view network routing tables using the “ip route” command in Linux Mint 20.3 OS.
Note: You need sudo privileges to make any changes in the routing table. However, viewing the routing table doesn’t need any sudo privileges.
View Network Routing Table Using the “ip route” Command
The “ip route” command in Linux is used to view and modify the routing table. Using this command, you can add new routes to a particular network or host. You can delete the routes if you no longer want them in your routing table.
To view the network routing table in your Linux Mint, open the Terminal and run the following command:
Or
In the output, you will see a list of network destinations and gateways. The gateways are the addresses where the packets are forwarded when they are moving toward their destination. These routes are dynamic routes unless you have already added the static routes.
Following is the output of the “ip route” command in our system. The 192.168.42.0 is the local network attached to the network interface ens33. The 192.168.42.2 is the default gateway. Any traffic not intended for the local network and is not defined in the routing table is forwarded to this address.
Adding New Routes
Using the “ip route” command, you can also add a new route for a specific network. Use the following syntax to add a new route in your system’s routing table:
For instance, the following command adds the route for the 10.0.0.0/24 network through gateway 192.168.42.2 to route it through the ens33 network interface.
Permanently Adding Routes in Linux
The static route added by the “ip route” command is not a persistent route. A persistent route stays in place even when you reboot your system. To permanently add the static routes and to make them persistent, you will need to add the entry in the /etc/network/interfaces file.
Edit the /etc/network/interfaces file through the following command:
Add following entry for your static route:
Then, save and close the file and restart the network service:
Deleting Routes
To delete a route using the “ip route” command, use the previous syntax but replace the add option by del:
Adding a New Default Gateway
Sometimes, you must add a new default gateway to your Linux system. The “ip route” command also allows you to add a new default gateway. Use the following syntax:
Conclusion
In this post, we reviewed how to view the network routing table using the “ip route” command in Linux Mint 20.3 OS. We also covered how to permanently add routes in Linux Mint so that they persist after reboot. Remember, this is not the only way to view the network routing table in Linux. You can also view the routing table using the “netstat” and “route” commands.