Static Routing

What is Static Routing and how to configure it

Static routing is a form of routing that occurs when a router uses a manually configured routing entry, rather than information from dynamic routing traffic. In many cases, static routes are manually configured by a network administrator by adding in entries into a routing table.  

 

  1. Static Routing 
  2. Static Routing on Interface 
  3. Static Routing on VRF 

 

Tested model & firmware version: 

  • Switch model name: 

Accton-AS5712-54X 

  • Community SONiC version: 

202211.2 

 

config route add 

This command is used to add a static route. Note that prefix /nexthop vrf`s and interface name are optional. 

  • Usage 

config route add prefix [vrf <vrf>] <A.B.C.D/M> nexthop [vrf <vrf>] <A.B.C.D> dev <interface name> 

 

config route del 

This command is used to delete a static route. Note that prefix /nexthop vrf`s and interface name are optional. 

  • Usage 

config route del prefix [vrf <vrf>] <A.B.C.D/M> nexthop [vrf <vrf>] <A.B.C.D> dev <interface name> 

 

Static Routing 

Topology: 

 

Procedure: 

Note: Commands are to be executed in sudo mode 

Step 1: Configure ip addresses for interfaces as per topology 

R1: 

root@sonic:/home/admin# config interface ip add Ethernet12 10.1.1.2/24 

  

R2: 

root@sonic:/home/admin# config interface ip add Ethernet12 10.1.1.4/24 

root@sonic:/home/admin# config interface ip add Ethernet6 30.1.1.2/24 

 

R3: 

root@sonic:/home/admin# config interface ip add Ethernet6 30.1.1.4/24 

 

Step 2: configure static route  

R1: 

root@sonic:/home/admin# config route add prefix 30.1.1.0/24 nexthop 10.1.1.4 

R3: 

root@sonic:/home/admin# config route add prefix 10.1.1.0/24 nexthop 30.1.1.2 

 

Result: 

R1: 

root@sonic:/home/admin# show ip route 

Codes: K - kernel route, C - connected, S - static, R - RIP, 

       O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, 

       T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, 

       F - PBR, f - OpenFabric, 

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

 

K>*0.0.0.0/0 [0/0] via 172.26.1.1, eth0, 00:42:51 

C>*10.0.0.4/31 is directly connected, Ethernet2, 00:42:45 

C>*10.0.0.8/31 is directly connected, Ethernet4, 00:42:44 

C>*10.0.0.48/31 is directly connected, Ethernet24, 00:39:32 

C>*10.0.0.96/31 is directly connected, Ethernet48, 00:39:32 

C>*10.0.0.102/31 is directly connected, Ethernet60, 00:39:32 

C>*10.1.0.1/32 is directly connected, Loopback0, 00:42:44 

C>*10.1.1.0/24 is directly connected, Ethernet12, 00:03:14 

S>*30.1.1.0/24 [1/0] via 10.1.1.4, Ethernet12, 00:00:05 

C>*172.26.1.0/24 is directly connected, eth0, 00:42:51 

 

root@sonic:/home/admin# 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 

root@sonic:/home/admin# 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: 

root@sonic:/home/admin# show ip route 

Codes: K - kernel route, C - connected, S - static, R - RIP, 

       O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, 

       T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, 

       F - PBR, f - OpenFabric, 

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

 

K>*0.0.0.0/0 [0/0] via 172.26.1.1, eth0, 17:24:28 

C>*10.0.0.8/31 is directly connected, Ethernet4, 02:22:00 

C>*10.1.0.1/32 is directly connected, Loopback0, 17:24:28 

S>*10.1.1.0/24 [1/0] via 30.1.1.2, Ethernet6, 00:15:54 

C>*30.1.1.0/24 is directly connected, Ethernet6, 02:18:45 

C>*172.26.1.0/24 is directly connected, eth0, 17:24:28 

 

root@sonic:/home/admin# 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 

root@sonic:/home/admin# 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 

 

 

 

Static Routing on Interface 

Topology: 

 

Procedure: 

Note: Commands are to be executed in sudo mode 

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

