zoukankan      html  css  js  c++  java
  • 有类与无类路由下的路由匹配原则(转载)

    使用有类路由:路由器首先匹配主网络号,如果主网络号存在,就继续匹配子网号,且不考虑缺省路由,如果子网无法匹配,丢弃数据包(在分类路由下,路由器认为知道所有主网络下的全部子网),并使用ICMP返回一个不可达回应。如果主网络号不存在,使用缺省路由(缺省路由存在前提)。

      上述情况出现在某些早期IOS版本里(12.0以前版本),这些早期版本默认没有打开ip classless.

      打开ip classless以后将改变路由器的路由行为,此时路由器将进行最长最精确匹配或使用默认路由进行匹配

      使用无类路由,如果没有找到最具体的匹配,就使用缺省路由。

      ip classless命令的作用主要是改变有类路由协议的查找路由表的行为。

      例1:某路由器上运行的路由协议为RIP(有类的路由协议),路由表如下:

      R 10.1.0.0/16 via 1.1.1.1

      R 10.2.0.0/26 via 1.1.1.2

      R* 0.0.0.0/0 via 1.1.1.3

      现在假设有3个IP报文,报文A的目标IP是10.1.1.1、报文B的目标IP是10.3.1.1、报文C的目标IP是11.11.1.1

      有类路由协议查找路由表的行为如下:

      首先查找目标IP所在的主网络,若路由表中有该主网络的任何一个子网路由的话,就必须精确匹配其中的子网路由;如果没有找到精确匹配的子网路由,它不会选择最后的缺省路由,而是丢弃报文。若路由表中不存在该主网络的任何一个子网路由,则最终选择缺省路由。

      报文A:目标IP为10.1.1.1,所在的主网络为10.0.0.0,目前的路由表中存在10.0.0.0的子网路由,此时路由器要进一步查找子网路由,是否能够精确匹配,我们看到10.1.0.0/16可以匹配我们的目标地址,所以报文A根据这条路由进行转发。

      报文B:目标IP为10.3.1.1,所在的主网络为10.0.0.0,目前的路由表中存在10.0.0.0的子网路由,此时路由器要进一步查找子网路由,是否能够精确匹配,我们看到路由表中的两条子网路由10.1.0.0/16和10.2.0.0/16均不能匹配我们的目标地址,根据有类路由协议的原则,它不会选择缺省路由,所以报文B被路由器丢弃。

      报文C:目标IP为11.1.1.1,所在的主网络为11.0.0.0,目前的路由表中不存在11.0.0.0的子网路由,此时路由器直接采用缺省路由,所以路由器采用缺省路由对报文C进行转发。

      上面的结果是有类路由协议查找路由的行为,而配置ip classless的目的就是改变它的这种行为,配置完该命令后查找路由的行为是根据最长匹配的原则,那上例中的报文B就可以通过缺省路由进行转发了。

      注意:该命令对于一个无类路由协议来说没有任何意义,因为无类路由协议查找路由的方式就是最长匹配的原则

    原文出自【比特网】,转载请保留原文链接:http://network.chinabyte.com/318/8620818.shtml

     

    note:

    1) what will be in the Route Table?

    To understand the kind of information that exists in the route table, it is useful to begin with an examination of what happens when a framed packet arrives at one of a router's interfaces. The data-link identifier in the frame's destination address field is examined. If it contains either the identifier of the router's interface or a broadcast identifier, the router strips off the frame and passes the enclosed packet to the network layer. At the network layer, the destination address of the packet is examined. If the destination address is either the IP address of the router's interface or an all-hosts broadcast address, the protocol field of the packet is examined and the enclosed data is sent to the appropriate internal process. [1]

    [1] There is also the special case of a multicast address, which is destined for a group of devices, but not for all devices. An example of a multicast address is the class D address 224.0.0.5, reserved for all OSPF-speaking routers.

    Any other destination address calls for routing. The address may be for a host on another network to which the router is attached (including the router interface attached to that network) or for a host on a network not directly connected to the router. The address may also be a directed broadcast, in which there is a distinct network or subnet address, and the remaining host bits are all ones. These addresses are also routable.

    If the packet is to be routed, the router will do a route table lookup to acquire the correct route. At a minimum, each route entry in the database must contain two items:

    • A destination address. This is the address of the network the router can reach. As this chapter explains, the router may have more than one route to the same address and/or a group of subnets of the same or of varying lengths grouped under the same major IP network address.

    • A pointer to the destination. This pointer either will indicate that the destination network is directly connected to the router or it will indicate the address of another router on a directly connected network. That router, which will be one router hop closer to the destination, is a next-hop router.

    The router will match the most specific address it can.[2] In descending order of specificity, the address may be one of the following:

    [2] There are two basic procedures for finding the best match, depending upon whether the router is behaving classfully or classlessly. Classful table lookups are explained in more detail in Chapter 5, "Routing Information Protocol (RIP),"and classless table lookups are explained in Chapter 7, "Routing Information Protocol Version 2."

    • A host address (a host route)

    • A subnet

    • A group of subnets (a summary route)

    • A major network number

    • A group of major network numbers (a supernet)

    • A default address

    This chapter provides examples of the first four types. Supernets are covered in Chapter 7, "Routing Information Protocol Version 2." A default address is considered a least-specific address and is matched only if no other match can be found. Default addressing is the topic ofChapter 12, "Default Routes and On-Demand Routing."

     

    If the destination address of the packet cannot be matched to any route table entry, the packet is dropped and a Destination Unreachable ICMP message is sent to the source address.

     

    2)Extracted from "Operation of RIP" in the Chapter 5 of Routing TCP/IP

    There is no provision for RIP to advertise a subnet mask along with each route entry. (i.e. RIP message format has no subnet mask)

     

    First, the network portion of the destination address is read and the routing table is consulted for a match. It is this first step of reading the major class A, B, or C network number that defines a classful routing table lookup. If there is no match for the major network, the packet is dropped and an ICMP Destination Unreachable message is sent to the packet's source. If there is a match for the network portion, the subnets listed for that network are examined. If a match can be found, the packet is routed. If a match cannot be made, the packet is dropped and a Destination Unreachable message is sent.

     

    The router's only recourse is to assume that the mask configured on one of its interfaces attached to 172.25.0.0 is used consistently throughout the internetwork. It will use its own mask for 172.25.0.0 to derive the subnet of the destination address. As the routing tables throughout this chapter illustrate, a router that is directly connected to a network will list the network in a heading along with the subnet mask of the connecting interface and will then list all the known subnets of the network. If the network is not directly connected, there is a listing only for the major-class network and no associated mask.

     

    Because the destination addresses of packets being routed by a classful routing protocol are interpreted according to the subnet masks locally configured on the router's interfaces, all subnet masks within a major, class-level network must be consistent

     

    Classful Routing: Summary

    The defining characteristic of a classful routing protocol is that it does not advertise an address mask along with the advertised destination address. Therefore, a classful routing protocol must first match the major class A, B, or C network portion of a destination address. For every packet passing through the router:

    1. If the destination address is a member of a directly connected major network, the subnet mask configured on the interface attached to that network will be used to determine the subnet of the destination address. Therefore, the same subnet mask must be used consistently throughout that major network.

    2. If the destination address is not a member of a directly connected major network, the router will try to match only the major class A, B, or C portion of the destination address.

    3)

    有类路由 汇总以后 地址是标准的A B C类地址掩码 即 255.0.0.0 255.255.0.0 255.255.255.0
    无类路由 汇总以后 地址是无类的 比如 172.16.12.0/16 - 172.16.15.0/16 汇总以后的地址是172.16.12.0/20 子码 不属于 A B C 3个类别

  • 相关阅读:
    扩展:13-SpringBoot-尚硅谷-基础入门
    Java-JDK动态代理(AOP)使用及实现原理分析
    程序员常用算法合集
    数据结构-图
    多叉树的基本概念
    平衡二叉树(AVL树)
    TP5返回多维数组
    使用HttpSession实现验证码
    thinkphp6使用
    无法链接远程数据库
  • 原文地址:https://www.cnblogs.com/xiaoerlang/p/3323650.html
Copyright © 2011-2022 走看看