How to add static route globally and under the vrf

How to add static route globally and under the vrf

Static Routing  

Static routing is a method where routes are manually configured in the routing table by a network administrator, as opposed to being learned dynamically via routing protocols. It is commonly used in simple or controlled environments where routes rarely change. 

 

  • Static Routing 

  • Static Routing on Interface 

  • Static Routing on VRF 

 

Prerequisites 

Hardware: 

  • Switches or routers that support VLANs 
    (e.g., edgecore, ufispace) 

Software: 

  • Network operating systems that support VLAN configuration 
    (e.g., SONiC-OS-4.4.0-Enterprise_Base, SONiC-OS-4.4.2-Enterprise_Base) 

Access: 

  • Administrative or privileged CLI access 

 

Commands: 

config static route add: 

  • This command is used to add a static route.  

Syntax: 

ip route <Destination-IP/mask> <nexthop-IP/interface> <route-preference/nexthop-vrf/tag> 

 

config static route del: 

  • This command is used to delete a static route.  

Syntax 

 

Scenario_01: Static routing 

Topology: 

 

 

Procedure: 

Step 1: Configure ip addresses for interfaces as per topology 

R1: 

  interafce Ethernet12  

ip address 10.1.1.2/24 

  

R2: 

 interface Ethernet 12  

Ip address 10.1.1.4/24 

 

interface Ethernet6  

ip address 30.1.1.2/24 


R3: 

 interface Ethernet6  

ip address 30.1.1.4/24 


Step 2: configure static route  

R1: 

sonic(config)# ip route 30.1.1.0/24 10.1.1.4 

R3: 

sonic(config)# ip route 10.1.1.0/24 30.1.1.2 

 

Validation: 

Check the destination IP address in routing table 

R1: 

  sonic# show ip route 

Codes:  K - kernel route, C - connected, S - static, B - BGP, O - OSPF 

        > - selected route, * - FIB route, q - queued route, r - rejected route 

       Destination        Gateway                                                                    Dist/Metric   Last Update 

-------------------------------------------------------------------------------------------------------------------------------- 

K>*   0.0.0.0/0          via 172.27.1.1                  Management0                                0/202         01:31:20 ago 

C>*   10.1.1.0/24       Direct                          Ethernet12                                 0/0           00:00:43 ago 

C>*   172.27.1.0/24      Direct                          Management0                                0/0           01:31:20 ago 

S>*   30.1.1.0/24       via 10.1.1.4                   Ethernet12                                 1/0           00:00:04 ago 

 

 sonic# ping 30.1.1.4 

PING 30.1.1.4 (30.1.1.4) 56(84) bytes of data. 

64 bytes from 30.1.1.4: icmp_seq=1 ttl=63 time=0.315 ms 

64 bytes from 30.1.1.4: icmp_seq=2 ttl=63 time=0.309 ms 

 

sonic# traceroute 30.1.1.4 

traceroute to 30.1.1.4 (30.1.1.4), 30 hops max, 60 byte packets 

 1  10.1.1.4 (10.1.1.4)  0.352 ms  0.316 ms  0.344 ms 

 2  30.1.1.4 (30.1.1.4)  0.312 ms  0.444 ms  0.510 ms 

 

 

R3: 

 sonic# show ip route 

Codes:  K - kernel route, C - connected, S - static, B - BGP, O - OSPF 

        > - selected route, * - FIB route, q - queued route, r - rejected route 

       Destination        Gateway                                                                    Dist/Metric   Last Update 

-------------------------------------------------------------------------------------------------------------------------------- 

K>*   0.0.0.0/0          via 172.27.1.1                  Management0                                0/202         01:31:20 ago 

C>*   30.1.1.0/24       Direct                          Ethernet6                                  0/0           00:00:43 ago 

C>*   172.27.1.0/24      Direct                          Management0                                0/0           01:31:20 ago 

S>*   10.1.1.0/24       via 30.1.1.2                   Ethernet6                                 1/0           00:00:04 ago 

 

 

sonic# ping 10.1.1.2 

PING 10.1.1.2 (10.1.1.2) 56(84) bytes of data. 

64 bytes from 10.1.1.2: icmp_seq=1 ttl=63 time=0.339 ms 

