Administrative Distance (AD) 管理距离

前言

当 Router 能够透过多於一个 Routing Protocol 到达目的地时,Administrative Distance (AD) 值就充当一个 Priority,让 Router 选择使用那一款 Routing Protocol 的路径。Router 会选择 AD 值最少的路径为 Best Path。例如:EIGRP 的 AD 是 90,OSPF 的 AD 是 110,当 Router 发现用 EIGRP 和 OSPF 的路径都能够到达目的地,就会选用 AD 值较少的 EIGRP。

Cisco Router 预设的 AD 值如下:

Routing Protocol Administrative Distance (AD)
Directly connected interface 0
Static route out an interface 1
Static route to next-hop address 1
DMNR – Dynamic Mobile Network Routing 3
EIGRP summary route 5
External BGP 20
Internal EIGRP 90
IGRP 100
OSPF 110
IS-IS 115
RIP 120
EGP 140
On Demand Routing (ODR) 160
External EIGRP 170
Internal BGP 200
Floating Static Route 254
Unknown 255

接下来,我们会用以下网络进行实验,试试修改 Routing 的 Protocol 的 AD。

ad

各 Router 设定如下:(Routing Protocol 的设定方法并不在本篇文章范围,如想查看关於 Routing Protocol 的设定,请读者参考本网关於 Routing Protocol 的文章。)

hostname R1
!
interface Ethernet0/0
 ip address 192.168.12.1 255.255.255.0
!
interface Ethernet0/1
 ip address 192.168.13.1 255.255.255.0
!
interface Ethernet0/2
 ip address 192.168.14.1 255.255.255.0
!
interface Ethernet0/3
 ip address 192.168.15.1 255.255.255.0
!
router eigrp 10
 network 192.168.12.0
 no auto-summary
!
router ospf 1
 network 192.168.13.0 0.0.0.255 area 0
!
router rip
 network 192.168.14.0
 version 2
 no auto-summary
!
router bgp 65000
 no synchronization
 neighbor 192.168.15.5 remote-as 65000
 no auto-summary
hostname R2
!
interface Ethernet0/0
 ip address 192.168.12.2 255.255.255.0
!
interface Ethernet0/1
 ip address 192.168.26.2 255.255.255.0
!
router eigrp 10
 network 192.168.12.0
 network 192.168.26.0
 no auto-summary
hostname R3
!
interface Ethernet0/0
 ip address 192.168.13.3 255.255.255.0
!
interface Ethernet0/1
 ip address 192.168.36.3 255.255.255.0
!
router ospf 1
 network 192.168.13.0 0.0.0.255 area 0
 network 192.168.36.0 0.0.0.255 area 0
hostname R4
!
interface Ethernet0/0
 ip address 192.168.14.4 255.255.255.0
!
interface Ethernet0/1
 ip address 192.168.46.4 255.255.255.0
!
router rip
 network 192.168.14.0
 network 192.168.46.0
 version 2
 no auto-summary
hostname R5
!
interface Ethernet0/0
 ip address 192.168.15.5 255.255.255.0
!
interface Ethernet0/1
 ip address 192.168.56.5 255.255.255.0
!
router bgp 65000
 no synchronization
 neighbor 192.168.15.1 remote-as 65000
 neighbor 192.168.15.1 route-reflector-client
 neighbor 192.168.56.6 remote-as 65000
 no auto-summary
hostname R6
!
interface Loopback0
 ip address 192.168.0.1 255.255.255.0
 ip ospf network point-to-point
!
interface Loopback1
 ip address 192.168.1.1 255.255.255.0
 ip ospf network point-to-point
!
interface Ethernet0/0
 ip address 192.168.26.6 255.255.255.0
!
interface Ethernet0/1
 ip address 192.168.36.6 255.255.255.0
!
interface Ethernet0/2
 ip address 192.168.46.6 255.255.255.0
!
interface Ethernet0/3
 ip address 192.168.56.6 255.255.255.0
