Linux Mint

View Network Routing Table Using the ip route Command in Linux Mint 20.3

A routing table contains routing entries that determine where all packets go when they leave a router or a system. Usually, the Linux systems use dynamic routing, where the kernel decides which route out of multiple routes a packet should follow. However, you can also add static routes, which are not dynamically updated, if you want to forward specific traffic to a particular gateway or router.

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:

$ ip route

Or

$ ip r

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:

$ sudo ip route add <network-address> via <gateway-ip> dev <interface-name>

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.

$ sudo ip route add 10.0.0.0/24 via 192.168.42.2 dev ens33

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:

$ sudo nano /etc/network/interfaces

Add following entry for your static route:

up route add -net <network-address> netmask <subnet-mask> dev <interface-name>

Then, save and close the file and restart the network service:

$ sudo systemctl restart network

Deleting Routes

To delete a route using the “ip route” command, use the previous syntax but replace the add option by del:

$ sudo ip route del <network address> via <gateway_ip> dev <interface name>

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:

$ sudo ip route add default via <gateway-ip>

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.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.