How to add a new network gateway or static route

How can I add an additional network gateway to an AlmaLinux and CentOS Linux host?

Configure Using Network Manager

Use nmcli, nmtui, or the GUI tools to change connection routes.

Modify the ipv4.routes property of the connection with nmcli to add a route. For a connection named “external,” for example, to add a route to the network via

# nmcli connection modify external ipv4.routes ""

To add additional routes, use the + (plus) modifier on the ipv4.routes property of the connection.

# nmcli connection modify external +ipv4.routes ""

Numerous routes can be added simultaneously, separated by a comma.

# nmcli connection modify external ipv4.routes ","

To delete a route, specify the route to be deleted using the – (minus) modifier on the connection’s ipv4.routes property.

# nmcli connection modify external -ipv4.routes ""

To disable all routes, change the value of the ipv4.routes property to “” [empty] (*1).

# nmcli connection modify external ipv4.routes ""

(*1) If no “+/-” is specified, it means that the entire list of current routes will be updated. However, if you specify “” [empty], it will remove all routes regardless of whether “+/-” is specified.

Bring the connection back up after making any of the modifications listed above. For instance, following the modification of the properties of the “external” connection.

# nmcli connection up external

Configure Without Network Manager

To add static routes, create or modify a route-<interface> file in the /etc/sysconfig/network-scripts/ directory, where <interface> is the name of the interface to which the routes should be added. Each route should be contained on a single line and take the basic form <network/prefix> via <gateway>, where <network/prefix> denotes the remote network’s IP address with prefix and gateway> denotes the next hop’s IP address. For instance, to add a route to the network via and another to the network via, both of which should be active when eth0 is up.

$ cat /etc/sysconfig/network-scripts/route-eth0 via via

For changes to take effect, the interface must be brought up again.

# ifup eth0

There is an older syntax for route-<interface> files recognized by all versions of CentOS that don’t use NetworkManager files.


This format has three fields: GATEWAY, NETMASK, and ADDRESS. These are the three fields this format deals with. Each field should have a number next to it that tells you which route it is for.

The gateway IP address is Z.Z.Z.Z in the example above. The following entries must be numbered in order (for example, ADDRESS1=, NETMASK1=, GATEWAY1=). Multiple entries must be numbered sequentially and must not skip a value (0 must be followed by 1, not a number greater than 1).

Leave a Reply