!
router eigrp 10
 network 192.168.0.0
 network 192.168.1.0
 network 192.168.26.0
 no auto-summary
!
router ospf 1
 network 192.168.0.0 0.0.0.255 area 0
 network 192.168.1.0 0.0.0.255 area 0
 network 192.168.36.0 0.0.0.255 area 0
!
router rip
 network 192.168.0.0
 network 192.168.1.0
 network 192.168.46.0
 version 2
 no auto-summary
!
router bgp 65000
 no synchronization
 network 192.168.0.0
 network 192.168.1.0
 neighbor 192.168.56.5 remote-as 65000
 no auto-summary

查看 R1 的 Route Table,发现正使用 EIGRP 的路径到达 192.168.0.0/24 和 192.168.1.0/24,因为在 EIGRP丶OSPF丶RIP 和 iBGP 4 种 Routing Protocol 之中,EIGRP 的 AD 是最少的。

R1#show ip route | include 192.168...0
D    192.168.0.0/24 [90/435200] via 192.168.12.2, 00:02:17, Ethernet0/0
D    192.168.1.0/24 [90/435200] via 192.168.12.2, 00:02:17, Ethernet0/0

修改 BGP 的 AD

现在於 R1 尝试把 iBGP 的 AD 由 200 改为 80,留意 AD 值只用於 Local 而不会外传,因此网络里不同 Router 的 AD 可以不相同。

R1(config)#router bgp 65000
R1(config-router)#distance bgp ?
  <1-255>  Distance for routes external to the AS

R1(config-router)#distance bgp 20 ?
  <1-255>  Distance for routes internal to the AS

R1(config-router)#distance bgp 20 80 ?
  <1-255>  Distance for local routes

R1(config-router)#distance bgp 20 80 200
R1(config-router)#end
R1#clear ip bgp *
R1#
*Mar  1 04:09:33.706: %BGP-5-ADJCHANGE: neighbor 192.168.15.5 Up
R1#show ip route | include 192.168...0
B    192.168.0.0/24 [80/0] via 192.168.56.6, 00:00:03
B    192.168.1.0/24 [80/0] via 192.168.56.6, 00:00:03

如果不想全部 BGP Route 的 AD 改变,我们亦可只把其中一条 Route 的 AD 更改,方法是使用 ACL,留意 Source address 是该 Route 的 Advertised Router IP。

R1(config)#router bgp 65000
R1(config-router)#no distance bgp 20 80 200
R1(config-router)#distance 80 ?
  A.B.C.D  IP Source address
 
R1(config-router)#distance 80 192.168.15.5 ?
  A.B.C.D  Wildcard bits
 
R1(config-router)#distance 80 192.168.15.5 0.0.0.0 ?
  <1-99>       IP Standard access list number
  <1300-1999>  IP Standard expanded access list number
  WORD         Standard access-list name
  <cr>
 
R1(config-router)#distance 80 192.168.15.5 0.0.0.0 1
R1(config-router)#exit
R1(config)#access-list 1 permit 192.168.0.0
R1(config)#end
R1#clear ip bgp *
R1#
R1#show ip route | include 192.168...0
B    192.168.0.0/24 [80/0] via 192.168.56.6, 00:00:38
D    192.168.1.0/24 [90/435200] via 192.168.12.2, 00:00:40, Ethernet0/0

修改 RIP 的 AD

修改 RIP AD 的方法大同小异:

R1(config)#router rip
R1(config-router)#distance ?
  <1-255>  Administrative distance

R1(config-router)#distance 70 ?
  A.B.C.D  IP Source address
  <cr>

R1(config-router)#distance 70 192.168.14.4 0.0.0.0 ?
  <1-99>       IP Standard access list number
  <1300-1999>  IP Standard expanded access list number
  WORD         Standard access-list name
  <cr>

