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

Configuring an IPv4 Static Route on Cisco IOS XR

Table of Contents

How to Configure a Static Route on Cisco IOS XR

This is the command for configuring a static route on Cisco IOS XR. Run it under the address-family ipv4 unicast submode of the router static configuration mode.

Like the ipv4 address command, IOS XR static routes accept either prefix-length notation or subnet-mask notation.

IOS XR Static Route Configuration (Prefix-Length Notation)
router static
 address-family ipv4 unicast
  [DESTINATION_NETWORK]/[PREFIX_LENGTH] [NEXT_HOP_IP_ADDRESS]
IOS XR Static Route Configuration (Subnet-Mask Notation)
router static
 address-family ipv4 unicast
  [DESTINATION_NETWORK] [SUBNET_MASK] [NEXT_HOP_IP_ADDRESS]
FieldValue
[DESTINATION_NETWORK]The destination network address of the static route (0.0.0.0 for a default route)
[PREFIX_LENGTH]The prefix length in CIDR notation (e.g. /24)
[SUBNET_MASK]The subnet mask in dotted-decimal notation (e.g. 255.255.255.0)
[NEXT_HOP_IP_ADDRESS]The IP address of the adjacent router to which the packet is forwarded

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

As with the ipv4 address command, regardless of which notation you use, show running-config always normalizes and stores it in prefix-length notation (note that this is the opposite of Cisco IOS(-XE) static routes, which are always normalized to subnet-mask notation).

Specifying an Outgoing Interface

Instead of, or in addition to, the next-hop IP address, you can also specify an outgoing interface.

IOS XR Static Route Configuration (Outgoing Interface + Next Hop)
router static
 address-family ipv4 unicast
  [DESTINATION_NETWORK]/[PREFIX_LENGTH] [INTERFACE_NAME] [NEXT_HOP_IP_ADDRESS]
FieldValue
[INTERFACE_NAME]The interface name from which the packet is sent (e.g. GigabitEthernet0/0/0/0)

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

XR1 Outgoing Interface + Next Hop Example (Verification)
RP/0/RP0/CPU0:XR1(config-static-afi)#192.0.2.0/24 GigabitEthernet0/0/0/0 10.1.2.2
RP/0/RP0/CPU0:XR1#show running-config router static
router static
 address-family ipv4 unicast
  0.0.0.0/0 10.1.2.2
  192.0.2.0/24 GigabitEthernet0/0/0/0 10.1.2.2
 !
!
The biggest advantage of specifying an outgoing interface is that the static route itself is automatically removed from the routing table when that interface goes down. When only a next-hop IP address is specified, reachability to the route is determined indirectly through a recursive lookup — so even if the link itself is actually down, the static route can remain valid as long as a route to the next hop is still learned via some other path. Configuring the outgoing interface wherever possible is recommended.

The “Verification on Real Hardware” section below configures XR1 and XR2’s static routes using the outgoing-interface notation.

Specifying Administrative Distance (Distance)

Adding a numeric value after the next-hop IP address lets you explicitly set the administrative distance (AD) for that static route (the default is 1).

IOS XR Static Route Configuration (Distance)
router static
 address-family ipv4 unicast
  [DESTINATION_NETWORK]/[PREFIX_LENGTH] [NEXT_HOP_IP_ADDRESS] [Distance]
FieldValue
[Distance]The administrative distance value, in the range 1-254

We also verified this on XR1, setting a distance of 200 for 192.0.2.0/24.

XR1 Distance (Verification) Config
router static
 address-family ipv4 unicast
  192.0.2.0/24 10.1.2.2 200
XR1 Distance Configuration Example (Verification)
RP/0/RP0/CPU0:XR1#configure
RP/0/RP0/CPU0:XR1(config)#router static
RP/0/RP0/CPU0:XR1(config-static)#address-family ipv4 unicast
RP/0/RP0/CPU0:XR1(config-static-afi)#192.0.2.0/24 10.1.2.2 200
RP/0/RP0/CPU0:XR1(config-static-afi)#commit
Sun Aug 16 10:19:34.035 UTC
RP/0/RP0/CPU0:XR1(config-static-afi)#end
RP/0/RP0/CPU0:XR1#

The specified value is reflected in the show route output.

XR1 show route 192.0.2.0/24 (Verification)
RP/0/RP0/CPU0:XR1#show route 192.0.2.0/24

Routing entry for 192.0.2.0/24
  Known via "static", distance 200, metric 0
  Installed Aug 16 10:19:34.271 for 00:00:22
  Routing Descriptor Blocks
    10.1.2.2
      Route metric is 0
  No advertising protos.

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

