How to install route command on CentOS / RHEL 7

in Categories , , last updated January 30, 2018

I am trying to use route command command on a CentOS Enterprise Linux/Red Hat Enterprise Linux version 7 (RHEL 7). But, I am getting the following error:
    bash: route: command not found
How do I install router command on CentOS/RHEL 7 and use it?

The route command deprecated in CentOS/RHEL 7/Fedora and many other Linux distributions. You need to use the ip command instead of route command. However, it is possible to install router and other deprecated command for compatibility reasons. This page shows how to install route command on CentOS/RHEL 7 server.

How to find out what package provides route command

Type the following yum command:
# yum whatprovides route
The output indicate that I need to install net-tools package. To get more info on the net-tools, run:
# yum info net-tools
yum whatprovides route command on CentOS RHEL Fedora server

How to install route command using yum

Simply type the following yum command:
# yum install net-tools
Sample outputs:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
 * epel:
 * extras:
 * remi-safe:
 * updates:
Resolving Dependencies
--> Running transaction check
---> Package net-tools.x86_64 0:2.0-0.22.20131004git.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
 Package               Arch               Version                               Repository        Size
 net-tools             x86_64             2.0-0.22.20131004git.el7              base             305 k
Transaction Summary
Install  1 Package
Total download size: 305 k
Installed size: 917 k
Is this ok [y/d/N]: y
Downloading packages:
net-tools-2.0-0.22.20131004git.el7.x86_64.rpm                                   | 305 kB  00:00:03     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : net-tools-2.0-0.22.20131004git.el7.x86_64                                           1/1 
  Verifying  : net-tools-2.0-0.22.20131004git.el7.x86_64                                           1/1 
  net-tools.x86_64 0:2.0-0.22.20131004git.el7                                                          

How to use route command

To see current route type:
# route -n
Sample outputs:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    0      0        0 eth0   U     0      0        0 eth0     U     1013   0        0 eth0

You can use ip command for same purpose:
# ip r
Sample outputs:

default via dev eth0 dev eth0 proto kernel scope link src dev eth0 scope link metric 1013

How to add default gateway/router IP

Run command:
route add default gw {IP-ADDRESS} {INTERFACE-NAME}
route add default gw eth0

You can also use ip command as follows to set default routing/gateway on Linux:
# ip route add default via
Verify it:
# route -n
# ip r

How to delete the default route

To deletes the current default route, which is labeled “default” or in the destination field of the current routing table.
# route del default
For more info read the route command man page:
$ man route

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Share this on (or read 0 comments/add one below):