Example for Filtering the Routes to Be Received or Advertised
Networking Requirements
Figure 10-4 shows how on an OSPF configured network, SwitchA receives routes from the Internet and provides these routes for the OSPF network. A user wants the network segments 172.16.17.0/24, 172.16.18.0/24, and 172.16.19.0/24 to be advertised on the OSPF configured network, and SwitchC to access only the network segment 172.16.18.0/24.
Configuration Roadmap
The configuration roadmap is as follows:
Configure a routing policy on SwitchA and apply the routing policy during route advertisement. When routes are advertised, the routing policy allows SwitchA to provide routes from network segments 172.16.17.0/24, 172.16.18.0/24, and 172.16.19.0/24 for SwitchB, and allows devices on the OSPF network to access only the three network segments.
Configure a routing policy on SwitchC and apply the routing policy during route importing. When routes are imported, the routing policy allows SwitchC to receive only the routes from, and therefore access, the network segment 172.16.18.0/24.
Procedure
- Add interfaces to VLANs.
<HUAWEI> system-view [~HUAWEI] sysname SwitchA [*HUAWEI] commit [~SwitchA] vlan 10 [*SwitchA-vlan10] quit [*SwitchA] interface 10ge 1/0/1 [*SwitchA-10GE1/0/1] port link-type trunk [*SwitchA-10GE1/0/1] port trunk allow-pass vlan 10 [*SwitchA-10GE1/0/1] quit [*SwitchA] commit
The configurations of SwitchB, SwitchC, and SwitchD are similar to the configuration of SwitchA, and are not described here.
- Assign IP addresses to VLANIF interfaces.
[~SwitchA] interface vlanif 10 [*SwitchA-Vlanif10] ip address 192.168.1.1 24 [*SwitchA-Vlanif10] quit [*SwitchA] commit
The configurations of SwitchB, SwitchC, and SwitchD are similar to the configuration of SwitchA, and are not described here.
- Configure basic OSPF functions.
# Configure SwitchA.
[~SwitchA] ospf [*SwitchA-ospf-1] area 0 [*SwitchA-ospf-1-area-0.0.0.0] network 192.168.1.0 0.0.0.255 [*SwitchA-ospf-1-area-0.0.0.0] quit [*SwitchA-ospf-1] quit [*SwitchA] commit
# Configure SwitchB.
[~SwitchB] ospf [*SwitchB-ospf-1] area 0 [*SwitchB-ospf-1-area-0.0.0.0] network 192.168.1.0 0.0.0.255 [*SwitchB-ospf-1-area-0.0.0.0] network 192.168.2.0 0.0.0.255 [*SwitchB-ospf-1-area-0.0.0.0] network 192.168.3.0 0.0.0.255 [*SwitchB-ospf-1-area-0.0.0.0] quit [*SwitchB-ospf-1] quit [*SwitchB] commit
# Configure SwitchC.
[~SwitchC] ospf [*SwitchC-ospf-1] area 0 [*SwitchC-ospf-1-area-0.0.0.0] network 192.168.2.0 0.0.0.255 [*SwitchC-ospf-1-area-0.0.0.0] quit [*SwitchC-ospf-1] quit [*SwitchC] commit
# Configure SwitchD.
[~SwitchD] ospf [*SwitchD-ospf-1] area 0 [*SwitchD-ospf-1-area-0.0.0.0] network 192.168.3.0 0.0.0.255 [*SwitchD-ospf-1-area-0.0.0.0] quit [*SwitchD-ospf-1] quit [*SwitchD] commit
- Configure five static routes on SwitchA and import these routes into OSPF.
[~SwitchA] ip route-static 172.16.16.0 24 NULL 0 [*SwitchA] ip route-static 172.16.17.0 24 NULL 0 [*SwitchA] ip route-static 172.16.18.0 24 NULL 0 [*SwitchA] ip route-static 172.16.19.0 24 NULL 0 [*SwitchA] ip route-static 172.16.20.0 24 NULL 0 [*SwitchA] commit [~SwitchA] ospf [~SwitchA-ospf-1] import-route static [*SwitchA-ospf-1] quit [*SwitchA] commit
# Check the IP routing table on SwitchB. You will see that the five static routes are imported into OSPF.
[~SwitchB] display ip routing-table Proto: Protocol Pre: Preference Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 13 Routes : 13 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.16.0/24 O_ASE 150 1 D 192.168.1.1 Vlanif10 172.16.17.0/24 O_ASE 150 1 D 192.168.1.1 Vlanif10 172.16.18.0/24 O_ASE 150 1 D 192.168.1.1 Vlanif10 172.16.19.0/24 O_ASE 150 1 D 192.168.1.1 Vlanif10 172.16.20.0/24 O_ASE 150 1 D 192.168.1.1 Vlanif10 192.168.1.0/24 Direct 0 0 D 192.168.1.2 Vlanif10 192.168.1.2/32 Direct 0 0 D 127.0.0.1 Vlanif10 192.168.2.0/24 Direct 0 0 D 192.168.2.1 Vlanif20 192.168.2.1/32 Direct 0 0 D 127.0.0.1 Vlanif20 192.168.3.0/24 Direct 0 0 D 192.168.3.1 Vlanif30 192.168.3.1/32 Direct 0 0 D 127.0.0.1 Vlanif30
- Configure a routing policy for advertising routes.
# Configure an IP prefix list named a2b on SwitchA.
[~SwitchA] ip ip-prefix a2b index 10 permit 172.16.17.0 24 [*SwitchA] ip ip-prefix a2b index 20 permit 172.16.18.0 24 [*SwitchA] ip ip-prefix a2b index 30 permit 172.16.19.0 24 [*SwitchA] commit
# Configure a routing policy on SwitchA for advertising routes, and use the IP prefix list a2b to filter routes.
[~SwitchA] ospf [~SwitchA-ospf-1] filter-policy ip-prefix a2b export static [*SwitchA-ospf-1] commit
# Check the IP routing table on SwitchB. You will see that SwitchB receives only three routes defined in the IP prefix list a2b.
[~SwitchB] display ip routing-table Proto: Protocol Pre: Preference Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 11 Routes : 11 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 Vlanif10 172.16.18.0/24 O_ASE 150 1 D 192.168.1.1 Vlanif10 172.16.19.0/24 O_ASE 150 1 D 192.168.1.1 Vlanif10 192.168.1.0/24 Direct 0 0 D 192.168.1.2 Vlanif10 192.168.1.2/32 Direct 0 0 D 127.0.0.1 Vlanif10 192.168.2.0/24 Direct 0 0 D 192.168.2.1 Vlanif20 192.168.2.1/32 Direct 0 0 D 127.0.0.1 Vlanif20 192.168.3.0/24 Direct 0 0 D 192.168.3.1 Vlanif30 192.168.3.1/32 Direct 0 0 D 127.0.0.1 Vlanif30
- Configure a routing policy for receiving routes.
# Configure an IP prefix list named in on SwitchC.
[~SwitchC] ip ip-prefix in index 10 permit 172.16.18.0 24 [*Switchc] commit
# Configure a routing policy on SwitchC for receiving routes, and use the IP prefix list in to filter routes.
[~SwitchC] ospf [~SwitchC-ospf-1] filter-policy ip-prefix in import [*SwitchC] commit
# Check the IP routing table on SwitchC. You will see that SwitchC receives only one route defined in the IP prefix list in.
[~SwitchC] display ip routing-table Proto: Protocol Pre: Preference Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 5 Routes : 5 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 Vlanif20 192.168.2.0/24 Direct 0 0 D 192.168.2.2 Vlanif20 192.168.2.2/32 Direct 0 0 D 127.0.0.1 Vlanif20
Configuration Files
- Configuration file of SwitchA
# sysname SwitchA # vlan batch 10 # interface Vlanif10 ip address 192.168.1.1 255.255.255.0 # interface 10GE1/0/1 port link-type trunk port trunk allow-pass vlan 10 # 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 SwitchB
# sysname SwitchB # vlan batch 10 20 30 # interface Vlanif10 ip address 192.168.1.1 255.255.255.0 # interface Vlanif20 ip address 192.168.2.1 255.255.255.0 # interface Vlanif30 ip address 192.168.3.1 255.255.255.0 # interface 10GE1/0/1 port link-type trunk port trunk allow-pass vlan 10 # interface 10GE1/0/2 port link-type trunk port trunk allow-pass vlan 20 # interface 10GE1/0/3 port link-type trunk port trunk allow-pass vlan 30 # 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 SwitchC
# sysname SwitchC # vlan batch 20 # interface Vlanif20 ip address 192.168.2.2 255.255.255.0 # interface 10GE1/0/1 port link-type trunk port trunk allow-pass vlan 20 # 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 SwitchD
# sysname SwitchD # vlan batch 30 # interface Vlanif30 ip address 192.168.3.2 255.255.255.0 # interface 10GE1/0/1 port link-type trunk port trunk allow-pass vlan 30 # ospf 1 area 0.0.0.0 network 192.168.3.0 0.0.0.255 # return