Verification on Real Hardware

We set up a test environment with four routers (XR1-XR4) connected in a chain via GigabitEthernet, configured static routes, and verified connectivity.

XR1 and XR4 sit at the ends of the chain and have no destination other than the opposite direction, so each is configured with only a default route. XR2 and XR3, acting as relays, each have a dedicated route to the segment on the far side that they are not directly connected to. For the reasons described above, XR1 and XR2 are configured with an outgoing interface specified.

RouterStatic Route to Configure
XR10.0.0.0/0 via GigabitEthernet0/0/0/0 10.1.2.2 (default route, with outgoing interface)
XR210.3.4.0/24 via GigabitEthernet0/0/0/1 10.2.3.3 (with outgoing interface)
XR310.1.2.0/24 via 10.2.3.2
XR40.0.0.0/0 via 10.3.4.3 (default route)

Routing Table Before Configuring Static Routes

Before configuring static routes, each router’s routing table has only routes to its directly connected segments and no route information for non-adjacent segments.

XR1 show route (Before)
RP/0/RP0/CPU0:XR1#show route

Codes: C - connected, S - static, R - RIP, B - BGP, (>) - Diversion path
       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, E - EGP
       i - ISIS, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, su - IS-IS summary null, * - candidate default
       U - per-user static route, o - ODR, L - local, G  - DAGR, l - LISP
       A - access/subscriber, a - Application route
       M - mobile route, r - RPL, t - Traffic Engineering, (!) - FRR Backup path
       s - local SRv6 route, z - local IID route

Gateway of last resort is not set

C    10.1.2.0/24 is directly connected, 00:07:14, GigabitEthernet0/0/0/0
L    10.1.2.1/32 is directly connected, 00:07:14, GigabitEthernet0/0/0/0
RP/0/RP0/CPU0:XR1#
XR2 show route (Before)
RP/0/RP0/CPU0:XR2#show route

Codes: C - connected, S - static, R - RIP, B - BGP, (>) - Diversion path
       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, E - EGP
       i - ISIS, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, su - IS-IS summary null, * - candidate default
       U - per-user static route, o - ODR, L - local, G  - DAGR, l - LISP
       A - access/subscriber, a - Application route
       M - mobile route, r - RPL, t - Traffic Engineering, (!) - FRR Backup path
       s - local SRv6 route, z - local IID route

Gateway of last resort is not set

C    10.1.2.0/24 is directly connected, 00:06:38, GigabitEthernet0/0/0/0
L    10.1.2.2/32 is directly connected, 00:06:38, GigabitEthernet0/0/0/0
C    10.2.3.0/24 is directly connected, 00:06:38, GigabitEthernet0/0/0/1
L    10.2.3.2/32 is directly connected, 00:06:38, GigabitEthernet0/0/0/1
RP/0/RP0/CPU0:XR2#
XR3 show route (Before)
RP/0/RP0/CPU0:XR3#show route

Codes: C - connected, S - static, R - RIP, B - BGP, (>) - Diversion path
       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, E - EGP
       i - ISIS, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, su - IS-IS summary null, * - candidate default
       U - per-user static route, o - ODR, L - local, G  - DAGR, l - LISP
       A - access/subscriber, a - Application route
       M - mobile route, r - RPL, t - Traffic Engineering, (!) - FRR Backup path
       s - local SRv6 route, z - local IID route

Gateway of last resort is not set

C    10.2.3.0/24 is directly connected, 00:05:59, GigabitEthernet0/0/0/0
L    10.2.3.3/32 is directly connected, 00:05:59, GigabitEthernet0/0/0/0
C    10.3.4.0/24 is directly connected, 00:05:59, GigabitEthernet0/0/0/1
L    10.3.4.3/32 is directly connected, 00:05:59, GigabitEthernet0/0/0/1
RP/0/RP0/CPU0:XR3#
XR4 show route (Before)
RP/0/RP0/CPU0:XR4#show route

Codes: C - connected, S - static, R - RIP, B - BGP, (>) - Diversion path
       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, E - EGP
       i - ISIS, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, su - IS-IS summary null, * - candidate default
       U - per-user static route, o - ODR, L - local, G  - DAGR, l - LISP
       A - access/subscriber, a - Application route
       M - mobile route, r - RPL, t - Traffic Engineering, (!) - FRR Backup path
       s - local SRv6 route, z - local IID route

Gateway of last resort is not set

C    10.3.4.0/24 is directly connected, 00:05:20, GigabitEthernet0/0/0/0
L    10.3.4.4/32 is directly connected, 00:05:20, GigabitEthernet0/0/0/0
RP/0/RP0/CPU0:XR4#

