Router#sh ip route
1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
2.0.0.0/32 is subnetted, 1 subnets
O 2.2.2.2 [110/11] via 12.12.12.2, 00:06:44, Ethernet0/0
12.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 12.12.12.0/24 is directly connected, Ethernet0/0
L 12.12.12.1/32 is directly connected, Ethernet0/0
13.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 13.13.13.0/24 is directly connected, Ethernet0/1
L 13.13.13.1/32 is directly connected, Ethernet0/1
23.0.0.0/24 is subnetted, 1 subnets
O 23.23.23.0 [110/20] via 13.13.13.3, 00:04:52, Ethernet0/1
[110/20] via 12.12.12.2, 00:05:42, Ethernet0/0ide
Router#sh ip ospf interface brief
Interface PID Area IP Address/Mask Cost State Nbrs F/C
Lo0 1 0 1.1.1.1/32 1 LOOP 0/0
Et0/1 1 0 13.13.13.1/24 10 BDR 1/1
Et0/0 1 0 12.12.12.1/24 10 BDR 1/1
Router#oop
測試1、R2和R3接口默認Cost值爲10,接下來咱們經過調整cost值,影響R1選路:
R1(config)#interface e0/0
R1(config-if)#ip ospf cost 100
R1(config-if)#int e0/1
R1(config-if)#ip ospf cost 110
R1#sh ip route
1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
2.0.0.0/32 is subnetted, 1 subnets
O 2.2.2.2 [110/101] via 12.12.12.2, 00:00:01, Ethernet0/0
12.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 12.12.12.0/24 is directly connected, Ethernet0/0
L 12.12.12.1/32 is directly connected, Ethernet0/0
13.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 13.13.13.0/24 is directly connected, Ethernet0/1
L 13.13.13.1/32 is directly connected, Ethernet0/1
23.0.0.0/24 is subnetted, 1 subnets
O 23.23.23.0 [110/110] via 12.12.12.2, 00:00:01, Ethernet0/0
R1 e0/0 爲100 + R2 e0/0 爲10 = 110,去往13.13.13.3 R1 e0/1 爲110 + R2 e0/1 爲10 = 120,所選擇較小的12.12.12.2方向。測試
測試2、咱們將R2和R3COST值調整下,去往23.23.23.0方向接口修改COST值,看好是去的方向。code
R2(config)#interface e0/1
R2(config-if)#ip ospf cost 1010
R3(config)#interface e0/0
R3(config-if)#ip ospf cost 1000
看下R1的路由狀況:
R1#sh ip route
1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
2.0.0.0/32 is subnetted, 1 subnets
O 2.2.2.2 [110/101] via 12.12.12.2, 00:12:20, Ethernet0/0
12.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 12.12.12.0/24 is directly connected, Ethernet0/0
L 12.12.12.1/32 is directly connected, Ethernet0/0
13.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C 13.13.13.0/24 is directly connected, Ethernet0/1
L 13.13.13.1/32 is directly connected, Ethernet0/1
23.0.0.0/24 is subnetted, 1 subnets
O 23.23.23.0 [110/1110] via 13.13.13.3, 00:00:08, Ethernet0/1
[110/1110] via 12.12.12.2, 00:00:08, Ethernet0/0
R1 e0/0 爲100 + R2 e0/0 爲1010 = 1110,去往13.13.13.3 R1 e0/1 爲110 + R2 e0/1 爲1000 = 1110router
Router#sh ip ospf database router 接口
OSPF Router with ID (1.1.1.1) (Process ID 1) Router Link States (Area 0)
LS age: 260
Options: (No TOS-capability, DC)
LS Type: Router Links
Link State ID: 1.1.1.1
Advertising Router: 1.1.1.1
LS Seq Number: 80000008
Checksum: 0x888
Length: 60
Number of Links: 3ip
Link connected to: a Stub Network (Link ID) Network/subnet number: 1.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: 13.13.13.3 (Link Data) Router Interface address: 13.13.13.1 Number of MTID metrics: 0 TOS 0 Metrics: 110 Link connected to: a Transit Network (Link ID) Designated Router address: 12.12.12.2 (Link Data) Router Interface address: 12.12.12.1 Number of MTID metrics: 0 TOS 0 Metrics: 100
LS age: 1583
Options: (No TOS-capability, DC)
LS Type: Router Links
Link State ID: 12.12.12.2
Advertising Router: 12.12.12.2
LS Seq Number: 80000006
Checksum: 0x1DD
Length: 60
Number of Links: 3路由
Link connected to: a Stub Network (Link ID) Network/subnet number: 2.2.2.2 (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: 23.23.23.3 (Link Data) Router Interface address: 23.23.23.2 Number of MTID metrics: 0 TOS 0 Metrics: 1010 Link connected to: a Transit Network (Link ID) Designated Router address: 12.12.12.2 (Link Data) Router Interface address: 12.12.12.2 Number of MTID metrics: 0 TOS 0 Metrics: 10
LS age: 1529
Options: (No TOS-capability, DC)
LS Type: Router Links
Link State ID: 23.23.23.3
Advertising Router: 23.23.23.3
LS Seq Number: 80000005
Checksum: 0xB302
Length: 48
Number of Links: 2it
Link connected to: a Transit Network (Link ID) Designated Router address: 13.13.13.3 (Link Data) Router Interface address: 13.13.13.3 Number of MTID metrics: 0 TOS 0 Metrics: 10 Link connected to: a Transit Network (Link ID) Designated Router address: 23.23.23.3 (Link Data) Router Interface address: 23.23.23.3 Number of MTID metrics: 0 TOS 0 Metrics: 1000
Router# io