简单配置不同的VLAN和实现不同VLAN之间的通信

实验的拓扑图:

简单配置不同的VLAN和实现不同VLAN之间的通信

按照拓扑图配置相应的IP地址和网关,即可实现不同主机的通信(因为路由转发实现了两个网段的通信,路由器的两端就是两端主机对应的网关):

分别在p0,p1,p2,p3,ping各个的主机都是能ping通的.

下面是在p0,ping 其他主机.

简单配置不同的VLAN和实现不同VLAN之间的通信

 

下面是划分VLAN,VLAN10,VLAN20,和实现不同VLAN之间的通信

 

switch0的配置:(要实现不同VLAN之间的通信要将交换机的f0/3端口配置成trunk口,trunk口的作用百度一下)

Switch>ena

Switch>enable

Switch#conf

Switch#config t

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

Switch(config)#vlan 10

Switch(config-vlan)#end

Switch#

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

Switch#config t

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

Switch(config)#int f0/1

Switch(config-if)#sw

Switch(config-if)#switchport acc

Switch(config-if)#switchport access vlan 10

Switch(config-if)#exit

Switch(config)#int f0/2

Switch(config-if)#sw

Switch(config-if)#switchport acce

Switch(config-if)#switchport access vlan 10

Switch(config-if)#exit

Switch(config)#int f0/3

Switch(config-if)#sw

Switch(config-if)#switchport mode tr

Switch(config-if)#switchport mode trunk

Switch(config-if)#

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

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

Switch(config-if)#end

Switch#

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

Switch#

 

 

switch1的配置:(同样也要将f0/2端口设置成trunk口)

Switch>ena

Switch>enable

Switch#config t

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

Switch(config)#vlan 20

Switch(config-vlan)#exit

Switch(config)#int f0/1

Switch(config-if)#sw

Switch(config-if)#switchport acc

Switch(config-if)#switchport access vlam 20

^

% Invalid input detected at '^' marker.

Switch(config-if)#switchport access vlan 20

Switch(config-if)#exit

Switch(config)#int f0/2

Switch(config-if)#sw

Switch(config-if)#switchport acc

Switch(config-if)#switchport access vlan 20

Switch(config-if)#exit

Switch(config)#int f0/3

Switch(config-if)#sw

Switch(config-if)#switchport mo

Switch(config-if)#switchport mode tr

Switch(config-if)#switchport mode trunk

Switch(config-if)#

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

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

Switch(config-if)#end

Switch#

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

Switch#

 

现在不同VLAN主机之间是不可以通信的,相同VLAN主机之间是可以ping通的.

 

路由器的配置:

 

Router>ena

Router#config t

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

Router(config)#no ip add

Router(config)#int f0/0

Router(config-if)#no ip add

Router(config-if)#no ip address       //清除为设置VLAN前的IP地址

Router(config-if)#no shut

Router(config-if)#exit

Router(config)#int f0/0.10              //创建子接口

Router(config-subif)#

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

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

Router(config-subif)#en

Router(config-subif)#encapsulation do

Router(config-subif)#encapsulation dot1Q 10      //封装协议,对应的子接口绑定VLAN10

Router(config-subif)#ip add

Router(config-subif)#ip address 192.168.10.254 255.255.255.0

Router(config-subif)#exit

Router(config)#int f0/1.20

Router(config-subif)#

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

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

Router(config-subif)#exit

Router(config)#int f0/1

Router(config-if)#no ip add

Router(config-if)#no ip address

Router(config-if)#no shut

Router(config-if)#exit

Router(config)#int f0/1.20           //创建子接口

Router(config-subif)#en

Router(config-subif)#encapsulation do

Router(config-subif)#encapsulation dot1Q 20            //封装协议,对应子接口绑定VLAN20

Router(config-subif)#ip add

Router(config-subif)#ip address 192.168.20.254 255.255.255.0       //配置对应VLAN的网关

Router(config-subif)#exit

Router(config)#end

Router#

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

Router#

 

现在不同VLAN之间的主机是可以通信的了.

简单配置不同的VLAN和实现不同VLAN之间的通信