64 bytes from 10.1.1.2: icmp_seq=2 ttl=63 time=0.348 ms 

 

sonic# traceroute 10.1.1.2 

traceroute to 10.1.1.2 (10.1.1.2), 30 hops max, 60 byte packets 

 1  30.1.1.2 (30.1.1.2)  0.358 ms  0.309 ms  0.285 ms 

 2  10.1.1.2 (10.1.1.2)  0.440 ms  0.394 ms  0.369 ms 

 

 

Scenario_02: Static Routing on Interface 

Topology: 


 

Procedure: 

Step 1: Configure ip addresses for interfaces and loopback as per topology 

R1: 

  interafce Ethernet12  

ip address 10.1.1.2/24 

 

interface Loopback 1 

ip address 1.1.1.1/32 


R2: 

 interface Ethernet 12  

Ip address 10.1.1.4/24 

 

interface Ethernet6  

ip address 30.1.1.2/24 


R3: 

 interface Ethernet6  

ip address 30.1.1.4/24 

 

interface Loopback 1 

Ip address 2.2.2.2/32 


Step 2: configure static route  

R1: 

sonic(config)# ip route 30.1.1.0/24 interface Ethernet 12 

sonic(config)# ip route 2.2.2.2/32 interface Ethernet 12 


R3: 

 sonic(config)# ip route 10.1.1.0/24 interface Ethernet6 

sonic(config)# ip route 1.1.1.1/32 interface Ethernet6 


R2: 

 sonic(config)# ip route 1.1.1.1/32 interface Ethernet12 

sonic(config)# ip route 2.2.2.2/32 interface Ethernet6 


Validation: 

R1 

 sonic# show ip route 

Codes:  K - kernel route, C - connected, S - static, B - BGP, O - OSPF 

        > - selected route, * - FIB route, q - queued route, r - rejected route 

       Destination        Gateway                                                                    Dist/Metric   Last Update 

-------------------------------------------------------------------------------------------------------------------------------- 

K>*   0.0.0.0/0          via 172.27.1.1                  Management0                                0/202         01:48:19 ago 

C>*   1.1.1.1/32         Direct                          Loopback1                                  0/0           00:04:10 ago 

C>*   10.1.1.0/24       Direct                          Ethernet12                                 0/0           00:17:42 ago 

C>*   172.27.1.0/24      Direct                          Management0                                0/0           01:48:19  

S>*   30.1.1.0/24       Direct                          Ethernet12                                 1/0           00:00:10 ago 

S>*   2.2.2.2/32       Direct                          Ethernet12                                 1/0           00:00:20 ago 

 

sonic# ping 2.2.2.2 

PING 2.2.2.2 (2.2.2.2) 56(84) bytes of data. 

64 bytes from 2.2.2.2: icmp_seq=1 ttl=63 time=0.273 ms 

64 bytes from 2.2.2.2: icmp_seq=2 ttl=63 time=0.273 ms 

 

R2: 

 sonic# show ip route 

Codes:  K - kernel route, C - connected, S - static, B - BGP, O - OSPF 

        > - selected route, * - FIB route, q - queued route, r - rejected route 

       Destination        Gateway                                                                    Dist/Metric   Last Update 

-------------------------------------------------------------------------------------------------------------------------------- 

K>*   0.0.0.0/0          via 172.27.1.1                  Management0                                0/202         01:48:19 ago 

C>*   10.1.1.0/24          Direct                        Ethernet12                                  0/0           00:04:10 ago 

C>*   30.1.1.0/24        Direct                          Ethernet6                                  0/0           00:17:42 ago 

C>*   172.27.1.0/24      Direct                          Management0                                0/0           01:48:19  

S>*   2.2.2.2/32       Direct                          Ethernet6                                  1/0           00:00:40 ago 

S>*   1.1.1.1/32       Direct                          Ethernet12                                  1/0           00:00:38 ago 


R3 

 sonic# show ip route 

Codes:  K - kernel route, C - connected, S - static, B - BGP, O - OSPF 

        > - selected route, * - FIB route, q - queued route, r - rejected route 

       Destination        Gateway                                                                    Dist/Metric   Last Update 

-------------------------------------------------------------------------------------------------------------------------------- 

K>*   0.0.0.0/0          via 172.27.1.1                  Management0                                0/202         01:48:19 ago 

