Skip to main content
  1. Router and Switch Articles/
  2. IOS-XE/

Configuring an IPv4 Static Route on Cisco IOS XE

Table of Contents

How to Configure a Static Route on Cisco IOS XE

This is the command for configuring a static route on Cisco IOS XE. Run it in global configuration mode.

Cisco IOS XE Static Route Configuration
ip route [DESTINATION_NETWORK] [SUBNET_MASK] [NEXT_HOP_IP_ADDRESS]
FieldValue
[DESTINATION_NETWORK]The destination network address for the static route (use 0.0.0.0 for a default route)
[SUBNET_MASK]The subnet mask in dotted-decimal notation (use 0.0.0.0 for a default route)
[NEXT_HOP_IP_ADDRESS]The IP address of the neighboring router to forward packets to

For configuring an IPv4 address on an interface, see Configuring an IPv4 Address on a Cisco IOS XE Interface. For the basic concept of static routing, see Static Routing.

The ip route command only accepts subnet-mask notation. As with the IOS XE ip address command, prefix-length (CIDR) notation cannot be specified.

Specifying an Outgoing Interface

Instead of, or together with, the next-hop IP address, you can also specify an outgoing interface.

Cisco IOS XE Static Route Configuration (Outgoing Interface + Next Hop)
ip route [DESTINATION_NETWORK] [SUBNET_MASK] [INTERFACE_NAME] [NEXT_HOP_IP_ADDRESS]
FieldValue
[INTERFACE_NAME]The name of the interface to send packets out of (e.g. GigabitEthernet1)

Entering this format on XE1 for a test route (192.0.2.0/24, removed after verification) results in the following configuration.

XE1 Outgoing Interface + Next Hop Example (Verification)
XE1(config)#ip route 192.0.2.0 255.255.255.0 GigabitEthernet1 10.1.2.2
XE1(config)#end
XE1#show running-config | include ip route
ip route 192.0.2.0 255.255.255.0 GigabitEthernet1 10.1.2.2
The biggest benefit of specifying an outgoing interface is that if that interface goes down, the static route itself is automatically invalidated and removed from the routing table. When only a next-hop IP address is specified, reachability is determined indirectly through a recursive lookup — so even if the link is actually down, the static route can remain active as long as reachability to the next hop is still available via some other route.

In the “Verification on Real Devices” section below, XE1 and XE2’s static routes are configured using the outgoing-interface format.

Specifying an Administrative Distance

Adding a number after the next-hop IP address lets you explicitly specify the administrative distance (AD) of that static route (the default is 1).

Cisco IOS XE Static Route Configuration (Distance)
ip route [DESTINATION_NETWORK] [SUBNET_MASK] [NEXT_HOP_IP_ADDRESS] [DISTANCE]
FieldValue
[DISTANCE]The administrative distance value, in the range 1–254

This was also verified on XE1 by specifying a distance of 200 for 192.0.2.0/24.

XE1 Distance Example (Verification) Config
ip route 192.0.2.0 255.255.255.0 10.1.2.2 200
XE1 Distance Configuration Example (Verification)
XE1#config term
Enter configuration commands, one per line.  End with CNTL/Z.
XE1(config)#no ip route 192.0.2.0 255.255.255.0 GigabitEthernet1 10.1.2.2
XE1(config)#ip route 192.0.2.0 255.255.255.0 10.1.2.2 200
XE1(config)#end
XE1#

The specified value is also reflected in the show ip route output.

XE1 show ip route 192.0.2.0 (Verification)
XE1#show ip route 192.0.2.0
Routing entry for 192.0.2.0/24
  Known via "static", distance 200, metric 0
  Routing Descriptor Blocks:
  * 10.1.2.2
      Route metric is 0, traffic share count is 1

For the basic concept of administrative distance, see Administrative Distance (AD).

Verification on Real Devices

In this verification environment, four routers (XE1–XE4) are connected in series via GigabitEthernet. Static routes were configured and connectivity was verified.

