Linux route Add Command Examples – ciscostuff

How do we add a route to linux system? what if we have to define custom routes for networking scheme required in my environment? How to use linux route command to show, add or modify the current routing table?

in order to modify the routing table, we can use any of the two commands; ip route or route. Both shows their magic and achieve the same goal of adding, deleting or modifying route parameters.

Display Current Routing Table

From the terminal, issue the following command

# route                                          


# ip route list

Output will look something like this:

[root@redHat~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default UG 100 0 0 ens192 U 100 0 0 ens192  U 0 0 0 virbr0

Additionally, following commands can be executed as well:

# route -n                                        


# ip route show                                   

Linux Add a Default Route using route add command

# route add default gw dev ens192     


Linux add a default gateway via ens192 using ip route  add commmand

# ip route add dev ens192          

Added routes can be verified using the above commands i.e ip route or route -n


Persistent route in Red Hat, Centos or Fedora

If you wish to add the routes and let them stay persistent regardless of the system reboots, edit the following configuration file in rpm based  operating systems.

# vi /etc/syconfig/network                        


Share your thoughts