C>*   2.2.2.2/32         Direct                          Loopback1                                  0/0           00:04:10 ago 

C>*   30.1.1.0/24       Direct                          Ethernet6                                  0/0           00:17:42 ago 

C>*   172.27.1.0/24      Direct                          Management0                                0/0           01:48:19  

S>*   10.1.1.0/24       Direct                          Ethernet6                                  1/0           00:00:30 ago 

S>*   1.1.1.1/32       Direct                          Ethernet6                                  1/0           00:00:50 ago 

 

 

sonic# ping 1.1.1.1 

PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data. 

64 bytes from 1.1.1.1: icmp_seq=1 ttl=63 time=0.297 ms 

64 bytes from 1.1.1.1: icmp_seq=2 ttl=63 time=0.304 ms 

64 bytes from 1.1.1.1: icmp_seq=3 ttl=63 time=0.297 ms 

 

Static Routing on VRF 

Topology: 


 

Procedure: 

Step 1: Configure ip addresses for interfaces and loopback on R1 and R3 as per topology 

R1: 

Configure ip address to Ethernet12 

 interafce Ethernet12  

ip address 10.1.1.2/24 

Configure ip address to loopback1 

interface Loopback1  

ip address 1.1.1.1/32 

 

R3: 

Configure ip address to Ethernet6 

 interface Ethernet6  

ip address 30.1.1.4/24 

Configure ip address to loopback1 

 interface Loopback1  

ip address 2.2.2.2/32 


Step 2: Create vrf on R2 

  ip vrf Vrf_1 

Step 3: Bind vrf to interfaces on R2 

interface Ethernet6 

ip vrf forwarding Vrf_1 

 

interface Ethernet12 

ip vrf forwarding Vrf_1 

 

Step 4: Configure ip addresses to interface on R2 as per topology 

R2: 

 interface Ethernet12  

ip address 10.1.1.4/24 

 

interface Ethernet6  

ip address 30.1.1.2/24 

Step 5: Configure static route on R1 and R3 

R1: 

 sonic(config)# ip route 30.1.1.0/24 10.1.1.4 

sonic(config)# ip route 2.2.2.2/32 10.1.1.4 


R3: 

 sonic(config)# ip route 10.1.1.0/24 30.1.1.2 

sonic(config)# ip route 1.1.1.1/32 30.1.1.2 


Step 6: Configure static route on vrf in R2 

 

 sonic(config)# ip route vrf Vrf_1 2.2.2.2/32 30.1.1.4 

Result : ping R1 loopback IP address to R3 Loopback IP address. 

R1: 

 sonic# ping 2.2.2.2 

PING 2.2.2.2 (2.2.2.2) 56(84) bytes of data. 

64 bytes from 2.2.2.2: icmp_seq=1 ttl=63 time=0.273 ms 

64 bytes from 2.2.2.2: icmp_seq=2 ttl=63 time=0.273 ms 

 

 

 

    • Related Articles

    • How to Configure Basic VRF Management

      VRF Management Objective This document explains how to configure Basic VRF (Virtual Routing and Forwarding) Management on SONiC-OS-4.4.2-Enterprise_Base. Management VRF provides a separate routing table specifically for out-of-band management ...
    • How to configure BGP

      BGP (Border Gateway Protocol) Objective BGP (Border Gateway Protocol) is the protocol that enables the global routing system of the internet. It manages how packets get routed from network to network by exchanging routing and reachability information ...
    • How to Configure eBGP and iBGP with Peer-Groups

      BGP (Border Gateway Protocol) with peer-group configurations Objective This document explains how to configure eBGP (External BGP) and iBGP (Internal BGP) using peer-groups on routers. Peer-groups help simplify BGP configuration by grouping neighbors ...
    • How to config bfd

      BFD (Bidirectional Forwarding Detection): Bidirectional Forwarding Detection (BFD) is a lightweight network protocol designed to detect link failures rapidly between two forwarding engines (e.g., routers or switches). BFD operates independently of ...
    • How to enable sflow server

      SFLOW (Sampled Flow): SFlow is a sampling technology invented by InMon and has become an industry standard defined in RFC 3176. It is a Network monitoring technology that collects and analyzes traffic statistics based on packet sampling. Tested model ...