How to Flush Routing Table from Cache in Linux

Last updated: June 25, 2022

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 or Unix 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.

In this guide, we learn how to flush routing table in Linux using terminal commands.

Flush routing table using ip command

IP is a Linux command line tool used to show and manipulate routing, network devices, interfaces, and tunnels. It is a replacement for ifconfig tool. IP command 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 you 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 following 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 a persistent static route, you can place routes in any of the below files:

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

An example of persistent routes on RedHat or CentOS Stream is:

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



A line on Ubuntu/Debian will look like the below:

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


In this tutorial, we learned how to flush the routing table from cache from the Linux terminal.

Thanks for reading, add your suggestions and feedback in the below comment section.

About The Author

Bobbin Zachariah

Bobbin Zachariah

Bobbin started his career in IT in the year 2000 as a computer science instructor and worked as a Linux system engineer and senior analyst roles. Currently working in DevOps environments to increase efficiency and improve delivery time in AWS Cloud infrastructure. He is certified in RHEL, CCNA, and MCP and holds a Masters's in computer science. When in his free time love playing cricket, blogging, and listening to music.



Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment