课题内容:
OSPF中为什么将环回口通告为主机路由?
实验拓扑:
基本IP地址配置及OSPF宣告配置
R1(config)#interface loopback 0
R1(config-if)#ip address 11.1.1.1 255.255.255.0
R1(config-if)#ip ospf 110 area 0
R1(config-if)#interface e0/0
R1(config-if)#ip address 12.1.1.1 255.255.255.252
R1(config-if)#no shutdown
R1(config-if)#ip ospf 110 area 0
R1(config-if)#end
R2(config)#interface loopback 0
R2(config-if)#ip address 22.1.1.1 255.255.255.0
R2(config-if)#ip ospf 110 area 0
R2(config-if)#interface e0/0
R2(config-if)#ip address 12.1.1.2 255.255.255.252
R2(config-if)#no shutdown
R2(config-if)#ip ospf 110 area 0
R2(config-if)#end
观察现象:
R1#show ip route ospf | begin Gateway
Gateway of last resort is not set
22.0.0.0/32 is subnetted, 1 subnets
O 22.1.1.1 [110/11] via 12.1.1.2, 00:01:28, Ethernet0/0
R2#show ip route ospf | begin Gateway
Gateway of last resort is not set
11.0.0.0/32 is subnetted, 1 subnets
O 11.1.1.1 [110/11] via 12.1.1.1, 00:01:42, Ethernet0/0
// R1 和 R2 的环回接口配置了24位长度的子网掩码,然而在路由表中却显示为 32位的主机路由 //
众所周知,OSPF的路由是由LSDB中的计算而来,我们来看下LSA的具体内容
R1#show ip ospf database router self-originate
OSPF Router with ID (11.1.1.1) (Process ID 110)
Router Link States (Area 0)
LS age: 359
Options: (No TOS-capability, DC)
LS Type: Router Links
Link State ID: 11.1.1.1
Advertising Router: 11.1.1.1
LS Seq Number: 80000003
Checksum: 0x527B
Length: 48
Number of Links: 2
Link connected to: a Stub Network
(Link ID) Network/subnet number: 11.1.1.1
(Link Data) Network Mask: 255.255.255.255
Number of MTID metrics: 0
TOS 0 Metrics: 1
Link connected to: a Transit Network
(Link ID) Designated Router address: 12.1.1.2
(Link Data) Router Interface address: 12.1.1.1
Number of MTID metrics: 0
TOS 0 Metrics: 10
//注意下划线标注的位置,R1在将环回口的链路状态收集为LSA内容的时候就已经标记为了 32 位的子网掩码; //
那么,OSPF为什么要这样做呢?
我们在RFC 2328中寻找答案:
Section 9.1节选
Loopback
In this state, the router’s interface to the network is looped back. The interface may be looped back in hardware or software. The interface will be unavailable for regular data traffic. However, it may still be desirable to gain information on the quality of this interface, either through sending ICMP pings to the interface or through something like a bit error test. For this reason, IP packets may still be addressed to an interface in Loopback state. To facilitate this, such interfaces are advertised in router-LSAs as single host routes, whose destination is the IP interface address.
翻译:
在此状态下,路由器与网络的接口将被环回。 接口可以在硬件或软件中循环。 该接口将无法用于常规数据流量。 但是,仍然需要获得有关此接口质量的信息,方法是将ICMP ping发送到接口或通过比特错误测试。 因此,IP数据包仍可以寻址到Loopback状态的接口。 为此,这些接口在Router-LSA中作为单个主机路由通告,其目的地是IP接口地址。
看起来,OSPF仅仅把环回口当作测试需要而设计;
然而在现如今主流的MPLS+IP的解决方案中,环回口的子网掩码则非常重要。在MPLS环境中,OSPF的环回口子网掩码如果配置的不是32位,则会造成标签断裂,从而造成×××流量被丢弃。(有关详细内容,欢迎关注乾颐堂达叔的博客更新,以及CCIE理论课哦)
关于解决方案:
不同的厂商解决方案也不同;
在cisco的设备上,将环回口的OSPF网络类型修改为点到点,将能够在LSA中真实反应出实际配置的子网掩码;
R1>enable
R1#conf t
R1(config)#interface loopback 0
R1(config-if)#ip ospf network point-to-point
R1(config-if)#end
验证:
R1#show ip ospf database router self-originate
OSPF Router with ID (11.1.1.1) (Process ID 110)
Router Link States (Area 0)
LS age: 28
Options: (No TOS-capability, DC)
LS Type: Router Links
Link State ID: 11.1.1.1
Advertising Router: 11.1.1.1
LS Seq Number: 80000006
Checksum: 0x4289
Length: 48
Number of Links: 2
Link connected to: a Stub Network
(Link ID) Network/subnet number: 11.1.1.0
(Link Data) Network Mask: 255.255.255.0
Number of MTID metrics: 0
TOS 0 Metrics: 1
Link connected to: a Transit Network
(Link ID) Designated Router address: 12.1.1.2
(Link Data) Router Interface address: 12.1.1.1
Number of MTID metrics: 0
TOS 0 Metrics: 10
R2#show ip route ospf | begin Gateway
Gateway of last resort is not set
11.0.0.0/24 is subnetted, 1 subnets
O 11.1.1.0 [110/11] via 12.1.1.1, 00:00:57, Ethernet0/0
谢谢大家!
我是达叔。