CentOS/RHEL:How To configure Static Routes or Persistent Routes

I would like to add a persistent route or static route on my centOS 7/6.5 or RHEL7/6.5 linux, HOw Do I create static routes so that the changes still can be there while system startup up? How to add persistent routes on CentOS 7 linux operating system ? this post will guide you how to configure static routes on your linux system.

You need to edit “/etc/sysconfig/network” configuration file to set default gatway or edit “/etc/sysconfig/network-scripts/route-eth0” network interface configuration file to set static gateway for particular network interface.

CentOS/RHEL check the current routing talbe


To display current kernel IP routing table by running the following command:

netstat -nr

route -n 

ip route list

Outputs:

[root@devops temp]# netstat -nr

Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

0.0.0.0         10.0.2.1        0.0.0.0         UG        0 0          0 enp0s3

0.0.0.0         10.0.2.2        0.0.0.0         UG        0 0          0 enp0s3

10.0.2.0        0.0.0.0         255.255.255.0   U         0 0          0 enp0s3

[root@devops temp]# route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

default         10.0.2.1        0.0.0.0         UG    0      0        0 enp0s3

default         10.0.2.2        0.0.0.0         UG    1024   0        0 enp0s3

10.0.2.0        0.0.0.0         255.255.255.0   U     0      0        0 enp0s3

[root@devops temp]# ip route list

default via 10.0.2.1 dev enp0s3 

default via 10.0.2.2 dev enp0s3  proto static  metric 1024 

10.0.2.0/24 dev enp0s3  proto kernel  scope link  src 10.0.2.15

CentOS/RHEL configure static routes (persistent routes)


To set static default gateway on your system, you need to edit “/etc/sysconfig/network” file and add the below sample configuration content in.

NETWORKING=yes

HOSTNAME=itsprite.com

GATEWAY=10.0.2.1 #====>set the default gateway

then save an close above configuraton file.

next, restart the network service by issue the following command:

systemctl restart network.service

OR

systemctl restart network

You might also like:

Sidebar



back to top