Example for Filtering Received and Advertised Routes
Networking Requirements
Figure 10-4 shows how on an OSPF network, RouterA receives routes from the Internet and provides these routes for the OSPF network. A user wants devices on the OSPF network to access only the network segments 172.16.17.0/24, 172.16.18.0/24, and 172.16.19.0/24, and RouterC to access only the network segment 172.16.18.0/24.
Configuration Roadmap
The configuration roadmap is as follows:
Configure a routing policy on RouterA and apply the routing policy during route advertisement. When routes are advertised, the routing policy allows RouterA to provide routes from network segments 172.16.17.0/24, 172.16.18.0/24, and 172.16.19.0/24 for RouterB, and allows devices on the OSPF network to access the three network segments.
Configure a routing policy on RouterC and apply the routing policy during route importing. When routes are imported, the routing policy allows RouterC to receive only the routes from the network segment 172.16.18.0/24 and access this network segment.
Procedure
- Assign an IP address to each interface.
# Configure IP addresses for all interfaces of RouterA.
<Huawei> system-view [Huawei] sysname RouterA [RouterA] interface gigabitethernet 1/0/0 [RouterA-GigabitEthernet1/0/0] ip address 192.168.1.1 255.255.255.0 [RouterA-GigabitEthernet1/0/0] quit
The configurations of RouterB, RouterC and RouterD are similar to the configuration of RouterA, and are not mentioned here.
- Configure basic OSPF functions.
# Configure RouterA.
[RouterA] ospf
[RouterA-ospf-1] area 0
[RouterA-ospf-1-area-0.0.0.0] network 192.168.1.0 0.0.0.255
[RouterA-ospf-1-area-0.0.0.0] quit
[RouterA-ospf-1] quit
# Configure RouterB.
[RouterB] ospf
[RouterB-ospf-1] area 0
[RouterB-ospf-1-area-0.0.0.0] network 192.168.1.0 0.0.0.255
[RouterB-ospf-1-area-0.0.0.0] network 192.168.2.0 0.0.0.255
[RouterB-ospf-1-area-0.0.0.0] network 192.168.3.0 0.0.0.255
[RouterB-ospf-1-area-0.0.0.0] quit
# Configure RouterC.
[RouterC] ospf
[RouterC-ospf-1] area 0
[RouterC-ospf-1-area-0.0.0.0] network 192.168.2.0 0.0.0.255
[RouterC-ospf-1-area-0.0.0.0] quit
[RouterC-ospf-1] quit
# Configure RouterD.
[RouterD] ospf
[RouterD-ospf-1] area 0
[RouterD-ospf-1-area-0.0.0.0] network 192.168.3.0 0.0.0.255
[RouterD-ospf-1-area-0.0.0.0] quit
- Configure five static routes on RouterA and import these routes
into OSPF.
[RouterA] ip route-static 172.16.16.0 24 NULL 0
[RouterA] ip route-static 172.16.17.0 24 NULL 0
[RouterA] ip route-static 172.16.18.0 24 NULL 0
[RouterA] ip route-static 172.16.19.0 24 NULL 0
[RouterA] ip route-static 172.16.20.0 24 NULL 0
[RouterA] ospf
[RouterA-ospf-1] import-route static
[RouterA-ospf-1] quit
# Check the IP routing table on RouterB. You can see that the five static routes are imported into OSPF.
[RouterB] display ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 18 Routes : 18 Destination/Mask Proto Pre Cost Flags NextHop Interface 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 172.16.16.0/24 O_ASE 150 1 D 192.168.1.1 GigabitEthernet1/0/0 172.16.17.0/24 O_ASE 150 1 D 192.168.1.1 GigabitEthernet1/0/0 172.16.18.0/24 O_ASE 150 1 D 192.168.1.1 GigabitEthernet1/0/0 172.16.19.0/24 O_ASE 150 1 D 192.168.1.1 GigabitEthernet1/0/0 172.16.20.0/24 O_ASE 150 1 D 192.168.1.1 GigabitEthernet1/0/0 192.168.1.0/24 Direct 0 0 D 192.168.1.2 GigabitEthernet1/0/0 192.168.1.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet1/0/0 192.168.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet1/0/0 192.168.2.0/24 Direct 0 0 D 192.168.2.1 GigabitEthernet3/0/0 192.168.2.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet3/0/0 192.168.2.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet3/0/0 192.168.3.0/24 Direct 0 0 D 192.168.3.1 GigabitEthernet2/0/0 192.168.3.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet2/0/0 192.168.3.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet2/0/0 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
- Configure a policy for advertising routes.
# Configure an IP prefix list named a2b on RouterA.
[RouterA] ip ip-prefix a2b index 10 permit 172.16.17.0 24
[RouterA] ip ip-prefix a2b index 20 permit 172.16.18.0 24
[RouterA] ip ip-prefix a2b index 30 permit 172.16.19.0 24
# Configure a policy for advertising routes on RouterA and use the IP prefix list a2b to filter routes.
[RouterA] ospf
[RouterA-ospf-1] filter-policy ip-prefix a2b export static
# Check the IP routing table on RouterB. You can see that the IP routing table contains only three routes defined in the IP prefix list a2b.
[RouterB] display ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 14 Routes : 14 Destination/Mask Proto Pre Cost Flags NextHop Interface 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 172.16.17.0/24 O_ASE 150 1 D 192.168.1.1 GigabitEthernet1/0/0 172.16.18.0/24 O_ASE 150 1 D 192.168.1.1 GigabitEthernet1/0/0 172.16.19.0/24 O_ASE 150 1 D 192.168.1.1 GigabitEthernet1/0/0 192.168.1.0/24 Direct 0 0 D 192.168.1.2 GigabitEthernet1/0/0 192.168.1.1/32 Direct 0 0 D 192.168.1.1 GigabitEthernet1/0/0 192.168.1.2/32 Direct 0 0 D 127.0.0.1 InLoopBack0 192.168.2.0/24 Direct 0 0 D 192.168.2.1 GigabitEthernet3/0/0 192.168.2.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 192.168.2.2/32 Direct 0 0 D 192.168.2.2 GigabitEthernet3/0/0 192.168.3.0/24 Direct 0 0 D 192.168.3.1 GigabitEthernet2/0/0 192.168.3.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 192.168.3.2/32 Direct 0 0 D 192.168.3.2 GigabitEthernet2/0/0
- Configure the policy for receiving routes.
# Configure an IP prefix list named in on RouterC.
[RouterC] ip ip-prefix in index 10 permit 172.16.18.0 24
# Configure the policy for receiving routes on RouterC, and use the IP prefix list in to filter routes.
[RouterC] ospf
[RouterC-ospf-1] filter-policy ip-prefix in import
# Check the IP routing table on RouterC. You can see that the IP routing table contains only one route defined in the IP prefix list in.
[RouterC] display ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 6 Routes : 6 Destination/Mask Proto Pre Cost Flags NextHop Interface 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 172.16.18.0/24 O_ASE 150 1 D 192.168.2.1 GigabitEthernet1/0/0 192.168.2.0/24 Direct 0 0 D 192.168.2.2 GigabitEthernet1/0/0 192.168.2.1/32 Direct 0 0 D 192.168.2.1 GigabitEthernet1/0/0 192.168.2.2/32 Direct 0 0 D 127.0.0.1 InLoopBack0
# Check the IP routing table on RouterD, and you can find that RouterD in the local core routing table receives all the routes advertised by RouterB.
[RouterD] display ip routing-table
Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 10 Routes : 10 Destination/Mask Proto Pre Cost Flags NextHop Interface 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 172.16.17.0/24 O_ASE 150 1 D 192.168.3.1 GigabitEthernet1/0/0 172.16.18.0/24 O_ASE 150 1 D 192.168.3.1 GigabitEthernet1/0/0 172.16.19.0/24 O_ASE 150 1 D 192.168.3.1 GigabitEthernet1/0/0 192.168.1.0/24 OSPF 10 1 D 192.168.3.1 GigabitEthernet1/0/0 192.168.2.0/24 OSPF 10 1 D 192.168.3.1 GigabitEthernet1/0/0 192.168.3.0/24 Direct 0 0 D 192.168.3.2 GigabitEthernet1/0/0 192.168.3.1/32 Direct 0 0 D 192.168.3.1 GigabitEthernet1/0/0 192.168.3.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet1/0/0
# Check the OSPF routing table of RouterC. You can see that three routes defined by the IP prefix list a2b are in the OSPF routing table. In the link state protocol, you can run the filter-policy import command to filter the routes that are added to the local core routing table from the protocol routing table.
[RouterC] display ospf routing
OSPF Process 1 with Router ID 192.168.2.2 Routing Tables Routing for Network Destination Cost Type NextHop AdvRouter Area 192.168.2.0/24 1 Stub 192.168.2.2 192.168.2.2 0.0.0.0 192.168.1.0/24 2 Stub 192.168.2.1 192.168.2.1 0.0.0.0 192.168.3.0/24 2 Stub 192.168.2.1 192.168.2.1 0.0.0.0 Routing for ASEs Destination Cost Type Tag NextHop AdvRouter 172.16.17.0/24 1 Type2 1 192.168.2.1 192.168.1.1 172.16.18.0/24 1 Type2 1 192.168.2.1 192.168.1.1 172.16.19.0/24 1 Type2 1 192.168.2.1 192.168.1.1 Total Nets: 6 Intra Area: 3 Inter Area: 0 ASE: 3 NSSA: 0
Configuration Files
Configuration file of RouterA
# sysname RouterA # interface GigabitEthernet1/0/0 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
Configuration file of RouterB
# sysname RouterB # interface GigabitEthernet1/0/0 ip address 192.168.1.2 255.255.255.0 # interface GigabitEthernet2/0/0 ip address 192.168.3.1 255.255.255.0 # interface GigabitEthernet3/0/0 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
Configuration file of RouterC
# sysname RouterC # interface GigabitEthernet1/0/0 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
Configuration file of RouterD
# sysname RouterD # interface GigabitEthernet1/0/0 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