To establish static routes, use the ip route command in global configuration mode. To remove static routes, use the no form of this command.
Syntax
ip route prefix {mask | /prefix-length} {{ip-address [metric value]} | reject-route}
no ip route prefix {mask | /prefix-length} [ip-address]
Parameters
-
prefix—IP route prefix for the destination.
-
mask—Prefix mask for the destination.
-
/ prefix-length—Prefix mask for the destination.Specifies the number of bits that comprise the IP address prefix. The prefix length must
be preceded by a forward slash (/). (Range: 0–32)
-
ip-address—IP address of the next hop that can be used to reach that network.
-
metric value—Metric of the route. The default metric is 4 for the Next Hop on an In-Band interface . Range: 1–255.
-
reject-route—Stopping routing to the destination network.
Default Configuration
No static routes are established.
Command Mode
Global Configuration mode
User Guidelines
Use the no ip route command without the ip-address parameter to remove all static routes to the given subnet.
Use the no ip route command with the ip-address parameter to remove only one static route to the given subnet via the given next hop.
Examples
Example 1—The following example shows how to route packets for network 172.31.0.0 to a router at 172.31.6.6 using mask:
switchxxxxxx(config)# ip route 172.31.0.0 255.255.0.0 172.31.6.6 metric 2
Example 2—The following example shows how to route packets for network 172.31.0.0 to a router at 172.31.6.6 using prefix length :
switchxxxxxx(config)# ip route 172.31.0.0 /16 172.31.6.6 metric 2
Example 3—The following example shows how to reject packets for network 194.1.1.0:
switchxxxxxx(config)# ip route 194.1.1.0 255.255.255.0 reject-route
Example 4—The following example shows how to remove all static routes to network 194.1.1.0/24:
switchxxxxxx(config)# no ip route 194.1.1.0 /24
Example 5—The following example shows how to remove one static route to network 194.1.1.0/24 via 1.1.1.1:
switchxxxxxx(config)# no ip route 194.1.1.0 /24 1.1.1.1