How to Add Permanent Routes in CentOS 7

Usually we add ip routes in Linux using either route command or "ip route" command. While both commands work the same way, neither command can use to add permanent routes to the system. They will get removed if you restart the network or if the server rebooted.

We have two methods to add permanent static routes in CentOS 7. One method is to use nmcli command, another method is to add entries manually by directly adding the configuration file into the /etc/sysconfig/network-scripts/ directory.

Method One : Using nmcli command line tool

Manage networking using nmcli command is the preferred way in CentOS 7. Use following format to add persistent route using nmcli command.

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

nmcli connection up "connection-name"

You can use the following command to list configured network connections on your CentOS 7 server.

nmcli connection show


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

nmcli connection modify "enp0s3" +ipv4.routes ""

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.


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


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

Alternatively, you can also use the following format.







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.