拓扑图:
基本配置:
R1,R2 192.168.12.0/24
R2,R3 192.168.23.0/24
R1:
interface Loopback0
 ip address 1.1.1.1 255.255.255.0
 ip ospf network point-to-point
!
interface Loopback1
 ip address 10.10.10.10 255.255.255.0
 ip ospf network point-to-point //指定OSPF网络类型避免loopback接口问题
在没有配置分发列表前各路由器的路由表:
R1:
r1#sh ip rou
C    192.168.12.0/24 is directly connected, Serial0/0
     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Loopback0
     10.0.0.0/24 is subnetted, 1 subnets
C       10.10.10.0 is directly connected, Loopback1
O    192.168.23.0/24 [110/128] via 192.168.12.2, 00:01:45, Serial0/0
r1#
R2
r2#sh ip rou
C    192.168.12.0/24 is directly connected, Serial0/0
     1.0.0.0/24 is subnetted, 1 subnets
O       1.1.1.0 [110/65] via 192.168.12.1, 00:01:32, Serial0/0
     10.0.0.0/24 is subnetted, 1 subnets
O       10.10.10.0 [110/65] via 192.168.12.1, 00:01:32, Serial0/0
C    192.168.23.0/24 is directly connected, Serial0/1
r2#
R3:
r3#sh ip rou
O    192.168.12.0/24 [110/128] via 192.168.23.1, 00:01:14, Serial0/0
     1.0.0.0/24 is subnetted, 1 subnets
O       1.1.1.0 [110/129] via 192.168.23.1, 00:01:14, Serial0/0
     10.0.0.0/24 is subnetted, 1 subnets
O       10.10.10.0 [110/129] via 192.168.23.1, 00:01:14, Serial0/0
C    192.168.23.0/24 is directly connected, Serial0/0
r3#
可以看到各路由器都学习到了全网的路由。下面配置分发列表:
配置参数:
r2(config)#acc 1 den 10.10.10.0
r2(config)#acc 1 per an
r2(config)#router os 1
r2(config-router)#distrib 1 in s0/0
查看配置效果:
r2#sh ip rou
C    192.168.12.0/24 is directly connected, Serial0/0
     1.0.0.0/24 is subnetted, 1 subnets
O       1.1.1.0 [110/65] via 192.168.12.1, 00:00:26, Serial0/0
C    192.168.23.0/24 is directly connected, Serial0/1
r2#
可以看到R2的路由表中没有10.10.10.0/24的路由了,但R3的路由表中还是有的,
R3:
r3#clear ip route *
r3#sh ip rou
O    192.168.12.0/24 [110/128] via 192.168.23.1, 00:00:01, Serial0/0
     1.0.0.0/24 is subnetted, 1 subnets
O       1.1.1.0 [110/129] via 192.168.23.1, 00:00:01, Serial0/0
     10.0.0.0/24 is subnetted, 1 subnets
O       10.10.10.0 [110/129] via 192.168.23.1, 00:00:01, Serial0/0
C    192.168.23.0/24 is directly connected, Serial0/0
r3#
因为OSPF是链路状态路由协议,是通过LSA来更新路由表的。下面可以在R2查看10.10.10.0/24LSA.
r2#show ip ospf database
 
            OSPF Router with ID (192.168.23.1) (Process ID 1)
 
                Router Link States (Area 0)
 
Link ID         ADV Router      Age         Seq#       Checksum Link count
10.10.10.10     10.10.10.10     339         0x80000004 0x00C3DC 4
192.168.23.1    192.168.23.1    346         0x80000004 0x00D194 4
192.168.23.2    192.168.23.2    382         0x80000002 0x000416 2
r2#
r2#show ip os database router 10.10.10.10
 
            OSPF Router with ID (192.168.23.1) (Process ID 1)
 
                Router Link States (Area 0)
 
  LS age: 368
  Options: (No TOS-capability, DC)
  LS Type: Router Links
  Link State ID: 10.10.10.10
  Advertising Router: 10.10.10.10
  LS Seq Number: 80000004
  Checksum: 0xC3DC
  Length: 72
  Number of Links: 4
 
    Link connected to: a Stub Network
     (Link ID) Network/subnet number: 10.10.10.0
     (Link Data) Network Mask: 255.255.255.0
      Number of TOS metrics: 0
       TOS 0 Metrics: 1
 
    Link connected to: a Stub Network
     (Link ID) Network/subnet number: 1.1.1.0
     (Link Data) Network Mask: 255.255.255.0
      Number of TOS metrics: 0
       TOS 0 Metrics: 1
 
    Link connected to: another Router (point-to-point)
     (Link ID) Neighboring Router ID: 192.168.23.1
     (Link Data) Router Interface address: 192.168.12.1
      Number of TOS metrics: 0
       TOS 0 Metrics: 64
 
    Link connected to: a Stub Network
     (Link ID) Network/subnet number: 192.168.12.0
     (Link Data) Network Mask: 255.255.255.0
      Number of TOS metrics: 0
       TOS 0 Metrics: 64
 
 
r2#
可以得出分发列表的IN方向在OSPF中只能到本路由器有作用!!!