In Linux How to Flush Routing Table from Cache

Routing Table

A routing table in computer networking is a data table that's stored on a router or network server which lists the routes to particular network destinations. Usually, each static route has a metric associated with it. This metric is used by network devices to decide which route to be selected for packets destined to a particular network. When talking in the context of Linux Systems, they also maintain a routing table, mostly when the server has more than one active network interface.

At some point, you may want to flush a routing table or update it so that you can access some networks. The network(s) can be local in your organization, or where traversing the public internet is involved. Most Linux distributions provide two major tools used for this task, namely ip, and route command line tools.

Flush routing table using ip command

ip is a Unix/Linux command line tool used to show and manipulate routing, network devices, interfaces, and tunnels. It is a replacement for the mostly used ifconfig tool. This tool can do almost all kinds of Linux network configurations for an interface. Before you flush any routes, you may first need to check your current routing table using the 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 my output, my default route is set to This means all packets destined for networks other than my local subnet will be forwarded through This IP is for my router.

For demonstration purposes, I'm going to start docker service on my Laptop. Docker has its own subnet. we'll use this to demonstrate the usage of 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

Flush specific route

I now have another route for subnet via If I want to flush this route, I'll 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 removed from the routing table.

Flush all routes

To flush all routes on the routing tables, the ip command options route flush table main are used. The full commands to run are:

$ sudo ip route flush table main
$ ip route show

A recheck for the routing table should return empty. This command should be used with caution since it can kick your out of the server if you're not on direct connection or don't have other access methods like a console, modem e.t.c.

Empty a routing cache

The Linux kernel usually refers to the routing cache before fetching a new route from the routing tables. This cache can be cleared using the command.

$ sudo ip route flush cache

The confirm any available cached routes with:

$ sudo ip route show cache

Displaying statistics from the routing cache

If you would like to get more information about the cached routes. use the commands:

$ sudo ip -s route show cache

Additional information like "used" field is given, which indicates the number of times this route has been accessed in the routing cache.

For persistent static route, you can place routes in any of the below files:

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

An example of persistent routes on CentOS 7 is:

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



A line on Ubuntu/Debian will look like below:

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

Please let us know your comments on this article.

Bobbin Zachariah 10:39 pm

About Bobbin Zachariah

Founder of LinOxide, passionate lover of Linux and technology writer. Started his career in Linux / Opensource from 2000. Love traveling, blogging and listening music. Reach Bobbin Zachariah about me page and google plus page.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.