0%

计算机网络原理实验四──路由器基本配置

准备

路由器基本配置可分为静态路由配置和动态路由配置

两台路由互相连接,并将路由器连接至PC机,路由器之间配置192.168.1.0/24 网段,路由器1与PC1配置192.168.2.0/24网段,路由器2与PC2配置192.168.3.0/24网段

路由器选择1941进行。

使用 Copper Cross-over 连接所有设备,将路由器的0/1口与PC网口相连,路由器0/0口与另一个路由器相连。

更改名称便于区分,将Router0改为R1,将Router1改为R2

静态路由

路由器配置

进入R1的CLI中,完成 g0/0 的端口配置

1
2
3
4
5
6
7
8
Router#en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int g0/0
Router(config-if)#ip address 192.168.1.1 255.255.255.0
Router(config-if)#no sh // 将端口设为启用

Router(config-if)#

同时配置 g0/1 的端口

1
2
3
4
5
6
7
8
Router(config-if)#int g0/1
Router(config-if)#ip address 192.168.2.1 255.255.255.0
Router(config-if)#no sh

Router(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up

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

此处 g0/1 配置完成后就直接连通了,这是因为PC的接口不需要手动启用,而另一个路由器还未配置完毕,接口需要在配置面板或者输入 no sh 来启用,要禁用的时候可以输入 shutdown

给PC0配置 192.168.2.2 地址,并尝试在命令提示符中 ping 192.168.2.1,成功连通。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
C:\>ping 192.168.2.1

Pinging 192.168.2.1 with 32 bytes of data:

Reply from 192.168.2.1: bytes=32 time<1ms TTL=255
Reply from 192.168.2.1: bytes=32 time<1ms TTL=255
Reply from 192.168.2.1: bytes=32 time<1ms TTL=255
Reply from 192.168.2.1: bytes=32 time<1ms TTL=255

Ping statistics for 192.168.2.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

C:\>

根据操作给R2的g0/0配置192.168.1.2地址,给g0/1配置192.168.3.1地址

配置静态路由

在R1上,设置静态路由,让PC0可以访问到PC1

1
2
3
4
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#ip route 192.168.3.0 255.255.255.0 192.168.1.2
// 目的网络 子网掩码 下一跳

输入do show run查看当前配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Router(config)#do show run
Building configuration...

Current configuration : 687 bytes
!
version 15.1
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Router
!
!
!
!
!
!
!
!
no ip cef
no ipv6 cef
!
!
!
!
license udi pid CISCO1941/K9 sn FTX152485P5-
!
!
!
!
!
!
!
!
!
!
!
spanning-tree mode pvst
!
!
!
!
!
!
interface GigabitEthernet0/0
ip address 192.168.1.1 255.255.255.0
duplex auto
speed auto
!
interface GigabitEthernet0/1
ip address 192.168.2.1 255.255.255.0
duplex auto
speed auto
!
interface Vlan1
no ip address
shutdown
!
ip classless
ip route 192.168.3.0 255.255.255.0 192.168.1.2
!
ip flow-export version 9
!
!
!
!
!
!
!
!
line con 0
!
line aux 0
!
line vty 0 4
login
!
!
!
end

同样也需要在R2上配置到PC0的路由

1
Router(config)#ip route 192.168.2.0 255.255.255.0 192.168.1.1

从PC0 ping PC1 尝试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
C:\>ping 192.168.3.2

Pinging 192.168.3.2 with 32 bytes of data:

Reply from 192.168.3.2: bytes=32 time=27ms TTL=126
Reply from 192.168.3.2: bytes=32 time<1ms TTL=126
Reply from 192.168.3.2: bytes=32 time<1ms TTL=126
Reply from 192.168.3.2: bytes=32 time=9ms TTL=126

Ping statistics for 192.168.3.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 27ms, Average = 9ms

C:\>

动态路由

路由配置

给R1进行配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int g0/0
Router(config-if)#ip address 192.168.1.1 255.255.255.0
Router(config-if)#no sh

Router(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up

Router(config-if)#
Router(config-if)#int g0/1
Router(config-if)#ip address 192.168.2.1 255.255.255.0
Router(config-if)#no sh

Router(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up

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

给R2进行配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int g0/0
Router(config-if)#ip addr 192.168.1.2 255.255.255.0
Router(config-if)#no sh

Router(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up

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

Router(config-if)#int g0/1
Router(config-if)#ip addr 192.168.3.1 255.255.255.0
Router(config-if)#no sh

Router(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up

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

并给两个PC配置 192.168.2.2 与 192.168.3.2

路由协议

在两台路由器上启用ospf协议并公布自己的直连网段

在R1上配置

1
2
3
4
5
6
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#route ospf 1
Router(config-router)#network 192.168.1.0 0.0.0.255 area 0
Router(config-router)#network 192.168.2.0 0.0.0.255 area 1
Router(config-router)#

在R2上配置

1
2
3
4
5
Router(config)#route ospf 1
Router(config-router)#network 192.168.1.0 255.255.255.0 area 0
Router(config-router)#network 192.168.3.0 255.255.255.0 area 0
00:11:30: %OSPF-5-ADJCHG: Process 1, Nbr 192.168.2.1 on GigabitEthernet0/0 from LOADING to FULL, Loading Done2
Router(config-router)#

查看do show run内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Router(config-router)#do show run
Building configuration...

Current configuration : 751 bytes
!
version 15.1
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Router
!
!
!
!
!
!
!
!
ip cef
no ipv6 cef
!
!
!
!
license udi pid CISCO1941/K9 sn FTX15246BJO-
!
!
!
!
!
!
!
!
!
!
!
spanning-tree mode pvst
!
!
!
!
!
!
interface GigabitEthernet0/0
ip address 192.168.1.2 255.255.255.0
duplex auto
speed auto
!
interface GigabitEthernet0/1
ip address 192.168.3.1 255.255.255.0
duplex auto
speed auto
!
interface Vlan1
no ip address
shutdown
!
router ospf 1
log-adjacency-changes
network 192.168.1.0 0.0.0.255 area 0
network 192.168.3.0 0.0.0.255 area 2
!
ip classless
!
ip flow-export version 9
!
!
!
!
!
!
!
!
line con 0
!
line aux 0
!
line vty 0 4
login
!
!
!
end

Router(config-router)#

尝试ping另一台PC

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
C:\>ping 192.168.3.2

Pinging 192.168.3.2 with 32 bytes of data:

Request timed out.
Reply from 192.168.3.2: bytes=32 time<1ms TTL=126
Reply from 192.168.3.2: bytes=32 time<1ms TTL=126
Reply from 192.168.3.2: bytes=32 time<1ms TTL=126

Ping statistics for 192.168.3.2:
Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

C:\>

在R1上查看邻居

1
2
3
4
5
Router#show ip ospf ne

Neighbor ID Pri State Dead Time Address Interface
192.168.3.1 1 FULL/BDR 00:00:35 192.168.1.2 GigabitEthernet0/0
Router#

后记

该篇实验参照自《计算机网络实验指导书—20190220.pdf》与配套视频。