天天看點

路由器 靜态路由配置 ------ 1.非預設的方式 2.超網法的方式 3.預設的方式

3種方式的拓撲圖完全一樣,不一樣的地方是在路由指令操作方面: ip route 目标網絡位址      子網路遮罩      下一跳位址

測試也完全一樣,拓撲圖如下:

路由器 靜态路由配置 ------ 1.非預設的方式 2.超網法的方式 3.預設的方式

依次配置3台路由器啟用接口的IP位址資訊如下:

路由器R1

Router>en

Router#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#host R1

R1(config)#int fa0/0

R1(config-if)#ip add 192.168.4.1 255.255.255.0

R1(config-if)#no shut

R1(config-if)#

%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

R1(config-if)#int se3/0

R1(config-if)#ip add 192.168.1.1 255.255.255.0

R1(config-if)#clock rate 64000

R1(config-if)#no shut

%LINK-5-CHANGED: Interface Serial3/0, changed state to down

R1(config-if)#end

R1#

%SYS-5-CONFIG_I: Configured from console by console

%LINK-5-CHANGED: Interface Serial3/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial3/0, changed state to up

R1#

路由器R2

Router>en

Router#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#host R2

R2(config)#int se2/0

R2(config-if)#ip add 192.168.1.2 255.255.255.0

R2(config-if)#no shut

R2(config-if)#

%LINK-5-CHANGED: Interface Serial2/0, changed state to up

R2(config-if)#

%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial2/0, changed state to up

R2(config-if)#int fa0/0

R2(config-if)#ip add 192.168.2.1 255.255.255.0

R2(config-if)#no shut

R2(config-if)#

%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

R2(config-if)#end

R2#

%SYS-5-CONFIG_I: Configured from console by console

R2#

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

R2#

路由器R3

Router>en

Router#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#host R3

R3(config)#int fa0/0

R3(config-if)#ip add 192.168.2.2 255.255.255.0

R3(config-if)#no shut

R3(config-if)#

%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

R3(config-if)#int fa1/0

R3(config-if)#ip add 192.168.3.1 255.255.255.0

R3(config-if)#no shut

R3(config-if)#

%LINK-5-CHANGED: Interface FastEthernet1/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0, changed state to up

R3(config-if)#end

R3#

%SYS-5-CONFIG_I: Configured from console by console

R3#

無論采用3種方式的哪一種配置靜态路由,以上各個路由器接口IP位址配置指令完全一樣。

方法1.非預設的方式配置路由:

路由器R1

R1#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

R1(config)#ip route 192.168.2.0 255.255.255.0 192.168.1.2

R1(config)#ip route 192.168.3.0 255.255.255.0 192.168.1.2

R1(config)#end

R1#

%SYS-5-CONFIG_I: Configured from console by console

R1#show ip route

Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP

       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP

       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area

       * - candidate default, U - per-user static route, o - ODR

       P - periodic downloaded static route

Gateway of last resort is not set

C    192.168.1.0/24 is directly connected, Serial3/0

S    192.168.2.0/24 [1/0] via 192.168.1.2

S    192.168.3.0/24 [1/0] via 192.168.1.2

C    192.168.4.0/24 is directly connected, FastEthernet0/0

R1#

路由器R2

R2#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

R2(config)#ip route 192.168.4.0 255.255.255.0 192.168.1.1

R2(config)#ip route 192.168.3.0 255.255.255.0 192.168.2.2

R2(config)#end

R2#

%SYS-5-CONFIG_I: Configured from console by console

R2#show ip route

Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP

       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP

       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area

       * - candidate default, U - per-user static route, o - ODR

       P - periodic downloaded static route

Gateway of last resort is not set

C    192.168.1.0/24 is directly connected, Serial2/0

C    192.168.2.0/24 is directly connected, FastEthernet0/0

S    192.168.3.0/24 [1/0] via 192.168.2.2

S    192.168.4.0/24 [1/0] via 192.168.1.1

R2#

路由器R3

R3#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

