How to clear routing table from cache in Linux

In this article, I will show how to refresh the routing table in Linux using terminal commands. A routing table in a computer network is a data table stored on a router or network server that lists routes to specific network destinations. Generally, each static route has a metric associated with it. Network devices use this metric to determine which route to choose for packets destined for a particular network. When talking in the context of a Linux system, they also maintain a routing table, mainly if the server has multiple active network interfaces.

At some point, you may want to refresh or update the routing table so that you can access certain networks. The network can be local in your organization or it can traverse the public Internet. Most Linux distributions provide two main tools for this task, namely ip, And routing command line tools.

Refresh routing table with ip command

IP is a Unix / Linux command line tool for displaying and manipulating routes, network devices, interfaces and tunnels. It replaces the most commonly used ifconfig tool. This tool can perform almost any type of Linux network configuration for the interface. Before refreshing any routes, you may first need to check the current routing table using the following command:

$ ip route 
default via dev wlp1s0 proto dhcp metric 600 dev wlp1s0 proto kernel scope link src metric 600

As you can see from the output, my default route is set to This means that all packets destined for networks other than my local subnet will be forwarded through That IP is used for my router.

For demonstration purposes, I will start the docker service on my laptop. Docker has its own subnet. We will use it to demonstrate the use of the ip command.

$ sudo systemctl start docker
$ ip route 
default via dev wlp1s0 proto dhcp metric 600 dev docker0 proto kernel scope link src linkdown dev wlp1s0 proto kernel scope link src metric 600

Rinse a specific route

I now set up another route for the subnet via If you want to refresh this route, you will use:

$ sudo ip route flush
$ ip route 
default via dev wlp1s0 proto dhcp metric 600 dev wlp1s0 proto kernel scope link src metric 600
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface UG 600 0 0 wlp1s0 U 600 0 0 wlp1s0

You can confirm that the route has been deleted from the routing table.

Flush all routes

To flush all routes on the routing table, use the ip command option route flush table main. The full command to run is:

$ sudo ip route flush table main
$ ip route show

Rechecking the routing table should return empty. Use this command with caution, as it may kick you out of the server if you are not directly connected or have no other access method (such as console, modem, etc.).

Clear route cache

The Linux kernel usually references the route cache before getting new routes from the routing table. You can clear this cache using commands.

$ sudo ip route flush cache

Confirm all available cache routes with:

$ sudo ip route show cache

Display statistics in route cache

If you want to get more information about cache routing. Use the following command:

$ sudo ip -s route show cache

Other information, such as “used” Given a field indicating the number of times this route has been visited in the route cache.

For a permanent static route, you can place the route in any of the following files:

/etc/sysconfig/static-routes or /etc/sysconfig/network-scripts/route-  # Red Hat and its derivatives - CentOS, Fedora e.t.c
/etc/network/interfaces # Debian and its derivatives

An example of persistent routing on CentOS 7 is:

# cat /etc/sysconfig/network-scripts/route-eth0



A line on Ubuntu / Debian looks like this:

up route add -net netmask gw
down route del -net netmask gw

Please let us know your comments on this article.

Also read:

  • How to use IP commands in Linux by example
  • How to use the Linux Route Add command

Related Posts