Configuring a Static Route Using the Command Line in Interactive Mode

You can use the nmcli command in interactive mode to configure network settings, including configuring static routes. When in interactive mode, the nmcli> prompt appears where you can run commands to configure static routes for a specific connection profile.

This procedure assumes the following network settings for creating the static route:

  • Name of the connection: myconnection
  • Default gateway address: 198.51.100.1
  • Network to which you want to create a static route: 192.0.2.0/24

To create the route, ensure first that the default gateway for the route is directly reachable on the interface. Then, do the following:

  1. Start nmcli in interactive mode.
    sudo nmcli connection modify myconnection
    nmcli>
  2. Create the static route.
    nmcli> set ipv4.routes 192.0.2.0/24 198.51.100.1
  3. Display the new configuration.
    nmcli> print
    ...
    ipv4.routes:        { ip = 192.0.2.1/24, nh = 198.51.100.1 }
    ...
  4. Save the configuration.
    nmcli> save persistent
  5. Restart the network connection.

    This step causes the connection to temporarily drop.

    nmcli> activate myconnection
  6. Exit the interactive mode.
    nmcli> quit
  7. Verify that the new route is active.
    ip route
    ...
    192.0.2.0/24 via 198.51.100.1 dev example proto static metric 100