关于缺省路由传递问题的探讨(ip default-network、ip default-gateway、ip route 0/0)

来源:互联网 发布:红点聊天软件 编辑:程序博客网 时间:2024/06/06 00:54

介绍

默认路由是一种特殊的静态路由,指的是当路由表中与包的目的地址之间没有匹配的表项时路由器能够做出的选择。当无法获得目标网段的精确路由时,默认路由是很有有效的,尤其是在末梢网络中。

这篇文章解释了如何配置默认路由和默认网关的,包含三条命令:

  • ip default-gateway

  • ip default-network

  • and ip route 0.0.0.0 0.0.0.0


    1. ip default-gateway


    仅在路由器关闭路由功能的情况下(no ip routing)才有效。

    应用场景:

    当路由器是一台主机或者路由器在boot模式下,为了使用tftp的情况下使用这条命令。

    此时直接ip default-gateway **(下一跳地址)即可


    2. ip default-network

    当使用Ip default-network在本地指一个网络时,这个网络号如果在路由表中存在,那么路由器会将该网络指定为缺省网关.



    我们在R1上配置完成之后查看其路由表:

          12.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
    C        12.1.1.0/24 is directly connected, FastEthernet0/0
    L        12.1.1.1/32 is directly connected, FastEthernet0/0
          23.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
    S        23.0.0.0/8 [1/0] via 23.1.1.0
    S        23.1.1.0/24 [1/0] via 12.1.1.2

    我们发现之前配置的ip default-network 23.1.1.0多了一个主类网络:

    23.0.0.0/8 [1/0] via 23.1.1.0。并且没有产生任何的默认路由。因此我们必须在R1上添加一条通往主类网络的默认路由:ip default-network 23.0.0.0.

    此时我们再次查看R1路由表:


    S*    0.0.0.0/0 [1/0] via 23.1.1.0
          12.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
    C        12.1.1.0/24 is directly connected, FastEthernet0/0
    L        12.1.1.1/32 is directly connected, FastEthernet0/0
     *    23.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
    S*       23.0.0.0/8 [1/0] via 23.1.1.0
    S        23.1.1.0/24 [1/0] via 12.1.1.2

    此时就能够ping通R2的2.2.2.2路由了。

    此时我们要注意ip default-network是有类的,因此如果使用该命令标记一个子网,实际上路由器会安装主类路由进路由表。

    如果我们使用的是动态路由,ip default-network命令指定的网络就必须通过动态协议获得。

    总结:

     If you configure multiple networks as candidate default routes using the ip default-network command, the network that has the lowest administrative distance is chosen as the network for the gateway of last resort. If all the networks have the same administrative distance then the network listed first in the routing table (show ip route lists the routing table) is chosen as the network for the gateway of last resort. If you use both the ip default-network and ip route 0.0.0.0 0.0.0.0 commands to configure candidate default networks, and the network used by the ip default-network command is known statically, the network defined with the ip default-network command takes precedence and is chosen for the gateway of last resort. Otherwise if the network used by the ip default-network command is derived by a routing protocol, the ip route 0.0.0.0 0.0.0.0 command, which has a lower administrative distance, takes precedence and is chosen for the gateway of last resort. If you use multiple ip route 0.0.0.0 0.0.0.0commands to configure a default route, traffic is load-balanced over the multiple routes.

    如果使用ip default-network指定了多个候选缺省路由,那么拥有最低AD的将会成为缺省路由,并且设定为缺省网关(gateway of last resort),如果AD都相等,那么show ip route 第一个显示的,就作为缺省网关。如果同时使用ip defaut-network及ip route 0.0.0.0 0.0.0.0,且ip defaut-network指定的网络为静态路由配置的,那么ip defaut-network的优先,并且成为缺省网关 gateway of last resort。但如果ip defaut-network指定的网络是学习自动态路由协议,则ip route 0/0的优先。

    原文地址:
    http://www.cisco.com/c/en/us/support/docs/ip/routing-information-protocol-rip/16448-default.html
  • ip default-gateway

  • ip default-network

  • and ip route 0.0.0.0 0.0.0.0

  • 0 0
    原创粉丝点击