R1(config-router)#distance 70 192.168.14.4 0.0.0.0 1
R1(config-router)#end
R1#
R1#show ip route | include 192.168...0
R    192.168.0.0/24 [70/1] via 192.168.14.4, 00:00:26, Ethernet0/2
D    192.168.1.0/24 [90/435200] via 192.168.12.2, 00:12:00, Ethernet0/0

修改 OSPF 的 AD

至於 OSPF 的 AD 可以按 External, Intra-Area 和 Inter-Area 3 个类型去修改,现在以修改 Intra-Area 为例子:

R1(config)#router ospf 1
R1(config-router)#distance ?
  <1-255>  Administrative distance
  ospf     OSPF distance

R1(config-router)#distance ospf ?
  external    External type 5 and type 7 routes
  inter-area  Inter-area routes
  intra-area  Intra-area routes

R1(config-router)#distance ospf intra-area 60
R1(config-router)#end
R1#
R1#show ip route | include 192.168...0
O    192.168.0.0/24 [60/21] via 192.168.13.3, 00:00:05, Ethernet0/1
O    192.168.1.0/24 [60/21] via 192.168.13.3, 00:00:05, Ethernet0/1

当然也可以只选一条 Route 来修改,但流程会较复杂,首先要找出发放 192.168.0.0 这条 Route 的 Advertising Router 的 Router ID:

R1#show ip ospf database router

            OSPF Router with ID (1.1.1.1) (Process ID 1)

                Router Link States (Area 0)


  LS age: 796
  Options: (No TOS-capability, DC)
  LS Type: Router Links
  Link State ID: 192.168.1.1
  Advertising Router: 192.168.1.1
  LS Seq Number: 80000007
  Checksum: 0x69C9
  Length: 60
  Number of Links: 3

    Link connected to: a Stub Network
     (Link ID) Network/subnet number: 192.168.1.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: 192.168.0.0
     (Link Data) Network Mask: 255.255.255.0
      Number of TOS metrics: 0
       TOS 0 Metrics: 1

<--Output Omitted-->
R1(config)#router ospf 1
R1(config-router)#distance 60 192.168.1.1 0.0.0.0 1
R1(config-router)#end
R1#
R1#show ip route | include 192.168...0
O    192.168.0.0/24 [60/21] via 192.168.13.3, 00:00:06, Ethernet0/1
D    192.168.1.0/24 [90/435200] via 192.168.12.2, 00:09:54, Ethernet0/0

修改 EIGRP 的 AD

最後尝试修改 EIGRP 的 AD:

R1(config)#router eigrp 10
R1(config-router)#distance ?
  <1-255>  Administrative distance
  eigrp    IP-EIGRP distance

R1(config-router)#distance eigrp ?
  <1-255>  Distance for internal routes

R1(config-router)#distance eigrp 50 ?
  <1-255>  Distance for external routes

R1(config-router)#distance eigrp 50 170
R1(config-router)#end
R1#
R1#show ip route | include 192.168...0
O    192.168.0.0/24 [60/21] via 192.168.13.3, 00:02:33, Ethernet0/1
D    192.168.1.0/24 [90/435200] via 192.168.12.2, 00:12:21, Ethernet0/0
R1#
R1#show ip route | include 192.168...0
D    192.168.0.0/24 [50/435200] via 192.168.12.2, 00:00:03, Ethernet0/0
D    192.168.1.0/24 [50/435200] via 192.168.12.2, 00:00:03, Ethernet0/0

亦可按个别 Route 修改:

R1(config)#router eigrp 10
R1(config-router)#no distance eigrp 50 170
R1(config-router)#distance 50 192.168.12.2 0.0.0.0 1
R1(config-router)#end
R1#
R1#show ip route | include 192.168...0
D    192.168.0.0/24 [50/435200] via 192.168.12.2, 00:00:02, Ethernet0/0
D    192.168.1.0/24 [90/435200] via 192.168.12.2, 00:00:02, Ethernet0/0

相關主題

发表回复

2021-07-22

Posted In: Layer 3 网络技术

Leave a Comment