There is more than one way to add static routes on Centos. One way is to just use ip route or route commands as we shall see. On the other hand if we want those routes to persist after reboot then we need to use nmcli or do it the old fashion way and edit some config files. We shall see both ways below as we::

Add persistent routes

By using nmcli command line tool

On Centos 7 onwards and already many versions of Fedora, using nmcli is the preferred way of adding persistent route.

nmcli connection modify "connection-name" +ipv4.routes "network address/prefix gateway"

nmcli connection up "connection-name"

We can verify:


nmcli connection show
Example

For example, lets add an entry that will route all traffic to the 10.0.0.0/24 network through the gateway of 192.168.1.10. And the name of the connection is enp0s3.

nmcli connection modify "enp0s3" +ipv4.routes "10.0.0.0/24 192.168.1.10"

nmcli connection reload

nmcli connection up enp0s3

Do not Forget the + mark before the keyword ipv4.routes (+ipv4.routes). Otherwise, existing entries will be overridden.

Method Two : Manually Create Configuration File
It is also possible to add permanent IP routes directly into the configuration file. First, we need to create the configuration file inside the /etc/sysconfig/network-scripts/ directory using the following format.

route-connectioname

For example, if the name of the network connection is enp0s3, then The name of the configuration file should be

route-enp0s3

Next Insert the routing to the configuration file using following format.

10.0.0.0/24 via 192.168.1.10

192.168.100.0/24 via 192.168.1.10

192.168.50.10/32 via 192.168.1.1

Alternatively, you can also use the following format.

ADDRESS0=10.0.0.0

NETMASK0=255.255.255.0

GATEWAY0=192.168.1.10

ADDRESS1=192.168.50.10

NETMASK1=255.255.255.255

GATEWAY1=192.168.1.1

Finally, you need to restart the network connection using nmcli command.

nmcli connection reload

nmcli connection up enp0s3

You can use the either of these two methods to add permanent routes in CentOS 7 Linux.