史上最详细的计网实验——packet tracer模拟配置vlan和静态路由

本篇博客将总结计算机网络实验在packet tracer中模拟的集体操作流程。

再此之前先来讲一下交换机和路由器一些基本的命令

在这里插入图片描述

命令含义
enable进入特权模式,可以输入命令缩写:en
configure terminal进入全局配置模式,命令缩写:conf t
exit退出当前模式
int进入某个接口,比如int fa 0/0,进入fa 0/0接口
show查看命令,比如show vlan:查看虚拟局域网号,又或者show ip route:查看路由表
shutdown断开命令,通常在已经连接的端口配置ip时,需要no shutdown 命令来更新
end退出且保存

了解了最基本的命令后,我们可以做第一个实验:交换机配置vlan。先来说说什么是vlan,vlan中文名是虚拟局域网,具体作用是在一个局域网中虚拟一个局域网。我们其实只要知道:在一个局域网中,如果设置了vlan,那么主机只能同相同vlan号的主机进行通信。

在这里插入图片描述

接下来将使用packet tracer来进行模拟。先取出交换机,型号我们选用2960,以及三台PC。接着配置PC的ip地址和子网掩码。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

配置完上述的主机ip后,我们点击交换机,开始配置vlan。这里我再补充一下接口类型,有access和trunk两种,access类型是支持vlan,而trunk类型是允许所有的信息通过。

Switch>en          ##进入特权模式
Switch#conf t      ##进入全局配置模式
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#vlan 10   ##进入vlan 10
Switch(config-vlan)#name v10  ## 改名为v10
Switch(config-vlan)#end       ##保存并退出
Switch#
%SYS-5-CONFIG_I: Configured from console by console

Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#vlan 20
Switch(config-vlan)#name v20
Switch(config-vlan)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console

Switch#

改名了 vlan10 和 vlan 20 后,我们就将接口加入到vlan 中,接口默认都是vlan 1的,大家可以通过命令show vlan查看所有的接口以及vlan情况。

Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#int fa 0/1
Switch(config-if)#switchport access vlan 10  ##将fa 0/1端口设置vlan为10
Switch(config-if)#end                        ##退出并保存
Switch#
%SYS-5-CONFIG_I: Configured from console by console

Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#int fa 0/2
Switch(config-if)#switchport access vlan 20  ##将fa 0/2端口设置vlan为20
Switch(config-if)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console

Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#int fa 0/3
Switch(config-if)#switchport access vlan 10
Switch(config-if)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console

Switch#

配置完如图所示,理论来说PC0只能和PC2通信。
在这里插入图片描述
我们可以尝试一下,用PC0分别ping一下PC1和PC2 。
在这里插入图片描述

接下来我们将使用两台交换机,进行vlan实验,先按如下图配置ip并连接。

在这里插入图片描述
点击0号交换机,设置fa 0/4 接口为trunk,这样所有的信息都可以通过fa 0/4传入交换机1中。

Switch>en
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#int fa 0/4
Switch(config-if)#switchport mode trunk   ##将fa 0/4的模式改为trunk模式

Switch(config-if)#
%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

Switch(config-if)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console

Switch#

交换机1的设置和上面类似,也是先给接口设置vlan,然后把连接交换机的接口fa 0/3设置为trunk模式,我就不详细讲解了。

在这里插入图片描述
可以发现PC0只能ping得同相同vlan号的主机。至此第一个实验vlan配置已经完全结束了。

接下来我们进行下一个实验:静态路由配置。实验器材选择两台PC和两个2811的路由器。

在这里插入图片描述

         --- System Configuration Dialog ---
##有时候开机会有这些提示,一律选n就完事了
Would you like to enter the initial configuration dialog? [yes/no]: 
% Please answer 'yes' or 'no'.
Would you like to enter the initial configuration dialog? [yes/no]: n


Press RETURN to get started!



Router>

先按如下配置PC的地址和掩码。
在这里插入图片描述

我们先来讲一下路由器,路由器的作用是用来连接两个局域网,两个局域网那想必是有不同的网络号,此时路由器就根据端口连接的是哪个网络号来传递相应的信息。其实我们可以将路由器的端口看作是一台pc机,他拥有一个网络ip,负责与其他端口或者PC通信。

设置Route0路由器。

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#int fa 0/0
Router(config-if)#ip address 192.168.1.1 255.255.255.0  ##给fa 0/0接口设置ip以及子网掩码
Router(config-if)#no shutdown                           ##no shutdown命令开启端口,端口默认是关闭的
														##这里提供一个小知识,如果想要修改ip,先shutdown
Router(config-if)#										##该端口,再配置ip,然后再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

Router(config-if)#exit
Router(config)#int fa 0/1
Router(config-if)#ip address 192.168.2.1 255.255.255.0
Router(config-if)#no shutdown

Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up

Router(config-if)#exit
Router(config)#

接下来设置Route1路由器。

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#int fa 0/1
Router(config-if)#ip address 192.168.2.2 255.255.255.0
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)#int fa 0/0
Router(config-if)#ip address 192.168.3.1 255.255.255.0
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)#exit
Router(config)#

在这里插入图片描述

这里补充一下,可以发现,我们刚刚主机的网络号和所连上对端口的网络号是一致的,因为只有网络号一致才能进行通信。接下来我们要设置的pc默认网关其实就是pc所连接的路由器接口的网络号,因为该pc仅于一台路由器相连,要传输的数据都要经过该接口,但如果该局域网有多个路由器,那么就可以设置别的路由器接口为默认网关。

在这里插入图片描述
在这里插入图片描述
设置完两个pc的ip和默认网关后,我们就要开始配置静态路由表了。

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#ip route 192.168.3.0 255.255.255.0 192.168.2.2  ##该命令为设置下一跳,命令格式为ip route 目的网络号 目的子网掩码 下一跳的ip
Router(config)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console

Router#show ip route
Codes: L - local, C - connected, S - static, 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

     192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.1.0/24 is directly connected, FastEthernet0/0
L       192.168.1.1/32 is directly connected, FastEthernet0/0
     192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.2.0/24 is directly connected, FastEthernet0/1
L       192.168.2.1/32 is directly connected, FastEthernet0/1
S    192.168.3.0/24 [1/0] via 192.168.2.2

Router#

在这里插入图片描述

单单只是给Route0设置下一跳还不够,还要给Route1设置下一跳,这样信息才能往返收发。

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1
Router(config)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console

Router#

这样这个实验最基本部分算是讲完了,大家可以用PC0 ping 一下PC1看能不能成功。
在这里插入图片描述

大家可以根据上面的只是进行更高级的网络连接,比如三个路由器的网络。

在这里插入图片描述

在做真机实验时一定要记得关掉防火墙!!!不然很可能连上也ping不通!!!

其次,在真机实验中使用Hyper Terminal连接,选择的端口如下所示,波特率选择9600(这个看具体情况)

在这里插入图片描述

  • 10
    点赞
  • 50
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值