不同交换机、不同VLAN之间的通信,实验报告_VLAN 

S0:
第一步设置VTP、打开Trunk口:
S0(vlan)#vtp domain 123     //建域
Changing VTP domain name from NULL to 123
S0(vlan)#vtp server       //配置为服务器模式
Device mode already VTP SERVER.
S0(vlan)#

S0(config)#interface fastethernet 0/1
S0(config-if)#switchport mode trunk       //打开Trunk口

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

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

S0(config-if)#


S1:
S1(vlan)#vtp ?
  client       Set the device to client mode.
  domain       Set the name of the VTP administrative domain.
  password     Set the password for the VTP administrative domain.
  server       Set the device to server mode.
  transparent  Set the device to transparent mode.
  v2-mode      Set the administrative domain to V2 mode.
S1(vlan)#vtp domain 123          //要与服务器端在同一个域里边。
Domain name already set to 123.
S1(vlan)#vtp cli
S1(vlan)#vtp client            //配置为客户端模式
Setting device to VTP CLIENT mode.
S1(vlan)#
S1(vlan)#exit
APPLY completed.
Exiting....
S1#
S1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
S1(config)#interface fastethernet 0/1
S1(config-if)#switchport mode trunk
S1(config-if)#

第二步划分VLAN: (服务器端)

S0#vlan database
% Warning: It is recommended to configure VLAN from config mode,
  as VLAN database mode is being deprecated. Please consult user
  documentation for configuring VTP/VLAN in config mode.

S0(vlan)#vlan 2
VLAN 2 added:
    Name: VLAN0002
S0(vlan)#vlan 3
VLAN 3 added:
    Name: VLAN0003
S0(vlan)#
S0(config)#interface fastethernet 0/2
S0(config-if)#switchport mode access        //把接口配置成接入模式
S0(config-if)#switchport access vlan 2   //把F0/2划进VLAN 2
S0(config-if)#end
S0#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
S0(config)#interface fastethernet 0/3
S0(config-if)#switchport mode access
S0(config-if)#switchport access vlan 3              //把F0/3划进VLAN 3
S0(config-if)#
接着去S1给VLAN添加端口
S1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
S1(config)#interface fastethernet 0/2
S1(config-if)#switchport mode access     //把接口配置成接入模式
S1(config-if)#switchport access vlan 2  //把 F0/2划进VLAN 2
S1(config-if)#
S1(config)#interface fastethernet 0/3
S1(config-if)#switchport mode access       
S1(config-if)#switchport access vlan 3  //把F0/3划进VLAN 3
S1(config-if)#


客户端IP配置:
PC0:
IP Address        192.168.1.100
subnet mask       255.255.255.0
default gateway   192.168.1.1

PC1:
IP Address        192.168.2.10
subnet mask       255.255.255.0
default gateway   192.168.2.1

PC2:
IP Address        192.168.1.104
subnet mask       255.255.255.0
default gateway   192.168.1.1

PC3:
IP Address        192.168.2.12
subnet mask       255.255.255.0
default gateway   192.168.2.1

实现了不同交换机相同VLAN之间的通信。要实现不同VLAN之间的通信必须经过路由。

R1:
R1(config)#interface fastethernet 0/0
R1(config-if)#no ip address      禁用IP
R1(config-if)#no shutdown        开启端口

%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)#end
R1(config)#interface fastethernet 0/0.2  //进子接口

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

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.2, changed state to up
R1(config-subif)#encap
R1(config-subif)#encapsulation dot1q 2   //先封装再配IP 不然出错。
R1(config-subif)#ip address 192.168.1.1 255.255.255.0       //IP为1.0网段的网关地址。
R1(config-subif)#no shutdown   //开启端口
R1(config-subif)#end
R1(config)#interface fastethernet 0/0.3 
R1(config-subif)#
%LINK-5-CHANGED: Interface FastEthernet0/0.3, changed state to up

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

R1(config-subif)#encap
R1(config-subif)#encapsulation dot1q 3
R1(config-subif)#ip address 192.168.2.1 255.255.255.0   //IP为2.0网段的网关地址。
R1(config-subif)#no shutdown
R1(config-subif)#

最后一步去与路由器直连的交换机打开trunK口。

S0#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
S0(config)#interface fastethernet 0/4       //与路由器相连的端口打开trunk
S0(config-if)#switchport mode trunk

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

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

S0(config-if)#no shutdown   
S0(config-if)#