Configuring a Static Route Using the Command Line
To configure static routes with the nmcli
command, use the following
syntax:
nmcli connection modify connection_name +ipv4.routes "ip[/prefix] options(s) attribute(s)"[next_hop] [metric] [attribute=value] [attribute=value] ..."
- +ipv4.routes
- The plus (+) sign indicates that you're creating an IPv4 route. Without the sign, the command changes an existing IPv4 setting.
- connection-name
- Connection name or label for which you're creating a static route.
- ip[/prefix]
- IP address of the static route that you're creating. The IP address can also be in CIDR notation.
- options
- Options include next hop addresses and optional route metrics. These options are
separated by spaces. For more information, see the
nm-settings-nmcli(5)
manual pages. - attributes
- Attributes are entered as attribute=value and are also separated by
spaces. Some attributes are
mtu
,src
,type
,cwnd
, and so on. For more information, see thenm-settings-nmcli(5)
manual pages.
Suppose that you have the following configurations:
- 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: