0、导言:
题图中是笔者自己在Cisco Packet Tracer上模拟的一个简单局域网,包括3个vlan,使用了3台路由器(SW)以及一个三层路由器(3LSW)。花了一些时间学习ccna就开始自己上手,算是一点简单实践。
下文将介绍简易的vlan路由网络搭建过程,包含4台主机,一台路由器以及一台三层路由器。
拓扑结构如下:
1、配置VLAN
各台主机按照拓扑图中信息设置网关以及本机IP地址及掩码。路由器Switch0共有24个fastEthernet接口,将其中0/1、0/2、0/3、0/4使用直连线分别接到主机PC0、PC1、PC2、PC3。
进入Switch0 CLI界面,开始设置:
-
# 1、进入config模式
-
-
Switch>en
-
Switch#config
-
Configuring from terminal, memory, or network [terminal]?
-
Enter configuration commands, one per line. End with CNTL/Z.
-
-
# 2、创建vlan,创建10以及20两个
-
-
Switch(config)#vlan 10
-
Switch(config-vlan)#exit
-
Switch(config)#vlan 20
-
Switch(config-vlan)#exit
-
-
# 3、将fastEthernet端口配置为相应的vlan接入口
-
-
Switch(config)#interface fastEthernet 0/1
-
Switch(config-if)#switchport access vlan 10
-
Switch(config-if)#exit
-
Switch(config)#interface fastEthernet 0/3
-
Switch(config-if)#switchport access vlan 10
-
Switch(config-if)#exit
-
-
Switch(config)#interface fastEthernet 0/2
-
Switch(config-if)#switchport access vlan 20
-
Switch(config-if)#exit
-
Switch(config)#interface fastEthernet 0/4
-
Switch(config-if)#switchport access vlan 20
-
Switch(config)#^Z
经过以上步骤,vlan设置完成,可以通过show vlan查看各个vlan对应的接口:
-
Switch#show vlan
-
-
VLAN Name Status Ports
-
---- -------------------------------- --------- -------------------------------
-
1 default active Fa0/5, Fa0/6, Fa0/7, Fa0/8
-
Fa0/9, Fa0/10, Fa0/11, Fa0/12
-
Fa0/13, Fa0/14, Fa0/15, Fa0/16
-
Fa0/17, Fa0/18, Fa0/19, Fa0/20
-
Fa0/21, Fa0/22, Fa0/23, Fa0/24
-
Gig0/1, Gig0/2
-
10 VLAN0010 active Fa0/1, Fa0/3
-
20 VLAN0020 active Fa0/2, Fa0/4
-
1002 fddi-default active
-
1003 token-ring-default active
-
1004 fddinet-default active
-
1005 trnet-default active
-
...
验证:
PC0 ping PC2
-
C:>ping 192.168.10.2
-
-
Pinging 192.168.10.2 with 32 bytes of data:
-
-
Reply from 192.168.10.2: bytes=32 time=1ms TTL=128
-
Reply from 192.168.10.2: bytes=32 time<1ms TTL=128
-
Reply from 192.168.10.2: bytes=32 time<1ms TTL=128
-
Reply from 192.168.10.2: bytes=32 time<1ms TTL=128
-
-
Ping statistics for 192.168.10.2:
-
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
-
Approximate round trip times in milli-seconds:
-
Minimum = 0ms, Maximum = 1ms, Average = 0ms
PC0 ping PC1
-
C:>ping 192.168.20.1
-
-
Pinging 192.168.20.1 with 32 bytes of data:
-
-
Request timed out.
-
Request timed out.
-
Request timed out.
-
Request timed out.
-
-
Ping statistics for 192.168.20.1:
-
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
vlan划分完毕。
2、设置三层交换机路由,实现不同VLAN互连
三层交换机与交换机通过交叉线连接,三层交换机端口为fastEthernet 0/1,交换机端口为fastEthernet 0/24。
首先要对交换机之间接口配置为trunk模式,对于交换机Switch0配置如下:
-
Switch>en
-
Switch#config
-
Configuring from terminal, memory, or network [terminal]?
-
Enter configuration commands, one per line. End with CNTL/Z.
-
Switch(config)#interface fastEthernet 0/24
-
Switch(config-if)#switchport mode trunk
-
-
Switch(config-if)#
-
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/24, changed state to down
-
-
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/24, changed state to up
对于三层交换机,需要进行以下配置:
1)设置互联端口模式
2)开启路由功能
3)配置vlan并开启路由转发
配置如下:
-
Switch>en
-
Switch#config
-
Configuring from terminal, memory, or network [terminal]?
-
Enter configuration commands, one per line. End with CNTL/Z.
-
-
# 1、配置接口模式,将包封装为802.1Q帧,并开启trunk模式
-
Switch(config)#interface fastEthernet 0/1
-
Switch(config-if)#switchport trunk encapsulation dot1q
-
Switch(config-if)#switchport mode trunk
-
Switch(config-if)#
-
Switch(config-if)#exit
-
-
# 2、开启路由
-
Switch(config)#ip routing
-
-
# 3、配置vlan,输入no shutdown开启路由模式。vlan的网络地址和对应网关相同
-
Switch(config)#vlan 10
-
Switch(config-vlan)#exit
-
Switch(config)#vlan 20
-
Switch(config-vlan)#exit
-
-
Switch(config)#interface 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 address 192.168.10.254 255.255.255.0
-
Switch(config-if)#no shutdown
-
Switch(config-if)#exit
-
-
Switch(config)#interface 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 address 192.168.20.254 255.255.255.0
-
Switch(config-if)#no shutdown
-
Switch(config-if)#^Z
-
Switch#
-
%SYS-5-CONFIG_I: Configured from console by console
-
-
# 4、查看路由表
-
Switch#show ip route
-
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
-
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
-
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
-
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
-
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
-
* - candidate default, U - per-user static route, o - ODR
-
P - periodic downloaded static route
-
-
Gateway of last resort is not set
-
-
C 192.168.10.0/24 is directly connected, Vlan10
-
C 192.168.20.0/24 is directly connected, Vlan20
设置完毕后,可以进行验证:
PC0 ping PC2
-
C:>ping 192.168.10.2
-
-
Pinging 192.168.10.2 with 32 bytes of data:
-
-
Reply from 192.168.10.2: bytes=32 time<1ms TTL=128
-
Reply from 192.168.10.2: bytes=32 time<1ms TTL=128
-
Reply from 192.168.10.2: bytes=32 time<1ms TTL=128
-
Reply from 192.168.10.2: bytes=32 time=1ms TTL=128
-
-
Ping statistics for 192.168.10.2:
-
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
-
Approximate round trip times in milli-seconds:
-
Minimum = 0ms, Maximum = 1ms, Average = 0ms
PC0 ping PC1
-
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
使用tracert检验路由功能:
-
C:>tracert 192.168.10.2
-
-
Tracing route to 192.168.10.2 over a maximum of 30 hops:
-
-
1 0 ms 1 ms 0 ms 192.168.10.2
-
-
Trace complete.
-
-
C:>tracert 192.168.20.1
-
-
Tracing route to 192.168.20.1 over a maximum of 30 hops:
-
-
1 0 ms 0 ms 0 ms 192.168.10.254
-
2 1 ms 0 ms 0 ms 192.168.20.1
-
-
Trace complete.
PC0一跳就到达PC2(同个vlan),而PC0到PC1需要一条到达自己的网关192.168.10.254,再通过网关跳到目标主机PC1:192.168.20.1。
流程图如下:
3、总结
交换机创建vlan步骤为:命名vlan——设置switchport access为对应vlan
三层交换机配置流程为:开启路由功能——设置interface vlan开启对应vlan的路由功能
如果有新的机器加入,那么直接接入路由器并设置接口即可。而如果有新的vlan需要划分,则需要在三层路由器以及路由器上创建vlan,并在三层路由器进行网关配置。