静态路由配置


Target:

   理解静态路由的工作原理,掌握如何配置静态路由。

实验原理:

路由器属于网络层设备,能够根据IP包头的信息,选择一条最佳路径,将数据包转发出去。实现不同网段的主机之间的互相访问。

路由器是根据路由表进行选路和转发的。而路由表里就是由一条条的路由信息组成。路由表的产生方式一般有3种:

1 直连路由 给路由器接口配置一个IP地址,路由器自动产生本接口IP所在网段的路由信息。

2 静态路由在拓扑结构简单的网络中,网管员通过手工的方式配置本路由器未知

网段的路由信息,从而实现不同网段之间的连接。

3 动态路由协议学习产生的路由在大规模的网络中,或网络拓扑相对复杂的情况下,通过在路由器上运行动态路由协议,路由器之间互相自动学习产生路由信息。

实验拓扑图:

144330359.png

实验设备:

路由器(带串口) 2台

V.35 DCE/DTE电缆 1对


Step:

第一步:配置路由器的名称、接口IP地址和时钟

R3740#configure terminal

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

R3740(config)#hostname RouterA

!配置路由器的名称

RouterA(config)#

RouterA(config)#interface serial 4/0

!进入端口S4/0的接口配置模式

RouterA(config-if)#clock rate 512000

!设置串口的时钟

RouterA(config-if)#ip address 192.168.1.1 255.255.255.0

!设置端口的IP地址

RouterA(config-if)#no shutdown

!开启端口

RouterA(config-if)#exit

RouterA(config)#

RouterA(config)#interface loopback 0

!设置Loopback端口用于测试

RouterA(config-if)#Sep 15 01:05:02 RouterA %7:%LINE PROTOCOL CHANGE: Interface Loopback 0, changed state to UP

RouterA(config-if)#ip address 172.16.1.1 255.255.255.0

RouterA(config-if)#exit

RouterA(config)#

RouterA(config)#interface loopback 1

RouterA(config-if)#Sep 15 01:05:31 RouterA %7:%LINE PROTOCOL CHANGE: Interface Loopback 1, changed state to UP

RouterA(config-if)#ip address 172.16.2.1 255.255.255.0

RouterA(config-if)#exit

R3740#configure terminal

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

R3740 (config)#hostname RouterB

RouterB(config)#

RouterB(config)#interface serial 4/0

RouterB(config-if)#ip address 192.168.1.2 255.255.255.0

RouterB(config-if)#no shutdown

RouterB(config-if)#exit

RouterB(config)#

RouterB(config)#interface loopback 0

RouterB(config-if)#Aug 22 03:03:36 RouterB %7:%LINE PROTOCOL CHANGE: Interface Loopback 0, changed state to UP

RouterB(config-if)#ip address 10.1.1.1 255.255.255.0

RouterB(config-if)#exit

RouterB(config)#

RouterB(config)#interface loopback 1

RouterB(config-if)#Aug 22 03:04:03 RouterB %7:%LINE PROTOCOL CHANGE: Interface Loopback 1, changed state to UP

RouterB(config-if)#ip address 10.2.2.1 255.255.255.0

RouterB(config-if)#exit

第二步:配置静态路由

RouterA(config)#ip route 10.1.1.0 255.255.255.0 192.168.1.2

!设置到子网10.1.1.0的静态路由,采用下一跳的方式

RouterA(config)#ip route 10.2.2.0 255.255.255.0 s4/0

!设置到子网10.2.2.0的静态路由,采用出站端口的方式

RouterB(config)#ip route 172.16.1.0 255.255.255.0 192.168.1.1

RouterB(config)#ip route 172.16.2.0 255.255.255.0 s4/0

第三步:查看路由表和接口配置

RouterA#show ip route

Codes: C - connected, S - static, R - RIP B - BGP

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

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

* - candidate default

Gateway of last resort is no set

S 10.1.1.0/24 [1/0] via 192.168.1.2

S 10.2.2.0/24 is directly connected, serial 4/0

C 172.16.1.0/24 is directly connected, Loopback 0

C 172.16.1.1/32 is local host.

C 172.16.2.0/24 is directly connected, Loopback 1

C 172.16.2.1/32 is local host.

C 192.168.1.0/24 is directly connected, serial 4/0

C 192.168.1.1/32 is local host.

!可以看到以下一跳方式配置的静态路由和以出站端口方式配置的静态路由,在路由表中的显示方式是不一样的

RouterA#show interfaces serial 4/0

Index(dec):1 (hex):1

serial 4/0 is UP , line protocol is UP

Hardware is Infineon DSCC4 PEB20534 H-10 serial

Interface address is: 192.168.1.1/24

MTU 1500 bytes, BW 2000 Kbit

Encapsulation protocol is HDLC, loopback not set

Keepalive interval is 10 sec , set

Carrier delay is 2 sec

RXload is 1 ,Txload is 1

Queueing strategy: WFQ

11421118 carrier transitions

V35 DCE cable