R1: 

Configure ip address to Ethernet12 

root@sonic:/home/admin# config interface ip add Ethernet12 10.1.1.2/24 

 

Configure ip address to loopback1 

root@sonic:/home/admin# config interface ip add Loopback1 1.1.1.1/32 

R2: 

Configure ip address to Ethernet12 and Ethernet6 

root@sonic:/home/admin# config interface ip add Ethernet12 10.1.1.4/24 

root@sonic:/home/admin# config interface ip add Ethernet6 30.1.1.2/24 

 

R3: 

Configure ip address to Ethernet6 

root@sonic:/home/admin# config interface ip add Ethernet6 30.1.1.4/24 

 

Configure ip address to loopback1 

root@sonic:/home/admin# config interface ip add Loopback1 2.2.2.2/32 

 

Step 2: configure static route on interfaces 

R1: 

root@sonic:/home/admin# config route add prefix 30.1.1.0/24 nexthop dev Ethernet12 

root@sonic:/home/admin# config route add prefix 2.2.2.2/32 nexthop dev Ethernet12 

 

R2: 

root@sonic:/home/admin# config route add prefix 1.1.1.1/32 nexthop dev Ethernet12 

root@sonic:/home/admin# config route add prefix 2.2.2.2/32 nexthop dev Ethernet6 

 

R3: 

root@sonic:/home/admin# config route add prefix 10.1.1.0/24 nexthop dev Ethernet6 

root@sonic:/home/admin# config route add prefix 1.1.1.1/32 nexthop dev Ethernet6 

 

Result: 

R1: 

root@sonic:/home/admin# show ip route 

Codes: K - kernel route, C - connected, S - static, R - RIP, 

       O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, 

       T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, 

       F - PBR, f - OpenFabric, 

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

  

K>*0.0.0.0/0 [0/0] via 172.26.1.1, eth0, 01:22:08 

C>*1.1.1.1/32 is directly connected, Loopback1, 00:55:33 

S>*2.2.2.2/32 [1/0] is directly connected, Ethernet12, 00:50:51 

C>*10.0.0.4/31 is directly connected, Ethernet2, 01:22:03 

C>*10.0.0.8/31 is directly connected, Ethernet4, 01:22:01 

C>*10.0.0.48/31 is directly connected, Ethernet24, 01:22:03 

C>*10.0.0.96/31 is directly connected, Ethernet48, 01:22:02 

C>*10.0.0.102/31 is directly connected, Ethernet60, 01:22:02 

C>*10.1.0.1/32 is directly connected, Loopback0, 01:22:02 

S>*30.1.1.0/24 [1/0] via 10.1.1.4, Ethernet12, 00:00:05 

C>*10.1.1.0/24 is directly connected, Ethernet12, 00:54:51 

C>*172.26.1.0/24 is directly connected, eth0, 01:22:08 

root@sonic:/home/admin# 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: 

root@sonic:/home/admin# show ip route 

Codes: K - kernel route, C - connected, S - static, R - RIP, 

       O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, 

       T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, 

       F - PBR, f - OpenFabric, 

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

  

K>*0.0.0.0/0 [0/0] via 172.26.1.1, eth0, 01:09:32 

S>*1.1.1.1/32 [1/0] is directly connected, Ethernet12, 00:37:17 

S>*2.2.2.2/32 [1/0] is directly connected, Ethernet6, 00:37:35 

C>*10.0.0.8/31 is directly connected, Ethernet4, 01:09:29 

C>*10.0.0.48/31 is directly connected, Ethernet24, 01:09:22 

C>*10.0.0.96/31 is directly connected, Ethernet48, 01:09:22 

C>*10.0.0.102/31 is directly connected, Ethernet60, 01:09:22 

C>*10.1.0.1/32 is directly connected, Loopback0, 01:09:28 

C>*10.1.1.0/24 is directly connected, Ethernet12, 00:41:00 

C>*30.1.1.0/24 is directly connected, Ethernet6, 00:40:15 

C>*172.26.1.0/24 is directly connected, eth0, 01:09:32 

 