XE1 and XE4 are each at the end of a segment, with no forwarding destination other than the opposite direction, so only a default route is configured on each. The relay routers XE2 and XE3 each configure a route to the opposite-side segment they are not directly connected to. XE1 and XE2 are configured using the outgoing-interface format for the reason described above.

RouterStatic Route Configured
XE10.0.0.0/0 via GigabitEthernet1 10.1.2.2 (default route, outgoing interface specified)
XE210.3.4.0/24 via GigabitEthernet2 10.2.3.3 (outgoing interface specified)
XE310.1.2.0/24 via 10.2.3.2
XE40.0.0.0/0 via 10.3.4.3 (default route)

Routing Table Before Configuring the Static Route

Before configuring the static route, each router’s routing table only contains routes for directly connected segments — there is no route information for non-adjacent segments.

XE1 show ip route (Before)
XE1#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, m - OMP
       n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       H - NHRP, G - NHRP registered, g - NHRP registration summary
       o - ODR, P - periodic downloaded static route, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR
       & - replicated local route overrides by connected

Gateway of last resort is not set

      10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C        10.1.2.0/24 is directly connected, GigabitEthernet1
L        10.1.2.1/32 is directly connected, GigabitEthernet1
XE2 show ip route (Before)
XE2#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, m - OMP
       n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       H - NHRP, G - NHRP registered, g - NHRP registration summary
       o - ODR, P - periodic downloaded static route, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR
       & - replicated local route overrides by connected

Gateway of last resort is not set

      10.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
C        10.1.2.0/24 is directly connected, GigabitEthernet1
L        10.1.2.2/32 is directly connected, GigabitEthernet1
C        10.2.3.0/24 is directly connected, GigabitEthernet2
L        10.2.3.2/32 is directly connected, GigabitEthernet2
XE3 show ip route (Before)
XE3#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, m - OMP
       n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       H - NHRP, G - NHRP registered, g - NHRP registration summary
       o - ODR, P - periodic downloaded static route, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR
       & - replicated local route overrides by connected

Gateway of last resort is not set

      10.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
C        10.2.3.0/24 is directly connected, GigabitEthernet1
L        10.2.3.3/32 is directly connected, GigabitEthernet1
C        10.3.4.0/24 is directly connected, GigabitEthernet2
L        10.3.4.3/32 is directly connected, GigabitEthernet2
XE4 show ip route (Before)
XE4#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, m - OMP
       n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       H - NHRP, G - NHRP registered, g - NHRP registration summary
       o - ODR, P - periodic downloaded static route, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR
       & - replicated local route overrides by connected

Gateway of last resort is not set

      10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C        10.3.4.0/24 is directly connected, GigabitEthernet1
L        10.3.4.4/32 is directly connected, GigabitEthernet1

In every case, “Gateway of last resort is not set”, showing that no route information exists other than directly connected routes (C/L).

Example: Outgoing Interface Configuration (XE1)

This configures a default route on XE1 with an outgoing interface specified.

XE1 Static Route (Outgoing Interface) Config
ip route 0.0.0.0 0.0.0.0 GigabitEthernet1 10.1.2.2
XE1 Static Route Configuration Example (Outgoing Interface)
XE1#config term
Enter configuration commands, one per line.  End with CNTL/Z.
XE1(config)#ip route 0.0.0.0 0.0.0.0 GigabitEthernet1 10.1.2.2
XE1(config)#end
XE1#

XE2 is configured the same way with 10.3.4.0/24 GigabitEthernet2 10.2.3.3 (outgoing interface specified), XE3 with next-hop only 10.1.2.0/24 10.2.3.2, and XE4 with a next-hop-only default route 0.0.0.0/0 10.3.4.3.

How It Appears in show running-config

The ip route command is displayed in show running-config exactly as entered, in subnet-mask notation.

XE1 show running-config (ip route)
XE1#show running-config | include ip route
ip route 0.0.0.0 0.0.0.0 GigabitEthernet1 10.1.2.2
XE2 show running-config (ip route)
XE2#show running-config | include ip route
ip route 10.3.4.0 255.255.255.0 GigabitEthernet2 10.2.3.3
XE3 show running-config (ip route)
XE3#show running-config | include ip route
ip route 10.1.2.0 255.255.255.0 10.2.3.2
XE4 show running-config (ip route)
XE4#show running-config | include ip route
ip route 0.0.0.0 0.0.0.0 10.3.4.3

