CentOS/RHEL7: Install Route Command

If the route command is not installed in your default CentOS or RHEL 7 Linux, you need to install it. And The RHEL 7 maybe does not support route command. how to achieve it. This post will guide you how to install route command in CentOS /RHEL 7 Linux.

Of course, you can use the “ip route” command instead of “route” command to achieve the same result.

Install Route Command


You need to find what package provides route command firstly, then install that package. Type the following command:

# yum whatprovides route

Outputs:

[root@osetc_x8664 ~]# yum whatprovides route
Loaded plugins: rhnplugin, ulninfo
This system is receiving updates from RHN.
net-tools-2.0-0.17.20131004git.el7.x86_64 : Basic networking tools
Repo : @rhel_x86_64_latest
Matched from:
Filename : /usr/sbin/route

From the above output, it indicate that you need to install a package called net-tools.

You can use the yum install command to install this package, type:

# yum install net-tools

Outputs:

[root@vultr ~]# yum install net-tools
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.hostduplex.com
* epel: mirrors.develooper.com
* extras: mirrors.usc.edu
* updates: mirror.sfo12.us.leaseweb.net
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:00
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!

Use Route Command to Display Route Table


After net-tools package is installed, you can run the route command to check the current route table, type the following command:

# route -n

outputs:

[root@osetc_x8664 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.147.84.1 0.0.0.0 UG 100 0 0 eth0
192.147.36.60 192.147.84.1 255.255.255.255 UGH 100 0 0 eth0
192.147.84.0 0.0.0.0 255.255.252.0 U 100 0 0 eth0

You can also use the “ip r” command to print the current route table info, type:

# ip r

Outputs:

[root@osetc_x8664 ~]# ip r
default via 192.147.84.1 dev eth0 proto static metric 100
192.147.36.60 via 192.147.84.1 dev eth0 proto dhcp metric 100
192.147.84.0/22 dev eth0 proto kernel scope link src 192.147.87.207 metric 100

Add Default Gateway Using Route Command


If you want to add default gateway to route table, you can run the following command:

# route add default gw 192.168.1.2

This command will add one default gateway into the route table, and the ip address of gateway is 192.168.1.2.

You can also use the IP command to set the default gateway, type the following command:

# ip route add default via 192.168.1.2

Delete Default Gateway Using Route Command


If you want to delete one default gateway from route table, type the following command:

# route del default gw 192.168.1.2

Add and delete route to a Host Type


if you want to add route to a host type, type the following command:

# route add -host 192.168.1.30 gw 192.168.1.2

Delete route to a host, type:

# route del -host 192.168.1.100 gw 192.168.1.2

If you want to get more information about route command, you can check the man page of route command:

# man route

or

# info route

 

You might also like:

Sidebar



back to top