How To Add Route In Linux

How To Add Route In Linux

In this article, we will learn: Route add command Linux. How to configure static route, and delete temporary and permanent static routes in CentOS/RedHat Linux servers.

Route manipulates the kernel’s IP routing tables. Its primary use is to set up static routes to specific hosts or networks via an interface after it has been configured with the ifconfig program. Route program now is obsolete. The newer version is ip route.

Show Linux Routing Table

Command route -n will show Linux routing table:

route -n

The output of the kernel routing table is organized in the following columns:

The destination network or destination host.
The gateway address or ‘*’ if none set.
The netmask for the destination net; ‘’ for a host destination and ‘’ for the default route.
Possible flags include
U (route is up)
H (target is a host)
G (use gateway)
R (reinstate route for dynamic routing)
D (dynamically installed by daemon or redirect)
M (modified from routing daemon or redirect)
A (installed by addrconf)
C (cache entry)
! (reject route)

Also you can use one of the following commands:

# netstat -nr
# ip route list


Add a Temporary Route

For adding temporary static routes in Linux we can use route command. So after system reboot all changes will be lost.

To add a static route for a specific host:

# route add -host gw
# route add -host eth0

Delete a static route:

# route del -host eth0


To add a static route for a specific network:

# route add -net gw
# route add -net eth0

Delete a static route for a specific network:

# route add -net eth0


Add Permanent Static Route

For add permanent static route, we need to edit the interface file in /etc/sysconfig/network-scripts folder.

Sample configuration for route-eth0 file:

# vi /etc/sysconfig/network-scripts/route-eth0 via dev eth0


Add Default Gateway Linux CentOS/RedHat

To add Default Gateway:

# route add default gw eth0

To delete default gateway use command route del:

# route del default gw eth0

To set default gateway and make routing changes persistent after reboot we need edit configuration file: /etc/sysconfig/network.


Save changes end restart networking service:

# service network restart


Leave a Reply

Your email address will not be published. Required fields are marked *