R3: 

root@sonic:/home/admin# show ip route 

Codes: K - kernel route, C - connected, S - static, R - RIP, 

       O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, 

       T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, 

       F - PBR, f - OpenFabric, 

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

  

K>*0.0.0.0/0 [0/0] via 172.26.1.1, eth0, 01:21:17 

S>*1.1.1.1/32 [1/0] is directly connected, Ethernet6, 00:48:33 

C>*2.2.2.2/32 is directly connected, Loopback1, 00:51:19 

C>*10.1.0.1/32 is directly connected, Loopback0, 01:21:14 

C>*30.1.1.0/24 is directly connected, Ethernet6, 00:50:49 

C>*172.26.1.0/24 is directly connected, eth0, 01:21:17 

S>*10.1.1.0/24 [1/0] via 30.1.1.2, Ethernet6, 00:15:54 

C>*192.168.10.0/24 is directly connected, Ethernet50, 01:20:59 

root@sonic:/home/admin# 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: 

Note: Commands are to be executed in sudo mode 

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

R1: 

Configure ip address to Ethernet12 

root@sonic:/home/admin# config interface ip add Ethernet12 10.1.1.2/24 

 

Configure ip address to loopback1 

root@sonic:/home/admin# config interface ip add Loopback1 1.1.1.1/32 

 

 

R3: 

Configure ip address to Ethernet6 

root@sonic:/home/admin# config interface ip add Ethernet6 30.1.1.4/24 

 

 

Configure ip address to loopback1 

root@sonic:/home/admin# config interface ip add Loopback1 2.2.2.2/32 

 

 

Step 2: Create vrf on R2 

root@sonic:/home/admin# Config vrf add Vrf_1 

 

  

Step 3: Bind vrf to interfaces on R2 

root@sonic:/home/admin# Config interface vrf bind Ethernet6 Vrf_1 

root@sonic:/home/admin# Config interface vrf bind Ethernet12 Vrf_1 

 

 

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

R2: 

root@sonic:/home/admin# config interface ip add Ethernet12 10.1.1.4/24 

root@sonic:/home/admin# config interface ip add Ethernet6 30.1.1.2/24 

 

 

Step 5: Configure static route on R1 and R3 

R1: 

root@sonic:/home/admin# config route add prefix 2.2.2.2/32 nexthop 10.1.1.4 

root@sonic:/home/admin# Config route add prefix 30.1.1.0/24 nexthop 10.1.1.4 

 

  

R3: 

root@sonic:/home/admin# config route add prefix 1.1.1.1/32 nexthop 30.1.1.2 

root@sonic:/home/admin# Config route add prefix 10.1.1.0/24 nexthop 30.1.1.2 

 

 

Step 6: Configure static route on vrf in R2 

root@sonic:/home/admin# config route add prefix vrf Vrf_1 2.2.2.2/32 nexthop 30.1.1.4 

root@sonic:/home/admin# config route add prefix vrf Vrf_1 1.1.1.1/32 nexthop 10.1.1.2 

 

 

Result 

R1: 

root@sonic:/home/admin# show ip route 

Codes: K - kernel route, C - connected, S - static, R - RIP, 

       O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, 

       T - Table, v - VNC, V - VNC-Direct, A - Babel, F - PBR, 

       f - OpenFabric, 

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

       t - trapped, o - offload failure 

  

K>* 0.0.0.0/0 [0/0] via 172.26.1.1, eth0, 00:01:48 

C>* 1.1.1.1/32 is directly connected, Loopback1, 00:02:44 

S>* 2.2.2.2/32 [1/0] via 10.1.1.4, Ethernet12, weight 1, 00:01:13 

C>* 10.0.0.4/31 is directly connected, Ethernet2, 00:18:41 

C>* 10.0.0.8/31 is directly connected, Ethernet4, 00:18:40 

C>* 10.0.0.48/31 is directly connected, Ethernet24, 00:18:40 

C>* 10.0.0.96/31 is directly connected, Ethernet48, 00:18:40 