Each shows “Gateway of last resort is not set”, confirming there is no route information other than the directly connected routes (C/L).

Example: Prefix-Length Notation + Outgoing Interface (XR1)

On XR1, we configure a default route using prefix-length notation with the outgoing interface specified.

XR1 Static Route (Prefix-Length Notation + Outgoing Interface) Config
router static
 address-family ipv4 unicast
  0.0.0.0/0 GigabitEthernet0/0/0/0 10.1.2.2
XR1 Static Route Configuration (Prefix-Length Notation + Outgoing Interface) Example
RP/0/RP0/CPU0:XR1#configure
RP/0/RP0/CPU0:XR1(config)#router static
RP/0/RP0/CPU0:XR1(config-static)#address-family ipv4 unicast
RP/0/RP0/CPU0:XR1(config-static-afi)#0.0.0.0/0 GigabitEthernet0/0/0/0 10.1.2.2
RP/0/RP0/CPU0:XR1(config-static-afi)#commit
Sun Aug 16 10:25:55.482 UTC
RP/0/RP0/CPU0:XR1(config-static-afi)#end
RP/0/RP0/CPU0:XR1#

Example: Subnet-Mask Notation (XR4)

On XR4, we configure a default route using subnet-mask notation.

XR4 Static Route (Subnet-Mask Notation) Config
router static
 address-family ipv4 unicast
  0.0.0.0 0.0.0.0 10.3.4.3
XR4 Static Route Configuration (Subnet-Mask Notation) Example
RP/0/RP0/CPU0:XR4#configure
RP/0/RP0/CPU0:XR4(config)#router static
RP/0/RP0/CPU0:XR4(config-static)#address-family ipv4 unicast
RP/0/RP0/CPU0:XR4(config-static-afi)#0.0.0.0 0.0.0.0 10.3.4.3
RP/0/RP0/CPU0:XR4(config-static-afi)#commit
Sun Aug 16 10:04:38.964 UTC
RP/0/RP0/CPU0:XR4(config-static-afi)#end
RP/0/RP0/CPU0:XR4#

XR2 is configured the same way with an outgoing interface, using 10.3.4.0/24 GigabitEthernet0/0/0/1 10.2.3.3, while XR3 uses 10.1.2.0/24 10.2.3.2 with only a next hop.

How It Appears in show running-config router static

Regardless of which notation was used to enter it, show running-config router static displays it in the same prefix-length notation.

XR1 show running-config router static
RP/0/RP0/CPU0:XR1#show running-config router static

router static
 address-family ipv4 unicast
  0.0.0.0/0 GigabitEthernet0/0/0/0 10.1.2.2
 !
!

RP/0/RP0/CPU0:XR1#
XR2 show running-config router static
RP/0/RP0/CPU0:XR2#show running-config router static

router static
 address-family ipv4 unicast
  10.3.4.0/24 GigabitEthernet0/0/0/1 10.2.3.3
 !
!

RP/0/RP0/CPU0:XR2#
XR3 show running-config router static
RP/0/RP0/CPU0:XR3#show running-config router static

router static
 address-family ipv4 unicast
  10.1.2.0/24 10.2.3.2
 !
!

RP/0/RP0/CPU0:XR3#
XR4 show running-config router static
RP/0/RP0/CPU0:XR4#show running-config router static

router static
 address-family ipv4 unicast
  0.0.0.0/0 10.3.4.3
 !
!

RP/0/RP0/CPU0:XR4#

XR4 was entered as 0.0.0.0 0.0.0.0 10.3.4.3 (subnet-mask notation), but show running-config shows it normalized to 0.0.0.0/0 (prefix-length notation), the same as XR1.

Routing Table After Configuring Static Routes

XR1 show route (After)
RP/0/RP0/CPU0:XR1#show route

Codes: C - connected, S - static, R - RIP, B - BGP, (>) - Diversion path
       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, E - EGP
       i - ISIS, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, su - IS-IS summary null, * - candidate default
       U - per-user static route, o - ODR, L - local, G  - DAGR, l - LISP
       A - access/subscriber, a - Application route
       M - mobile route, r - RPL, t - Traffic Engineering, (!) - FRR Backup path
       s - local SRv6 route, z - local IID route

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, 00:00:24, GigabitEthernet0/0/0/0
C    10.1.2.0/24 is directly connected, 00:30:13, GigabitEthernet0/0/0/0
L    10.1.2.1/32 is directly connected, 00:30:13, GigabitEthernet0/0/0/0
RP/0/RP0/CPU0:XR1#
XR2 show route (After)
RP/0/RP0/CPU0:XR2#show route

