How to install route command on CentOS / RHEL 7

last updated in Categories , ,

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: del-mirrors.extreme-ix.org
 * epel: mirror1.ku.ac.th
 * extras: del-mirrors.extreme-ix.org
 * remi-safe: rpms.remirepo.net
 * updates: mirror.vodien.com
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
=======================================================================================================
Installing:
 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 
 
Installed:
  net-tools.x86_64 0:2.0-0.22.20131004git.el7                                                          
 
Complete!

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
0.0.0.0         10.98.222.1     0.0.0.0         UG    0      0        0 eth0
10.98.222.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1013   0        0 eth0

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

default via 10.98.222.1 dev eth0 
10.98.222.0/24 dev eth0 proto kernel scope link src 10.98.222.3 
169.254.0.0/16 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 192.168.2.254 eth0

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

How to delete the default route

To deletes the current default route, which is labeled “default” or 0.0.0.0 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.