在文章Cisco Packet Tracer入门–三层交换机局域网搭建教程的基础上进行操作
搭建
一、实验目标:
三层交换机负责作为局域网的默认网关和DHCP
目的:模拟公司网络分布,公司A有三个部分:技术部(vlan10 192.168.10.0/24)、财务部(vlan20 192.168.20.0/24)、市场部(vlan30 192.168.30.0/24)
假设每个部门有两台电脑(为网络添加相应数量电脑)
一个交换机作为一个部门的枢纽,一个交换机一个vlan、一个网段
二、实验过程
- Ping+抓包
ping是一个行为,它使用的协议为ICMP,因此我们勾选ICMP,不勾选其他(不显示其它协议相关包)(包=报文)
设置完毕之后,我们用主机192.168.1.2 ping 192.168.1.5来看数据包的传送情况(抓包)
【对于一次数据包的发送:发送端发送数据包到接收端,接收端收到数据包后将会生成回复报文(回复数据包)给发送端。告诉发送端它已经收到发送端发给它的数据包了】
【它的作用在于动态展示数据报文在网络间的一次传输,可以在过程中各个节点数据报文的变化,用于辅助学习】
【在Switch1进行操作】
Switch>
Switch>en
Switch#config
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname sw1 --为本台交换机重命名为sw1(修改设备名称)
sw1(config)# --可以看到已经重命名成功
sw1(config)#vlan 10 --创建vlan10(vlan即虚拟局域网)
sw1(config-vlan)#name jishubu --为vlan10命名为技术部jishubu
sw1(config-vlan)#exit
sw1(config)#vlan 20
sw1(config-vlan)#name caiwubu
sw1(config-vlan)#exit
sw1(config)#vlan 30
sw1(config-vlan)#name shichangbu
sw1(config-vlan)#exit
【基于端口划分vlan】
sw1(config)#interface range f0/2-3 --同时进入f0-2和f0-3端口,如果只进入一个端口的话(如进入端口f0/2)输入命令 interface f0/2
sw1(config-if-range)#switchport mode access --端口模式设置为access(access模式即接入模式,因为该端口连接终端设备,所以需要设置为access模式)
【补充-端口模式:
access:接入模式。只能允许一种的vlan流量通过
trunk:中继模式(主干模式)。可允许多种的vlan流量通过】
sw1(config-if-range)#switchport access vlan 10 --将端口f0-2、f0-3划分到vlan10
上述命令对应配图
假设交换机sw1需要连接一台市场部(其他部门)–即只通过一种vlan流量 的终端,我们应该这样配置
sw1#
sw1#config
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
sw1(config)#int f0/4
sw1(config-if)#switchport mode access
sw1(config-if)#switchport access vlan 30
sw1(config-if)#exit
当sw1所连接的市场部的电脑与本部电脑同时豆芽发送数据包时,将会如何处理?
这时交换机sw1需要多种流量通过,因此
sw1(config)#
sw1(config)#int f0/1 --进入到端口f0/1
sw1(config-if)#switchport mode trunk --设置端口模式为trunk主干模式
sw1(config-if)#
%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
sw1(config-if)#switchport trunk allowed vlan all --设置交换机trunk模式运行所有vlan端口流量通过(如果只想要vlan10与vlan20通过可以更改命令为switchport trunk allowed vlan 10,20)
如果想要是我们的三层交换机可以访问互联网,那么肯定也需要让三层交换机能够接受多种端口流量,同理,我们的三层交换机也同样要设置成trunk端口
Switch>en
Switch#config
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#int f0/1
Switch(config-if)#switchport mode trunk
Command rejected: An interface whose trunk encapsulation is "Auto" can not be configured to "trunk" mode. --发现代码报错:在思科的三层交换机里,trunk端口的设置需要先封装,再设置为trunk端口
Switch(config-if)#switchport trunk encapsulation dot1q --封装
Switch(config-if)#switchport mode trunk
Switch(config-if)#switchport trunk allowed vlan all
【二层交换机不需要封装,但三层交换机需要封装】
【shift+? 命令帮助】
【table可以命令补全】
【目标--不同的部门获取到不同的ip地址】
【过程--1.创建vlan,通过不同的vlan将每一个部门进行逻辑划分;2.结合vlan对交换机端口模式的设置access+trunk;3.在三层交换机里设置默认网关地址;4.在三层交换机里设置三个地址池给三个不同的部门】
Switch(config-if)#hostname dsw
dsw(config)#vlan 10
dsw(config-vlan)#name jishubu
dsw(config-vlan)#exit
dsw(config)#vlan 20
dsw(config-vlan)#name caiwubu
dsw(config-vlan)#exit
dsw(config)#vlan 30
dsw(config-vlan)#name shichangbu
dsw(config-vlan)#exit
dsw(config)#int vlan 10
dsw(config-if)#
%LINK-5-CHANGED: Interface Vlan10, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up
dsw(config-if)#ip address 192.168.10.254 255.255.255.0
dsw(config-if)#no shutdown
dsw(config-if)#exit
dsw(config)#int vlan 20
dsw(config-if)#
%LINK-5-CHANGED: Interface Vlan20, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up
dsw(config-if)#ip address 192.168.20.254 255.255.255.0
dsw(config-if)#no shutdown
dsw(config-if)#exit
dsw(config)#int vlan 30
dsw(config-if)#
%LINK-5-CHANGED: Interface Vlan30, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan30, changed state to up
dsw(config-if)#ip address 192.168.30.254 255.255.255.0
dsw(config-if)#no shutdown
dsw(config-if)#exit
dsw#show ip interface brief
Interface IP-Address OK? Method Status Protocol
FastEthernet0/1 unassigned YES unset up up
……….
Vlan1 192.168.1.1 YES manual up up
Vlan10 192.168.10.254 YES manual up up
Vlan20 192.168.20.254 YES manual up up
Vlan30 192.168.30.254 YES manual up up --up可以看到我们的端口已经尽数打开【网关地址设置成功】 双up即打开,一个up一个down是没有打开
【接下来在三层交换机里设置三个地址池给三个不同的部门】
【命令show running-config查看当前运行的所有配置】
dsw#show running-config
Building configuration…
…………
ip dhcp pool myippool --在这里我们看到了已有且正在运行的地址池的配置信息
network 192.168.1.0 255.255.255.0
default-router 192.168.1.1
dns-server 114.114.114.114
……..
【可以将上面的地址池命令段取出,编辑修改为我们需要的命令,可快速创建地址池】
dns-server 114.114.114.114
ip dhcp pool 20
network 192.168.20.0 255.255.255.0
default-router 192.168.20.254
dns-server 114.114.114.114
ip dhcp pool 30
network 192.168.30.0 255.255.255.0
default-router 192.168.30.254
dns-server 114.114.114.114
【之后将它们复制黏贴到CLI命令行中执行–实现快速创建】
【三层交换机】
dsw(config)#ip dhcp pool 10
dsw(dhcp-config)#network 192.168.10.0 255.255.255.0
dsw(dhcp-config)#default-router 192.168.10.254
dsw(dhcp-config)#dns-server 114.114.114.114
dsw(dhcp-config)#ip dhcp pool 20
dsw(dhcp-config)#network 192.168.20.0 255.255.255.0
dsw(dhcp-config)#default-router 192.168.20.254
dsw(dhcp-config)#dns-server 114.114.114.114
dsw(dhcp-config)#ip dhcp pool 30
dsw(dhcp-config)#network 192.168.30.0 255.255.255.0
dsw(dhcp-config)#default-router 192.168.30.254
dsw(dhcp-config)#dns-server 114.114.114.114
dsw(dhcp-config)#exit
【在财务部交换机进行操作】
Switch>en
Switch#config
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#int f0/1
Switch(config-if)#switchport mode trunk
Switch(config-if)#
%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
Switch(config-if)#switchport trunk allowed vlan all
Switch(config-if)#exit
Switch(config)#int range f0/2-3
Switch(config-if-range)#switchport mode access
Switch(config-if-range)#switchport access vlan 20
% Access VLAN does not exist. Creating vlan 20 --返现vlan20不存在,自动进行创建vlan20
Switch(config-if-range)#
【在市场部交换机进行操作】
Switch>
Switch>en
Switch#config
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#int f0/1
Switch(config-if)#switchport mode trunk
Switch(config-if)#
%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
Switch(config-if)#switchport trunk allowed vlan all
Switch(config-if)#exit
Switch(config)#int range f0/2-3
Switch(config-if-range)#switchport mode access
Switch(config-if-range)#switchport access vlan 30
% Access VLAN does not exist. Creating vlan 30
Switch(config-if-range)#
最后在PC端的ip设置窗口选择dhcp即可完成自动获取ip了。