Skip to content
Ask AI

Policy-Based Routing Configuration Guide

Policy-Based Routing (PBR) is a routing mechanism that forwards packets based on custom-defined policies. When packets are routed, they can be matched based on source IP address, destination IP address, IP protocol, source TCP/UDP port number, and destination TCP/UDP port number. For packets that meet the matching conditions, the next hop is set to complete the forwarding control of the packets.

Table 1 Configure Policy-Based Routing

PurposeCommandsDescription
Enter global configuration view.configure terminal-
Create a PBR policy and enter the pbr-map configuration viewpbr-map pbr-map-name seq seq-numsequence number, with a value range of 1 to 700.
Configure PBR policy matching fieldsmatch {dst-ip dip|dst-port dport|ip-protocol {tcp|udp}|src-ip sip|src-port sport}-
Configure PBR policy actionsset {nexthop {A.B.C.D|X:X::X:X}|nexthop-group next-group-name}-
Create a next-hop group and enter the next-hop group configuration viewnexthop-group next-group-name-
Configure the next hopnexthop {A.B.C.D|X:X::X:X}-

Configure interface binding with policy routing

Section titled “Configure interface binding with policy routing”

Table 2 Configure interface binding with policy routing

PurposeCommandsDescription
Enter global configuration viewconfigure terminal-
Enter interface configuration view.interface interface-type interface-nameInterface type: optional ethernet, link-aggregation
Bind PBR policypbr-policy pbr-map-namepbr-map-name: PBR policy name

Table 3 PBR Display and Maintenance

PurposeCommandDescription
Check PBR binding information.show pbr interface [ethernet interface-name|link-aggregation lag-id] [json]-
Check PBR policy information.show pbr map [pbr-map-name|json|detail]-
Check PBR next hop information.show pbr nexthop-groups [next-group-name|json]-
  1. Networking Requirements To achieve flexible scheduling and refined management of traffic, policy routing (PBR) technology needs to be deployed in the network architecture. We now require VM1 to serve as the traffic source, release two streams of traffic externally, configure PBR through the switch, and forward one stream to VM2 and the other stream to VM3 to meet the traffic processing needs in different business scenarios, improve network resource utilization efficiency and business flexibility.
  2. Topology

  1. Procedure

#Configure Interface IP.

sonic# config terminal
sonic(config)# interface ethernet 0/72
sonic(config-if-0/72)# ip address 72.0.0.1/24
sonic(config-if-0/72)# exit
sonic(config)# interface ethernet 0/73
sonic(config-if-0/73)# ip address 73.0.0.1/24
sonic(config-if-0/73)# exit
sonic(config)# interface ethernet 0/74
sonic(config-if-0/74)# ip address 74.0.0.1/24
sonic(config-if-0/74)# exit

#Configure PBR.

sonic# config terminal
sonic(config)# pbr-map test seq 1
sonic(config-pbr-map)# match src-ip 1.0.0.0/24
sonic(config-pbr-map)# set nexthop 73.0.0.2
sonic(config-pbr-map)# exit
sonic(config)# pbr-map test seq 2
sonic(config-pbr-map)# match src-ip 2.0.0.0/24
sonic(config-pbr-map)# set nexthop 74.0.0.2
sonic(config-pbr-map)# exit
sonic(config)# interface ethernet 0/72
sonic(config-if-0/72)# pbr-policy test
sonic(config-if-0/72)# exit
  1. Verify the configuration.

#Check pbr configuration

sonic# show pbr interface
ethernet 0/72(106) with pbr-policy test
Leaf-129# show pbr nexthop-groups
Nexthop-Group: test2 Table: 10001 Valid: 0 Installed: 0
Valid: 0 nexthop 74.0.0.2
Nexthop-Group: test1 Table: 10000 Valid: 0 Installed: 0
Valid: 0 nexthop 73.0.0.2
Leaf-129# show pbr map
pbr-map test valid: no
Seq: 1 rule: 300
Installed: no Reason: Invalid NH
SRC Match: 1.0.0.0/24
nexthop 73.0.0.2
Installed: no Tableid: 10000
Seq: 2 rule: 301
Installed: no Reason: Invalid NH
SRC Match: 2.0.0.0/24
nexthop 74.0.0.2
Installed: no Tableid: 10001

TC2 is configured with HOST1 IP: 73.0.0.2, gateway IP: 73.0.0.1. TC3 is configured with HOST2 IP: 74.0.0.2, gateway IP: 74.0.0.1. TC1 sends two streams with source IPs 1.0.0.1 and 2.0.0.1, TC2 can capture the stream with source IP 1.0.0.1, and TC3 can capture the stream with source IP 2.0.0.1.