Routing Table After Configuring the Static Route

XE1 show ip route (After)
XE1#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, m - OMP
       n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       H - NHRP, G - NHRP registered, g - NHRP registration summary
       o - ODR, P - periodic downloaded static route, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR
       & - replicated local route overrides by connected

Gateway of last resort is 10.1.2.2 to network 0.0.0.0

S*    0.0.0.0/0 [1/0] via 10.1.2.2, GigabitEthernet1
      10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C        10.1.2.0/24 is directly connected, GigabitEthernet1
L        10.1.2.1/32 is directly connected, GigabitEthernet1
XE2 show ip route (After)
XE2#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, m - OMP
       n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       H - NHRP, G - NHRP registered, g - NHRP registration summary
       o - ODR, P - periodic downloaded static route, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR
       & - replicated local route overrides by connected

Gateway of last resort is not set

      10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
C        10.1.2.0/24 is directly connected, GigabitEthernet1
L        10.1.2.2/32 is directly connected, GigabitEthernet1
C        10.2.3.0/24 is directly connected, GigabitEthernet2
L        10.2.3.2/32 is directly connected, GigabitEthernet2
S        10.3.4.0/24 [1/0] via 10.2.3.3, GigabitEthernet2
XE3 show ip route (After)
XE3#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, m - OMP
       n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       H - NHRP, G - NHRP registered, g - NHRP registration summary
       o - ODR, P - periodic downloaded static route, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR
       & - replicated local route overrides by connected

Gateway of last resort is not set

      10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
S        10.1.2.0/24 [1/0] via 10.2.3.2
C        10.2.3.0/24 is directly connected, GigabitEthernet1
L        10.2.3.3/32 is directly connected, GigabitEthernet1
C        10.3.4.0/24 is directly connected, GigabitEthernet2
L        10.3.4.3/32 is directly connected, GigabitEthernet2
XE4 show ip route (After)
XE4#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, m - OMP
       n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       H - NHRP, G - NHRP registered, g - NHRP registration summary
       o - ODR, P - periodic downloaded static route, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR
       & - replicated local route overrides by connected

Gateway of last resort is 10.3.4.3 to network 0.0.0.0

S*    0.0.0.0/0 [1/0] via 10.3.4.3
      10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C        10.3.4.0/24 is directly connected, GigabitEthernet1
L        10.3.4.4/32 is directly connected, GigabitEthernet1

The routes configured on XE2 and XE3 are now added as S (static route) entries, and on XE1 and XE4 as S* (candidate default, default route) entries.

Connectivity Check

Running ping from XE1 to XE4 (3 hops away) confirms connectivity between the two end segments.

XE1 ping 10.3.4.4
XE1#ping 10.3.4.4
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.3.4.4, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 3/4/5 ms
XE1#

Connectivity in the reverse direction, from XE4 to XE1, was also verified.

XE4 ping 10.1.2.1
XE4#ping 10.1.2.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.2.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/5 ms
XE4#

Both pings return a 100% success rate, confirming that XE1 and XE4, which are not directly connected, can correctly reach each other via the relay routers XE2 and XE3. XE1 and XE4 send packets out using their default route without being aware of the other endpoint, and the relay routers XE2 and XE3 forward them in the correct direction based on their own route information.

Verification Config

Download XE1 config (r1_ipv4-static.en.cfg)

Download XE2 config (r2_ipv4-static.en.cfg)

Download XE3 config (r3_ipv4-static.en.cfg)

Download XE4 config (r4_ipv4-static.en.cfg)

Verification Environment and show Output

Download XE1 show output (r1_ipv4-static_show.en.txt)

Download XE2 show output (r2_ipv4-static_show.en.txt)

Download XE3 show output (r3_ipv4-static_show.en.txt)

Download XE4 show output (r4_ipv4-static_show.en.txt)

Related Articles