0%

计算机网络原理实验三──三层交换机基本配置

准备

在 Switch 中拖入 3560-24PS ,放入两个PC机,并在Connections中选择Copper Straight-Through连接Switch的GigabitEthernet 0/1、0/2和两台PC机的FastEthernet 0。

开始

划分vlan

给vlan配置地址

双击进入其中一台 Switch 中,为vlan10添加192.168.20.254地址

1
2
3
4
5
6
7
8
9
10
11
Switch#en
Switch#conf
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#interface vlan 10
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan10, changed state to up

Switch(config-if)#ip address 192.168.10.254 255.255.255.0
Switch(config-if)#no sh
Switch(config-if)#

添加出错后,可为vlan10删除该地址

1
2
3
4
Switch(config-if)#int vlan 10
Switch(config-if)#no ip addre
Switch(config-if)#no ip address 192.168.10.254 255.255.255.0
Switch(config-if)#

或者直接添加新的覆盖

1
Switch(config-if)#ip address 192.168.10.254 255.255.255.0

用同样的方法,给vlan20添加192.168.20.254 的ip

给接口配置vlan

进入gb0/1与gb0/2,分别给两个接口分配vlan10与vlan20

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Switch(config)#interface gigabitEthernet 0/1
Switch(config-if)#switchport access vlan 10
Switch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up

Switch(config-if)#exit
Switch(config)#inte
Switch(config)#interface gi
Switch(config)#interface gigabitEthernet 0/2
Switch(config-if)#switc
Switch(config-if)#switchport acc
Switch(config-if)#switchport access vlan 20
% Access VLAN does not exist. Creating vlan 20
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan20, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up

Switch(config-if)#

给PC配置IP

给划分在vlan10上的PC机进行IP配置,IP地址设为192.168.10.1,Gateway设为192.168.10.254,另一台同理。

此时使用一台PC机ping另一台PC机,发现不通,但是ping 192.168.20.254是通的,这是因为交换机目前还没有路由功能。在交换机上输入

1
Switch(config)#ip routing

这时候就有三层交换机的路由功能了。

这时候就可以ping通了

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

Pinging 192.168.20.1 with 32 bytes of data:

Reply from 192.168.20.1: bytes=32 time=1ms TTL=127
Reply from 192.168.20.1: bytes=32 time<1ms TTL=127
Reply from 192.168.20.1: bytes=32 time=6ms TTL=127
Reply from 192.168.20.1: bytes=32 time<1ms TTL=127

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

不划分vlan的交换机配置

给接口配置地址

不划分vlan的时候

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#int g0/1
Switch(config-if)#no swi
Switch(config-if)#no switchport
Switch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to down

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

Switch(config-if)#ip add
Switch(config-if)#ip address 192.168.10.254 255.255.255.0
Switch(config-if)#no sh
Switch(config-if)#int g0/2
Switch(config-if)#no sw
Switch(config-if)#no switchport
Switch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/2, changed state to down

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

Switch(config-if)#ip add
Switch(config-if)#ip address 192.168.20.254 255.255.255.0
Switch(config-if)#

并给两台主机分别配置 192.168.10.1 和 192.168.20.1的ip,在 Switch 中输入

1
2
3
4
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#ip routing
Switch(config)#

在第一台PC机中输入 ping 192.168.20.1 即可ping通

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

Pinging 192.168.20.1 with 32 bytes of data:

Request timed out.
Reply from 192.168.20.1: bytes=32 time<1ms TTL=127
Reply from 192.168.20.1: bytes=32 time<1ms TTL=127
Reply from 192.168.20.1: bytes=32 time<1ms TTL=127

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

C:\>

问题探究

  • 为什么ping第一次的时候会出现一次超时?

其他

默认模式下,交换机工作在二层模式下,需要运行 no switchport 将其修改为三层模式。

交换机需要手动配置网络而路由器不用