C>* 10.0.0.102/31 is directly connected, Ethernet60, 00:18:40 

C>* 10.1.0.1/32 is directly connected, Loopback0, 00:18:40 

C>* 10.1.1.0/24 is directly connected, Ethernet12, 00:02:56 

S>* 30.1.1.0/24 [1/0] via 10.1.1.4, Ethernet12, weight 1, 00:00:05 

C>* 172.26.1.0/24 is directly connected, eth0, 00:02:02 

root@sonic:/home/admin# 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: 

Verify the routes on vrf routing table 

root@sonic:/home/admin# show ip route vrf Vrf_1 

: 

Codes: K - kernel route, C - connected, S - static, R - RIP, 

       O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, 

       T - Table, v - VNC, V - VNC-Direct, A - Babel, F - PBR, 

       f - OpenFabric, 

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

       t - trapped, o - offload failure 

  

VRF Vrf_1: 

S>* 1.1.1.1/32 [1/0] via 10.1.1.2, Ethernet12, weight 1, 00:00:11 

S>* 2.2.2.2/32 [1/0] via 30.1.1.4, Ethernet6, weight 1, 00:28:47 

C>* 10.1.1.0/24 is directly connected, Ethernet12, 00:02:15 

C>*30.1.1.0/24 is directly connected, Ethernet6, 01:01:59 

   

root@sonic:/home/admin# ping -I Vrf_1 2.2.2.2 

ping: Warning: source address might be selected on device other than: Vrf_1 

PING 2.2.2.2 (2.2.2.2) from 20.1.1.1 Vrf_2: 56(84) bytes of data. 

64 bytes from 2.2.2.2: icmp_seq=1 ttl=64 time=0.255 ms 

64 bytes from 2.2.2.2: icmp_seq=2 ttl=64 time=0.284 ms 

 

 

 

R3: 

root@sonic:/home/admin# show ip route 

Codes: K - kernel route, C - connected, S - static, R - RIP, 

       O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP, 

       T - Table, v - VNC, V - VNC-Direct, A - Babel, F - PBR, 

       f - OpenFabric, 

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

       t - trapped, o - offload failure 

  

K>* 0.0.0.0/0 [0/0] via 172.26.1.1, eth0, 01:32:46 

S> 1.1.1.1/32 [1/0] via 30.1.1.2, Ethernet6, weight 1, 00:27:17 

C>* 2.2.2.2/32 is directly connected, Loopback1, 01:31:28 

C>* 10.1.0.1/32 is directly connected, Loopback0, 01:38:24 

S> 10.1.1.0/24 [1/0] via 30.1.1.2, Ethernet6, weight 1, 00:27:08 

C>* 30.1.1.0/24 is directly connected, Ethernet6, 01:31:40 

C>* 172.26.1.0/24 is directly connected, eth0, 01:33:05 

C>* 192.168.10.0/24 is directly connected, Ethernet50, 01:38:10 

 

root@sonic:/home/admin# 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 

 

 
    • Related Articles

    • How to configure Sub Interface

      Sub interfaces divide the parent interface into two or more virtual interfaces on which you can assign unique Layer 3 parameters such as IP addresses and dynamic routing protocols. The IP address for each sub interface should be in a different subnet ...
    • Where can I get the Configuration guide for SONiC

      Attached document provides the details about the Configuration of SONiC
    • Management Interface Configuration (SONiC)

      Configure the management interface (eth0) for network administration in SONiC. Default Configuration: By default, eth0 uses DHCP to dynamically obtain an IP address from a DHCP server. Static IP Configuration: Command Line: sudo config interface ip ...
    • Username and Password Configuration in SONiC

      Adding and Managing Users To configure usernames and passwords in SONiC, follow these steps: Add a New User To add a new user, use the command: sudo useradd <new-username> Example: admin@sonic:~$ sudo useradd new-username Change User Password To set ...
    • What are the Basic Configuration commands ?

      config hostname: Configures the system hostname. config platform firmware install: Installs platform component firmware. config platform firmware update: Updates a platform component firmware from the current/next SONiC image. config set_timezone: ...