R3(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1

R3(config)#ip route 192.168.4.0 255.255.255.0 192.168.2.1

R3(config)#end

R3#

%SYS-5-CONFIG_I: Configured from console by console

R3#show ip route

Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP

       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP

       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area

       * - candidate default, U - per-user static route, o - ODR

       P - periodic downloaded static route

Gateway of last resort is not set

S    192.168.1.0/24 [1/0] via 192.168.2.1

C    192.168.2.0/24 is directly connected, FastEthernet0/0

C    192.168.3.0/24 is directly connected, FastEthernet1/0

S    192.168.4.0/24 [1/0] via 192.168.2.1

R3#

方法2.超網法的方式配置路由:(實際上是合并預設網段組成一個大網段,屬于劃分子網方面的知識)

路由器R1

R1#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

 注釋:子網路遮罩将預設的C類位址8個預設網段192.168.0.0、192.168.1.0 、192.168.2.0、192.168.3.0、192.168.4.0、192.168.5.0 、192.168.6.0 、192.168.7.0  合并成一個大網段 ,在同一網段内的IP可直接通路。

此範例中超網的方式配置路由需要滿足8個預設網段連續,并在同一個大的網段内。,參看我的另外一篇 如何規劃與劃分子網,如果子網路遮罩是192.168.252.0

表示連續的4個預設網段合并成一個大網段,此時192.168.4.0就在第2個大網段内,這樣就不對了。

R1(config)#ip route 192.168.0.0 255.255.248.0 192.168.1.2  

R1(config)#end

R1#

%SYS-5-CONFIG_I: Configured from console by console

R1#show ip route

Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP

       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP

       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area

       * - candidate default, U - per-user static route, o - ODR

       P - periodic downloaded static route

Gateway of last resort is not set

S    192.168.0.0/21 [1/0] via 192.168.1.2

C    192.168.1.0/24 is directly connected, Serial3/0

C    192.168.4.0/24 is directly connected, FastEthernet0/0

R1#

路由器R2

R2#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

R2(config)#ip route 192.168.4.0 255.255.255.0 192.168.1.1

R2(config)#ip route 192.168.3.0 255.255.255.0 192.168.2.2

R2(config)#end

R2#

%SYS-5-CONFIG_I: Configured from console by console

R2#show ip route

Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP

       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP

       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area

       * - candidate default, U - per-user static route, o - ODR

       P - periodic downloaded static route

Gateway of last resort is not set

C    192.168.1.0/24 is directly connected, Serial2/0

C    192.168.2.0/24 is directly connected, FastEthernet0/0

S    192.168.3.0/24 [1/0] via 192.168.2.2

S    192.168.4.0/24 [1/0] via 192.168.1.1

R2#

路由器R3

R3#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

R3(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1

R3(config)#ip route 192.168.4.0 255.255.255.0 192.168.2.1

R3(config)#end

R3#

%SYS-5-CONFIG_I: Configured from console by console

R3#show ip route

Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP

       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP

       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area

       * - candidate default, U - per-user static route, o - ODR

       P - periodic downloaded static route

Gateway of last resort is not set

S    192.168.1.0/24 [1/0] via 192.168.2.1

C    192.168.2.0/24 is directly connected, FastEthernet0/0

C    192.168.3.0/24 is directly connected, FastEthernet1/0

S    192.168.4.0/24 [1/0] via 192.168.2.1

R3#

方法3.預設的方式配置路由:

路由器R1

R1#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

R1(config)#ip route 192.168.2.0 255.255.255.0 192.168.1.2

R1(config)#ip route 0.0.0.0 0.0.0.0 192.168.1.2

R1(config)#end

R1#

%SYS-5-CONFIG_I: Configured from console by console

R1#show ip route

Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP

       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP

       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area

       * - candidate default, U - per-user static route, o - ODR

       P - periodic downloaded static route

Gateway of last resort is 192.168.1.2 to network 0.0.0.0

C    192.168.1.0/24 is directly connected, Serial3/0

S    192.168.2.0/24 [1/0] via 192.168.1.2

C    192.168.4.0/24 is directly connected, FastEthernet0/0

S*   0.0.0.0/0 [1/0] via 192.168.1.2

R1#

路由器R2

R2#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

R2(config)#ip route 192.168.4.0 255.255.255.0 192.168.1.1

R2(config)#ip route 192.168.3.0 255.255.255.0 192.168.2.2

R2(config)#end

R2#

%SYS-5-CONFIG_I: Configured from console by console

R2#show ip route

Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP

       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP

       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area

       * - candidate default, U - per-user static route, o - ODR

       P - periodic downloaded static route

Gateway of last resort is not set

C    192.168.1.0/24 is directly connected, Serial2/0

C    192.168.2.0/24 is directly connected, FastEthernet0/0

S    192.168.3.0/24 [1/0] via 192.168.2.2

S    192.168.4.0/24 [1/0] via 192.168.1.1

R2#

路由器R3

R3#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

R3(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1

R3(config)#ip route 0.0.0.0 0.0.0.0 192.168.2.1

R3(config)#end

R3#

%SYS-5-CONFIG_I: Configured from console by console

R3#show ip route

Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP

       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP

       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area

       * - candidate default, U - per-user static route, o - ODR

       P - periodic downloaded static route

Gateway of last resort is 192.168.2.1 to network 0.0.0.0

S    192.168.1.0/24 [1/0] via 192.168.2.1

C    192.168.2.0/24 is directly connected, FastEthernet0/0

C    192.168.3.0/24 is directly connected, FastEthernet1/0

S*   0.0.0.0/0 [1/0] via 192.168.2.1

R3#

測試路由器配置

在用戶端PC0上

PC>ping 192.168.3.10

Pinging 192.168.3.10 with 32 bytes of data:

Request timed out.

Request timed out.

Reply from 192.168.3.10: bytes=32 time=1ms TTL=125

Reply from 192.168.3.10: bytes=32 time=3ms TTL=125

Ping statistics for 192.168.3.10:

Packets: Sent = 4, Received = 2, Lost = 2 (50% loss),

Approximate round trip times in milli-seconds:

Minimum = 1ms, Maximum = 3ms, Average = 2ms

PC>

在用戶端PC1上

PC>ping 192.168.4.10

Pinging 192.168.4.10 with 32 bytes of data:

Reply from 192.168.4.10: bytes=32 time=1ms TTL=125

Reply from 192.168.4.10: bytes=32 time=2ms TTL=125

Reply from 192.168.4.10: bytes=32 time=1ms TTL=125

Reply from 192.168.4.10: bytes=32 time=1ms TTL=125

Ping statistics for 192.168.4.10:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 1ms, Maximum = 2ms, Average = 1ms

PC>

測試結果表明每種靜态路由的配置方式都完全正确。

繼續閱讀