TCP/IP路由技术卷一上写道:

        When a router receives a Hello from a neighbor, it will verify that the Area ID, Authentication, Network Mask, HelloInterval, RouterDeadInterval, and Options values match the values configured on the receiving interface. If they do not, the packet is dropped and no adjacency is established.

那么子网掩码长度不一样到底能不能形成邻居关系呢?下面做个实验

R1(F0/0)---------------------(F0/0)R2

R1的F0/0 IP地址为172.16.0.1/16

R2的F0/0 IP地址为172.16.0.2/30

配好OSPF后

debug ip ospf events显示:

*Mar 1 00:02:05.827: OSPF: Rcv hello from 172.16.0.2 area 0 from FastEthernet0/0 172.16.0.2
*Mar 1 00:02:05.827: OSPF: Mismatched hello parameters from 172.16.0.2
*Mar 1 00:02:05.831: OSPF: Dead R 40 C 40, Hello R 10 C 10 Mask R 255.255.255.252 C 255.255.0.0

显示hello参数不一致(子网掩码不一样),无法形成邻居,sh ip ospf nei显示为空。

现在再换成串口互联:

R1(S1/0)---------------------(S1/0)R2

IP地址同第一个实验。

配好OSPF后,debug ip ospf events:

*Mar 1 00:07:52.227: OSPF: Interface Serial1/0 going Up
*Mar 1 00:07:52.227: OSPF: Send hello to 224.0.0.5 area 0 on Serial1/0 from 172.16.0.1
R1#
*Mar 1 00:07:55.875: OSPF: Rcv hello from 172.16.0.2 area 0 from Serial1/0 172.16.0.2
*Mar 1 00:07:55.879: OSPF: 2 Way Communication to 172.16.0.2 on Serial1/0, state 2WAY
*Mar 1 00:07:55.879: OSPF: Send DBD to 172.16.0.2 on Serial1/0 seq 0x25EE opt 0x52 flag 0x7 len 32
*Mar 1 00:07:55.879: OSPF: End of hello processing
*Mar 1 00:07:55.951: OSPF: Rcv DBD from 172.16.0.2 on Serial1/0 seq 0x26E0 opt 0x52 flag 0x7 len 32 mtu 1500 state EXSTART
*Mar 1 00:07:55.951: OSPF: NBR Negotiation Done. We are the SLAVE
*Mar 1 00:07:55.955: OSPF: Send DBD to 172.16.0.2 on Serial1/0 seq 0x26E0 opt 0x52 flag 0x2 len 52
*Mar 1 00:07:55.995: OSPF: Rcv DBD from 172.16.0.2 on Serial1/0 seq 0x26E1 opt 0x52 flag 0x3 len 72 mtu 1500 state EXCHANGE
*Mar 1 00:07:55.995: OSPF: Send DBD to 172.16.0.2 on Serial1/0 seq 0x26E1 opt 0x52 flag 0x0 len 32
*Mar 1 00:07:55.995: OSPF: Database request to 172.16.0.2
*Mar 1 00:07:55.995: OSPF: sent LS REQ packet to 172.16.0.2, length 24
*Mar 1 00
R1#:07:55.999: OSPF: Rcv DBD from 172.16.0.2 on Serial1/0 seq 0x26E2 opt 0x52 flag 0x1 len 32 mtu 1500 state EXCHANGE
*Mar 1 00:07:55.999: OSPF: Exchange Done with 172.16.0.2 on Serial1/0
*Mar 1 00:07:55.999: OSPF: Send DBD to 172.16.0.2 on Serial1/0 seq 0x26E2 opt 0x52 flag 0x0 len 32
*Mar 1 00:07:56.003: OSPF: Synchronized with 172.16.0.2 on Serial1/0, state FULL
*Mar 1 00:07:56.003: %OSPF-5-ADJCHG: Process 1, Nbr 172.16.0.2 on Serial1/0 from LOADING to FULL, Loading Done

显示成功建立了邻居关系,sh ip ospf nei也能看到对方。

难道卷一错了?

实际上,OSPF建立邻居关系时是否 检查子网掩码是分情况的,一下引用RFC2328原文:

However, there is one exception to the above rule: on point-to-point networks and on virtual links, the Network Mask in the received Hello Packet should be ignored.