DCD=up DSR=up DTR=up RTS=up CTS=up

5 minutes input rate 19 bits/sec, 0 packets/sec

5 minutes output rate 19 bits/sec, 0 packets/sec

95 packets input, 4134 bytes, 0 no buffer, 1 dropped

Received 69 broadcasts, 0 runts, 0 giants

0 input errors, 0 CRC, 0 frame, 0 overrun, 0 abort

94 packets output, 4118 bytes, 0 underruns , 0 dropped

0 output errors, 0 collisions, 0 interface resets

RouterB#show ip route

Codes: C - connected, S - static, R - RIP B - BGP

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

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

* - candidate default

Gateway of last resort is no set

C 10.1.1.0/24 is directly connected, Loopback 0

C 10.1.1.1/32 is local host.

C 10.2.2.0/24 is directly connected, Loopback 1

C 10.2.2.1/32 is local host.

S 172.16.1.0/24 [1/0] via 192.168.1.1

S 172.16.2.0/24 is directly connected, serial 4/0

C 192.168.1.0/24 is directly connected, serial 4/0

C 192.168.1.2/32 is local host.

RouterB#show interfaces serial 4/0

Index(dec):1 (hex):1

serial 4/0 is UP , line protocol is UP

Hardware is Infineon DSCC4 PEB20534 H-10 serial

Interface address is: 192.168.1.2/24

MTU 1500 bytes, BW 2000 Kbit

Encapsulation protocol is HDLC, loopback not set

Keepalive interval is 10 sec , set

Carrier delay is 2 sec

RXload is 1 ,Txload is 1

Queueing strategy: WFQ

11421118 carrier transitions

V35 DTE cable

DCD=up DSR=up DTR=up RTS=up CTS=up

5 minutes input rate 74 bits/sec, 0 packets/sec

5 minutes output rate 74 bits/sec, 0 packets/sec

86 packets input, 3942 bytes, 0 no buffer, 0 dropped

Received 61 broadcasts, 0 runts, 0 giants

0 input errors, 0 CRC, 0 frame, 0 overrun, 0 abort

87 packets output, 3964 bytes, 0 underruns , 0 dropped

0 output errors, 0 collisions, 1 interface resets

第四步:测试网络连通性

RouterA#ping 10.1.1.1

Sending 5, 100-byte ICMP Echoes to 10.1.1.1, timeout is 2 seconds:

< press Ctrl+C to break >

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 1/4/10 ms

RouterA#ping 10.2.2.1

Sending 5, 100-byte ICMP Echoes to 10.2.2.1, timeout is 2 seconds:

< press Ctrl+C to break >

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 1/4/10 ms

RouterB#ping 172.16.1.1

Sending 5, 100-byte ICMP Echoes to 172.16.1.1, timeout is 2 seconds:

< press Ctrl+C to break >

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 1/4/10 ms

RouterB#ping 172.16.2.1

Sending 5, 100-byte ICMP Echoes to 172.16.2.1, timeout is 2 seconds:

< press Ctrl+C to break >

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 1/4/10 ms

【注意事项】

1、如果两台路由器通过串口直接互连,则必须在其中一端设置时钟频率(DCE)。

2、静态路由必须双向都配置才能互通,配置时注意回程路由。

【参考配置】

RouterA#show running-config

Building configuration...

Current configuration : 745 bytes

!

version RGNOS 10.1.00(4), Release(18443)(Tue Jul 17 21:16:17 CST 2007 -ubu1server)

hostname RouterA

!

!

interface serial 4/0

ip address 192.168.1.1 255.255.255.0

clock rate 512000

!

interface serial 4/1

clock rate 64000

!

interface GigabitEthernet 0/0

duplex auto

speed auto

!

interface GigabitEthernet 0/1

duplex auto

speed auto

!

interface Loopback 0

ip address 172.16.1.1 255.255.255.0

!

interface Loopback 1

ip address 172.16.2.1 255.255.255.0

!

ip route 10.1.1.0 255.255.255.0 192.168.1.2

ip route 10.2.2.0 255.255.255.0 serial 4/0

!

line con 0

line aux 0

line vty 0 4

login

!

end

RouterB#show running-config

Building configuration...

Current configuration : 725 bytes

!

version RGNOS 10.1.00(4), Release(18443)(Tue Jul 17 21:16:17 CST 2007 -ubu1server)

hostname RouterB

!

!

interface serial 4/0

ip address 192.168.1.2 255.255.255.0

!

interface serial 4/1

clock rate 64000

!

interface GigabitEthernet 0/0

duplex auto

speed auto

!

interface GigabitEthernet 0/1

duplex auto

speed auto

!

interface Loopback 0

ip address 10.1.1.1 255.255.255.0

!

interface Loopback 1

ip address 10.2.2.1 255.255.255.0

!

ip route 172.16.1.0 255.255.255.0 192.168.1.1

ip route 172.16.2.0 255.255.255.0 serial 4/0

!

line con 0

line aux 0

line vty 0 4

login

!

end