Filters can be applied to the received routes and those to be advertised based on networking requirements.
In Figure 1, on the network running OSPF, Device A receives routes from the Internet and provides some Internet routes for Device B. It is required that Device A provide only 172.16.17.0/24, 172.16.18.0/24, and 172.16.19.0/24 for Device B, Device C receive only 172.16.18.0/24, and that Device D receive all the routes provided by Device B.
When filtering received routes and those to be advertised, note the following rules:
When configuring an IP prefix list, specify the IP prefix range as required.
The IP prefix list name is case sensitive.
The configuration roadmap is as follows:
Configure basic OSPF functions on Device A, Device B, Device C, and Device D.
Configure static routes on Device A and import these routes into OSPF.
Configure a policy to filter routes to be advertised on Device A and then check the routing table on Device B.
Configure a policy to filter received routes on Device C and then check the routing table on Device C.
To complete the configuration, you need the following data:
Five static routes imported by Device A
Area 0 (backbone area), in which Device A, Device B, Device C, and Device D are located
Name of the IP prefix list and routes to be filtered
# Configure Device A.
[~DeviceA] ospf [*DeviceA-ospf-1] area 0 [*DeviceA-ospf-1-area-0.0.0.0] network 192.168.1.0 0.0.0.255 [*DeviceA-ospf-1-area-0.0.0.0] commit [~DeviceA-ospf-1-area-0.0.0.0] quit [~DeviceA-ospf-1] quit
# Configure Device B.
[~DeviceB] ospf [*DeviceB-ospf-1] area 0 [*DeviceB-ospf-1-area-0.0.0.0] network 192.168.1.0 0.0.0.255 [*DeviceB-ospf-1-area-0.0.0.0] network 192.168.2.0 0.0.0.255 [*DeviceB-ospf-1-area-0.0.0.0] network 192.168.3.0 0.0.0.255 [*DeviceB-ospf-1-area-0.0.0.0] commit [~DeviceB-ospf-1-area-0.0.0.0] quit
# Configure Device C.
[~DeviceC] ospf [*DeviceC-ospf-1] area 0 [*DeviceC-ospf-1-area-0.0.0.0] network 192.168.2.0 0.0.0.255 [*DeviceC-ospf-1-area-0.0.0.0] commit [~DeviceC-ospf-1-area-0.0.0.0] quit [~DeviceC-ospf-1] quit
# Configure Device D.
[~DeviceD] ospf [*DeviceD-ospf-1] area 0 [*DeviceD-ospf-1-area-0.0.0.0] network 192.168.3.0 0.0.0.255 [*DeviceD-ospf-1-area-0.0.0.0] commit [~DeviceD-ospf-1-area-0.0.0.0] quit
[~DeviceA] ip route-static 172.16.16.0 24 NULL0 [*DeviceA] ip route-static 172.16.17.0 24 NULL0 [*DeviceA] ip route-static 172.16.18.0 24 NULL0 [*DeviceA] ip route-static 172.16.19.0 24 NULL0 [*DeviceA] ip route-static 172.16.20.0 24 NULL0 [*DeviceA] ospf [*DeviceA-ospf-1] import-route static [*DeviceA-ospf-1] commit [~DeviceA-ospf-1] quit
# Display the IP routing table on Device B. The following command output shows that the five static routes have been imported into OSPF.
[~DeviceB] display ip routing-table Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route ------------------------------------------------------------------------------ Routing Table : Public Destinations : 22 Routes : 22 Destination/Mask Proto Pre Cost Flags NextHop Interface 1.1.1.1/32 Direct 0 0 D 127.0.0.1 LoopBack1 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 172.16.16.0/24 O_ASE 150 1 D 192.168.1.1 GigabitEthernet0/1/0 172.16.17.0/24 O_ASE 150 1 D 192.168.1.1 GigabitEthernet0/1/0 172.16.18.0/24 O_ASE 150 1 D 192.168.1.1 GigabitEthernet0/1/0 172.16.19.0/24 O_ASE 150 1 D 192.168.1.1 GigabitEthernet0/1/0 172.16.20.0/24 O_ASE 150 1 D 192.168.1.1 GigabitEthernet0/1/0 192.168.1.0/24 Direct 0 0 D 192.168.1.2 GigabitEthernet0/1/0 192.168.1.1/32 Direct 0 0 D 192.168.1.1 GigabitEthernet0/1/0 192.168.1.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/0 192.168.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/0 192.168.2.0/24 Direct 0 0 D 192.168.2.1 GigabitEthernet0/1/16 192.168.2.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/16 192.168.2.2/32 Direct 0 0 D 192.168.2.2 GigabitEthernet0/1/16 192.168.2.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/16 192.168.3.0/24 Direct 0 0 D 192.168.3.1 GigabitEthernet0/1/8 192.168.3.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/8 192.168.3.2/32 Direct 0 0 D 192.168.3.2 GigabitEthernet0/1/8 192.168.3.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/8
# Configure the IP prefix list named a2b on Device A.
[~DeviceA] ip ip-prefix a2b index 10 permit 172.16.17.0 24 [*DeviceA] ip ip-prefix a2b index 20 permit 172.16.18.0 24 [*DeviceA] ip ip-prefix a2b index 30 permit 172.16.19.0 24 [*DeviceA] commit
# Configure a policy on Device A and use the IP prefix list named a2b to filter routes.
[~DeviceA] ospf [*DeviceA-ospf-1] filter-policy ip-prefix a2b export static [*DeviceA-ospf-1] commit [~DeviceA-ospf-1] quit
# Display the IP routing table on Device B. The following command output shows that Device B has received only three routes specified in the IP prefix list named a2b.
[~DeviceB] display ip routing-table Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route ------------------------------------------------------------------------------ Routing Table : Public Destinations : 20 Routes : 20 Destination/Mask Proto Pre Cost Flags NextHop Interface 1.1.1.1/32 Direct 0 0 D 127.0.0.1 LoopBack1 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 172.16.17.0/24 O_ASE 150 1 D 192.168.1.1 GigabitEthernet0/1/0 172.16.18.0/24 O_ASE 150 1 D 192.168.1.1 GigabitEthernet0/1/0 172.16.19.0/24 O_ASE 150 1 D 192.168.1.1 GigabitEthernet0/1/0 192.168.1.0/24 Direct 0 0 D 192.168.1.2 GigabitEthernet0/1/0 192.168.1.1/32 Direct 0 0 D 192.168.1.1 GigabitEthernet0/1/0 192.168.1.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/0 192.168.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/0 192.168.2.0/24 Direct 0 0 D 192.168.2.1 GigabitEthernet0/1/16 192.168.2.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/16 192.168.2.2/32 Direct 0 0 D 192.168.2.2 GigabitEthernet0/1/16 192.168.2.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/16 192.168.3.0/24 Direct 0 0 D 192.168.3.1 GigabitEthernet0/1/8 192.168.3.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/8 192.168.3.2/32 Direct 0 0 D 192.168.3.2 GigabitEthernet0/1/8 192.168.3.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/8
# Configure the IP prefix list named in on Device C.
[~DeviceC] ip ip-prefix in index 10 permit 172.16.18.0 24 [*DeviceC] commit
# Configure a policy on Device C and use the IP prefix list named in to filter routes.
[~DeviceC] ospf [*DeviceC-ospf-1] filter-policy ip-prefix in import [*DeviceC-ospf-1] commit
# Display the IP routing table on Device C. The following command output shows that Device C has received only one route specified in the IP prefix list named in.
[~DeviceC] display ip routing-table Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route ------------------------------------------------------------------------------ Routing Table : Public Destinations : 12 Routes : 12 Destination/Mask Proto Pre Cost Flags NextHop Interface 1.1.1.1/32 O_ASE 10 1 D 192.168.2.1 GigabitEthernet0/1/0 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 172.16.18.0/24 O_ASE 150 1 D 192.168.2.1 GigabitEthernet0/1/0 192.168.1.0/24 O_ASE 10 2 D 192.168.2.1 GigabitEthernet0/1/0 192.168.2.0/24 Direct 0 0 D 192.168.2.2 GigabitEthernet0/1/0 192.168.2.1/32 Direct 0 0 D 192.168.2.1 GigabitEthernet0/1/0 192.168.2.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/0 192.168.2.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/1/0 192.168.3.0/24 O_ASE 10 2 D 192.168.2.1 GigabitEthernet0/1/0
Device A configuration file
# sysname DeviceA # interface GigabitEthernet0/1/0 undo shutdown ip address 192.168.1.1 255.255.255.0 # ospf 1 filter-policy ip-prefix a2b export static import-route static area 0.0.0.0 network 192.168.1.0 0.0.0.255 # ip ip-prefix a2b index 10 permit 172.16.17.0 24 ip ip-prefix a2b index 20 permit 172.16.18.0 24 ip ip-prefix a2b index 30 permit 172.16.19.0 24 # ip route-static 172.16.16.0 255.255.255.0 NULL0 ip route-static 172.16.17.0 255.255.255.0 NULL0 ip route-static 172.16.18.0 255.255.255.0 NULL0 ip route-static 172.16.19.0 255.255.255.0 NULL0 ip route-static 172.16.20.0 255.255.255.0 NULL0 # return
Device B configuration file
# sysname DeviceB # interface GigabitEthernet0/1/0 undo shutdown ip address 192.168.1.2 255.255.255.0 # interface GigabitEthernet0/1/8 undo shutdown ip address 192.168.3.1 255.255.255.0 # interface GigabitEthernet0/1/16 undo shutdown ip address 192.168.2.1 255.255.255.0 # ospf 1 area 0.0.0.0 network 192.168.1.0 0.0.0.255 network 192.168.2.0 0.0.0.255 network 192.168.3.0 0.0.0.255 # return
Device C configuration file
# sysname DeviceC # interface GigabitEthernet0/1/0 undo shutdown ip address 192.168.2.2 255.255.255.0 # ospf 1 filter-policy ip-prefix in import area 0.0.0.0 network 192.168.2.0 0.0.0.255 # ip ip-prefix in index 10 permit 172.16.18.0 24 # return
Device D configuration file
# sysname DeviceD # interface GigabitEthernet0/1/0 undo shutdown ip address 192.168.3.2 255.255.255.0 # ospf 1 area 0.0.0.0 network 192.168.3.0 0.0.0.255 # return