Codes: C - connected, S - static, R - RIP, B - BGP, (>) - Diversion path
       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, E - EGP
       i - ISIS, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, su - IS-IS summary null, * - candidate default
       U - per-user static route, o - ODR, L - local, G  - DAGR, l - LISP
       A - access/subscriber, a - Application route
       M - mobile route, r - RPL, t - Traffic Engineering, (!) - FRR Backup path
       s - local SRv6 route, z - local IID route

Gateway of last resort is not set

C    10.1.2.0/24 is directly connected, 00:31:48, GigabitEthernet0/0/0/0
L    10.1.2.2/32 is directly connected, 00:31:48, GigabitEthernet0/0/0/0
C    10.2.3.0/24 is directly connected, 00:31:48, GigabitEthernet0/0/0/1
L    10.2.3.2/32 is directly connected, 00:31:48, GigabitEthernet0/0/0/1
S    10.3.4.0/24 [1/0] via 10.2.3.3, 00:02:32, GigabitEthernet0/0/0/1
RP/0/RP0/CPU0:XR2#
XR3 show route (After)
RP/0/RP0/CPU0:XR3#show route

Codes: C - connected, S - static, R - RIP, B - BGP, (>) - Diversion path
       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, E - EGP
       i - ISIS, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, su - IS-IS summary null, * - candidate default
       U - per-user static route, o - ODR, L - local, G  - DAGR, l - LISP
       A - access/subscriber, a - Application route
       M - mobile route, r - RPL, t - Traffic Engineering, (!) - FRR Backup path
       s - local SRv6 route, z - local IID route

Gateway of last resort is not set

S    10.1.2.0/24 [1/0] via 10.2.3.2, 00:01:19
C    10.2.3.0/24 is directly connected, 00:08:55, GigabitEthernet0/0/0/0
L    10.2.3.3/32 is directly connected, 00:08:55, GigabitEthernet0/0/0/0
C    10.3.4.0/24 is directly connected, 00:08:55, GigabitEthernet0/0/0/1
L    10.3.4.3/32 is directly connected, 00:08:55, GigabitEthernet0/0/0/1
RP/0/RP0/CPU0:XR3#
XR4 show route (After)
RP/0/RP0/CPU0:XR4#show route

Codes: C - connected, S - static, R - RIP, B - BGP, (>) - Diversion path
       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, E - EGP
       i - ISIS, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, su - IS-IS summary null, * - candidate default
       U - per-user static route, o - ODR, L - local, G  - DAGR, l - LISP
       A - access/subscriber, a - Application route
       M - mobile route, r - RPL, t - Traffic Engineering, (!) - FRR Backup path
       s - local SRv6 route, z - local IID route

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, 00:02:07
C    10.3.4.0/24 is directly connected, 00:08:17, GigabitEthernet0/0/0/0
L    10.3.4.4/32 is directly connected, 00:08:17, GigabitEthernet0/0/0/0
RP/0/RP0/CPU0:XR4#

XR2 and XR3 each have their configured route added as S (static route), while XR1 and XR4 have S* (candidate default, the default route) added.

Connectivity Check

We ran ping from XR1 to XR4 (3 hops away) to verify reachability between the segments at each end.

XR1 ping 10.3.4.4
RP/0/RP0/CPU0:XR1#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 = 7/9/11 ms
RP/0/RP0/CPU0:XR1#

We also verified connectivity in the reverse direction, from XR4 to XR1.

XR4 ping 10.1.2.1
RP/0/RP0/CPU0:XR4#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 = 8/9/12 ms
RP/0/RP0/CPU0:XR4#

Both pings succeeded at a 100% success rate, confirming that XR1 and XR4, which are not directly connected, can reach each other correctly via XR2 and XR3 acting as relays. XR1 and XR4 send packets out via their default route without needing to know about the other end, and the route information held by the relaying XR2 and XR3 forwards them in the correct direction.

Verification Configs

Download XR1 config (r1_ipv4-static.cfg)

Download XR2 config (r2_ipv4-static.cfg)

Download XR3 config (r3_ipv4-static.cfg)

Download XR4 config (r4_ipv4-static.cfg)

Test Environment and show Output

Download XR1 show output (r1_ipv4-static_show.txt)

Download XR2 show output (r2_ipv4-static_show.txt)

Download XR3 show output (r3_ipv4-static_show.txt)

Download XR4 show output (r4_ipv4-static_show.txt)

Related Articles