感觉自己需要一个平台记录每一天的学习,所以决定从今天起写写博客。
知识都是那些知识,做法也都是那些做法,我还在不断地学习传统做法,暂时还没有推陈出新的本领,而这只是对我学习过程的一个记录,但愿不会涉及到抄袭问题。如果我的某些文章可以帮到你,拿去用就好,也没有什么被抄袭的问题。下面进入正题。
(一)不同vlan之间通信的三种方法
不同vlan之间的通信,根据设备不同也有不同的设备配置。以下使用的环境:Cisco Packet Tracer 6.0
1、路由器+二层交换机,使用单臂路由技术,即在路由器上开启子接口。
描述:PC0所在网段:192.168.1.0,属于vlan10;PC1所在网段:192.168.2.0,属于vlan20。实现PC0、PC1之间的相互访问。
配置:
(1)终端设备
PC0 | PC1 | |
IP地址 | 192.168.1.2 | 192.168.2.2 |
子网掩码 | 255.255.255.0 | 255.255.255.0 |
默认网关 | 192.168.1.1 | 192.168.2.1 |
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#vlan 10
Switch(config-vlan)#exit
Switch(config)#vlan 20
Switch(config-vlan)#exit
Switch(config)#int f0/2
Switch(config-if)#sw
Switch(config-if)#switchport mode access
Switch(config-if)#sw
Switch(config-if)#switchport access vlan 10
Switch(config-if)#int f0/3
Switch(config-if)#sw
Switch(config-if)#switchport mode access
Switch(config-if)#sw
Switch(config-if)#switchport access vlan 20
Switch(config-if)#int f0/1
Switch(config-if)#no shut
Switch(config-if)#no shutdown
Switch(config-if)#sw
Switch(config-if)#switchport mode trunk
Switch(config-if)#
(3)路由器
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int f0/0
Router(config-if)#no sh
Router(config-if)#no shutdown
Router(config-if)#int f0/0.10
Router(config-subif)#en
Router(config-subif)#encapsulation d
Router(config-subif)#encapsulation dot1Q 10
Router(config-subif)#ip add 192.168.1.1 255.255.255.0
Router(config-subif)#exit
Router(config)#int f0/0.20
Router(config-subif)#en
Router(config-subif)#encapsulation d
Router(config-subif)#encapsulation dot1Q 20
Router(config-subif)#ip add 192.168.2.1 255.255.255.0
Router(config-subif)#exit
Router(config)#
2、三层交换机,使用SVI(switch virtual interface:交换机虚拟接口)技术。
描述:PC0所在网段:192.168.1.0,属于vlan10;PC1所在网段:192.168.2.0,属于vlan20。实现PC0、PC1之间的相互访问。
配置:
(1)终端设备配置同上。
(2)交换机
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#vlan 10
Switch(config-vlan)#vlan 20
Switch(config-vlan)#exit
Switch(config)#int vlan 10
Switch(config-if)#ip add 192.168.1.1 255.255.255.0
Switch(config-if)#ip routing
Switch(config)#int vlan 20
Switch(config-if)#ip add 192.168.2.1 255.255.255.0
Switch(config-if)#ip routing
Switch(config)#int f0/1
Switch(config-if)#sw
Switch(config-if)#switchport mode access
Switch(config-if)#sw
Switch(config-if)#switchport access vlan 10
Switch(config-if)#int f0/2
Switch(config-if)#sw
Switch(config-if)#switchport mode access
Switch(config-if)#sw
Switch(config-if)#switchport access vlan 20
Switch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up
Switch(config-if)#
3、路由器+三层交换机,是对方法二的延伸,可以通过路由器访问外网。
描述:PC3所在网段:192.168.1.0,属于vlan10;PC4所在网段:192.168.2.0,属于vlan20;PC5模拟外网主机。应实现PC3、PC4、PC5相互访问。
配置:
(1)终端设备:
PC3 | PC4 | PC5 | |
IP地址 | 192.168.1.2 | 192.168.2.2 | 202.113.112.2 |
子网掩码 | 255.255.255.0 | 255.255.255.0 | 255.255.255.0 |
默认网关 | 192.168.1.1 | 192.168.2.1 | 202.113.112.1 |
Switch3:
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#vlan 10
Switch(config-vlan)#int f0/1
Switch(config-if)#sw
Switch(config-if)#switchport mode access
Switch(config-if)#sw
Switch(config-if)#switchport access vlan 10
Switch(config-if)#int f0/2
Switch(config-if)#sw
Switch(config-if)#switchport
Switch(config-if)#switchport mode trunk
Switch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to up
Switch(config-if)#
Switch4:
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#vlan 20
Switch(config-vlan)#int f0/1
Switch(config-if)#sw
Switch(config-if)#switchport mode access
Switch(config-if)#sw
Switch(config-if)#switchport access vlan 20
Switch(config-if)#int f0/2
Switch(config-if)#sw
Switch(config-if)#switchport mode trunk
Switch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to up
Switch(config-if)#
(3)三层交换机:
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#vlan 10
Switch(config-vlan)#vlan 20
Switch(config-vlan)#int f0/2
Switch(config-if)#sw
Switch(config-if)#switchport mode access
Switch(config-if)#sw
Switch(config-if)#switchport access vlan 10
Switch(config-if)#sw
Switch(config-if)#switchport mode trunk
Switch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to up
Switch(config-if)#int f0/3
Switch(config-if)#sw
Switch(config-if)#switchport mode access
Switch(config-if)#sw
Switch(config-if)#switchport access vlan 20
Switch(config-if)#sw
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)#int vlan 10
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan10, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up
Switch(config-if)#ip add 192.168.1.1 255.255.255.0
Switch(config-if)#ip routing
Switch(config)#int 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)#ip add 192.168.2.1 255.255.255.0
Switch(config-if)#ip routing
Switch(config)#int f0/1
Switch(config-if)#no shu
Switch(config-if)#no shutdown
Switch(config-if)#no sw
Switch(config-if)#no switchport
Switch(config-if)#ip add 192.168.3.1 255.255.255.0
Switch(config-if)#exit
Switch(config)#ip route 0.0.0.0 0.0.0.0 192.168.3.2
Switch(config)#
(4)路由器
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int f0/0
Router(config-if)#ip add 192.168.3.2 255.255.255.0
Router(config-if)#no shut
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Router(config-if)#int f0/1
Router(config-if)#ip add 202.113.112.1 255.255.255.0
Router(config-if)#no shut
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
Router(config-if)#exit
Router(config)#ip route 192.168.1.0 255.255.255.0 192.168.3.1
Router(config)#ip route 192.168.2.0 255.255.255.0 192.168.3.1
Router(config)#
总结:
无论是方法一还是方法二,都可以总结为三个步骤:创建vlan(在交换机上:二层或三层)—>划分vlan(switchport)—>设置IP地址(路由器的子接口或三层交换机的子接口),有点像废话。
三层交换机有二层交换机和路由器的共性:no switchport 可以开启路由接口模式,设置IP地址;ip routing(在config模式下) 可以开启路由功能;可以设置vlan,也可以设置静态路由。
注意:
方法一中,路由器上要先开启encapsulation dot1Q 协议,再设置子接口的ip地址。
方法二中,要开启每个SVI的ip routing 功能。
方法三中,
万事开头难,希望自己可以一直坚持下去。(第一次写博客,感觉开启了新世界的大门)