cisco常用命令详解

时间:2023-12-04 20:24:56

                    cisco常用命令详解

                                  作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.常用命令用法展示

1.命令行模式的来回切换

 yinzhengjie>enable         #从用户模式切换到特权模式,权限最低,可以说是无功能,啥也不能做。
yinzhengjie#     #特权模式,可以进行查看端口的IP配置信息,查看主机表等,重启路由器等等操作。 yinzhengjie#configure terminal   #从特权模式切换到全局配置模式,权限最高,可以在这里配置vlan等等
Enter configuration commands, one per line. End with CNTL/Z.
yinzhengjie(config)# yinzhengjie(config)#exit      #从全局配置模式切换到特权模式,如果想要切换到用户模式继续敲击exit即可。
yinzhengjie#
%SYS--CONFIG_I: Configured from console by console

3种模式的来回切换

2.修改主机名

 (config)#hostname yinzhengjie   #注意:需要在全局配置模式下敲击哟
yinzhengjie(config)#

全局配置模式下修改主机名

3.配置用户切换至特权模式的密码

 yinzhengjie(config)#enable password yinzhengjie  #配置在用户模式进入特权模式的密码是:yinzhengjie, 但是这种配置方法可以通过show  run来进行查看
yinzhengjie(config)# yinzhengjie>enable #验证过程,注意,
Password:
yinzhengjie# #可以在特权模式下查看你做了哪些配置
yinzhengjie#show run
Building configuration... Current configuration : bytes
!
version 12.2
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname yinzhengjie
!
!
!
enable password yinzhengjie #这个就是进入特权模式的密码

明文加密特权模式密码

 yinzhengjie(config)#enable secret yinzhengjie   #配置用户模式进入特权模式的密码,且是密文形式的,不会被show run看出来密码。
yinzhengjie(config)#exit
yinzhengjie#
%SYS--CONFIG_I: Configured from console by console yinzhengjie#show run
Building configuration... Current configuration : bytes
!
version 12.2
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname yinzhengjie
!
!
!
enable secret $$mERr$m71c3Gjeqb4tpumB3.jHY. #这种加密是无法被看到的哟

密文加密特权模式密码

4.查看命令用法

 yinzhengjie#show hosts         #查看主机表
Default Domain is not set
Name/address lookup uses domain service
Name servers are 255.255.255.255 Codes: UN - unknown, EX - expired, OK - OK, ?? - revalidate
temp - temporary, perm - permanent
NA - Not Applicable None - Not defined Host Port Flags Age Type Address(es)
yinzhengjie# yinzhengjie#show ip interface #查看端口的IP配置信息
FastEthernet0/ is administratively down, line protocol is down (disabled)
Internet protocol processing disabled
FastEthernet0/ is administratively down, line protocol is down (disabled)
Internet protocol processing disabled
yinzhengjie#

常用查询命令

5.VLAN的创建与删除

 yinzhengjie#vlan data   #进入VLAN配置模式
% Warning: It is recommended to configure VLAN from config mode,
as VLAN database mode is being deprecated. Please consult user
documentation for configuring VTP/VLAN in config mode. yinzhengjie(vlan)#vlan name test_1 #创建VLAN10并其名称为test_1
VLAN added: #输出信息,创建VLAN10
Name: test_1 #输出信息,名称为test_1
yinzhengjie(vlan)#vlan name test_2 #创建VLAN20
VLAN added:
Name: test_2
yinzhengjie(vlan)#vlan name test_3 #创建VLAN30
VLAN added:
Name: test_3
yinzhengjie(vlan) 思科VLAN的创建

VLAN的添加

 yinzhengjie#show vlan brief      #查看VLAN信息

 VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
default active Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
test_1 active #之前已经存在的VLAN
test_2 active #之前已经存在的VLAN
test_3 active #之前已经存在的VLAN
fddi-default active
token-ring-default active
fddinet-default active
trnet-default active
yinzhengjie#
yinzhengjie#vlan database #进入VLAN的配置模式
% Warning: It is recommended to configure VLAN from config mode,
as VLAN database mode is being deprecated. Please consult user
documentation for configuring VTP/VLAN in config mode. yinzhengjie(vlan)#no vlan #删除VLAN10
Deleting VLAN ...
yinzhengjie(vlan)#no vlan #删除VLAN20
Deleting VLAN ...
yinzhengjie(vlan)#exit
APPLY completed.
Exiting....
yinzhengjie#show vlan brief VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
default active Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
test_3 active #只剩下VLAN30了,10和20都被删除了
fddi-default active
token-ring-default active
fddinet-default active
trnet-default active
yinzhengjie#

VLAN的删除

6.将交换机的接口添加或删除到VLAN之中

 yinzhengjie#show vlan brief        #查看VLAN信息

 VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
default active Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
test_3 active #当前VLAN30是没用任何的接口在这个VLAN之中的
fddi-default active
token-ring-default active
fddinet-default active
trnet-default active
yinzhengjie#configure terminal
Enter configuration commands, one per line. End with CNTL/Z. yinzhengjie(config)#interface fastEthernet / #只进入f0/1接口
yinzhengjie(config-if)#switchport access vlan #将该接口下允许VLAN30通过
yinzhengjie(config-if)#exit #退出当前接口
yinzhengjie(config)#interface range fastEthernet /- #同时进入f0/2到f0/5的接口
yinzhengjie(config-if-range)#switchport access vlan #允许vlan30通过
yinzhengjie(config-if-range)#exit
yinzhengjie(config)#exit #退到特权模式中
yinzhengjie#
%SYS--CONFIG_I: Configured from console by console
yinzhengjie#show vlan brief VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
default active Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/
test_3 active Fa0/, Fa0/, Fa0/, Fa0/
Fa0/ #观察发现,f0/1到f0/5都从vlan1中跑到了vlan30中去了
fddi-default active
token-ring-default active
fddinet-default active
trnet-default active
yinzhengjie#

配置access口

 yinzhengjie#show vlan brief 

 VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
default active Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/
test_3 active Fa0/, Fa0/, Fa0/, Fa0/
Fa0/ #当前VLAN存在着5个接口
fddi-default active
token-ring-default active
fddinet-default active
trnet-default active
yinzhengjie#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
yinzhengjie(config)#interface range fastEthernet /- #同时进入f0/1到f0/5的接口之中
yinzhengjie(config-if-range)#no switchport access vlan #不允许vlan30通过
yinzhengjie(config-if-range)#exit
yinzhengjie(config)#exit
yinzhengjie#
%SYS--CONFIG_I: Configured from console by console yinzhengjie#show vlan brief VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
default active Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
Fa0/, Fa0/, Fa0/, Fa0/
test_3 active #该VLAN的接口全部被清空了,默认被情况的接口又回到了VLAN1中去了
fddi-default active
token-ring-default active
fddinet-default active
trnet-default active
yinzhengjie#

删除access口

7.配置vlan的管理IP

 yinzhengjie(config)#interface vlan  #在全局配置模式进入vlan接口
yinzhengjie(config-if)#
%LINK--CHANGED: Interface Vlan10, changed state to up %LINEPROTO--UPDOWN: Line protocol on Interface Vlan10, changed state to up yinzhengjie(config-if)#ip add 192.168.10.1 255.255.255.0 #配置管理IP
yinzhengjie(config-if)#

配置管理IP

 interface Vlan1
no ip address
shutdown
!
interface Vlan5
ip address 192.168.5.1 255.255.255.0
!
interface Vlan10
ip address 192.168.10.1 255.255.255.0 #我们查看当前是有IP地址的
!
line con
!
line vty
login
line vty
login
!
!
end
yinzhengjie#configure terminal #进入全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
yinzhengjie(config)#interface vlan #进入VLAN10的接口
yinzhengjie(config-if)#no ip address #情况当前vlan中的IP地址
yinzhengjie(config-if)#exit
yinzhengjie(config)#exit
yinzhengjie#
%SYS--CONFIG_I: Configured from console by console
s
% Ambiguous command: "s"
yinzhengjie#
yinzhengjie#show run #查看当前配置
Building configuration... Current configuration : bytes
!
version 12.1
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname yinzhengjie
!
!
spanning-tree mode pvst
!
interface FastEthernet0/
switchport access vlan
switchport mode trunk
!
interface FastEthernet0/
switchport access vlan
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface Vlan1
no ip address
shutdown
!
interface Vlan5
ip address 192.168.5.1 255.255.255.0
!
interface Vlan10
no ip address #此时我们发现IP被清空了
!
!
line con
!
line vty
login
line vty
login
!
!
end yinzhengjie#

删除管理IP

二.简单网络配置练习

小试牛刀:好了,学了以上的命令,我们一起来做一个简单的练习:

1.在交换机上划分vlan,将PC1、PC3加入到vlan2,PC2、PC4加入vlan3,并实现跨交换机的同vlan之间的通讯,如图-1所示:

cisco常用命令详解

pc0的cmd窗口测试结果如下:

 PC>ipconfig

 FastEthernet0 Connection:(default port)
Link-local IPv6 Address.........: FE80::20B:BEFF:FEC2:A4BD
IP Address......................: 192.168.5.10
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.5.1 PC>ping 192.168.5.1 #网关地址 Pinging 192.168.5.1 with bytes of data: Reply from 192.168.5.1: bytes= time=0ms TTL=
Reply from 192.168.5.1: bytes= time=0ms TTL= Ping statistics for 192.168.5.1:
Packets: Sent = , Received = , Lost = (% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms Control-C
^C
PC>ping 192.168.5.2 #右边的交换机 Pinging 192.168.5.2 with bytes of data: Reply from 192.168.5.2: bytes= time=0ms TTL= Ping statistics for 192.168.5.2:
Packets: Sent = , Received = , Lost = (% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms Control-C
^C
PC>ping 192.168.5.20 #右边的PC机器 Pinging 192.168.5.20 with bytes of data: Reply from 192.168.5.20: bytes= time=0ms TTL= Ping statistics for 192.168.5.20:
Packets: Sent = , Received = , Lost = (% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms Control-C
^C
PC>ping 192.168.10.1 Pinging 192.168.10.1 with bytes of data: Ping statistics for 192.168.10.1:
Packets: Sent = , Received = , Lost = (% loss), Control-C
^C
PC>ping 192.168.10.10 Pinging 192.168.10.10 with bytes of data: Ping statistics for 192.168.10.10:
Packets: Sent = , Received = , Lost = (% loss), Control-C
^C
PC>

PC0测试结果

pc1的cmd窗口测试结果如下:

 PC>
PC>ipconfig FastEthernet0 Connection:(default port)
Link-local IPv6 Address.........: FE80:::A3FF:FE0D:B465
IP Address......................: 192.168.10.10
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.10.1 PC>ping 192.168.10.1 #网关地址 Pinging 192.168.10.1 with bytes of data: Reply from 192.168.10.1: bytes= time=0ms TTL=
Reply from 192.168.10.1: bytes= time=0ms TTL= Ping statistics for 192.168.10.1:
Packets: Sent = , Received = , Lost = (% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms Control-C
^C
PC>ping 192.168.10.2 #右边交换机的网关地址 Pinging 192.168.10.2 with bytes of data: Reply from 192.168.10.2: bytes= time=1ms TTL= Ping statistics for 192.168.10.2:
Packets: Sent = , Received = , Lost = (% loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 1ms, Average = 1ms Control-C
^C
PC>ping 192.168.10.20 Pinging 192.168.10.20 with bytes of data: Reply from 192.168.10.20: bytes= time=0ms TTL=
Reply from 192.168.10.20: bytes= time=0ms TTL=
Reply from 192.168.10.20: bytes= time=0ms TTL=
Reply from 192.168.10.20: bytes= time=1ms TTL= Ping statistics for 192.168.10.20:
Packets: Sent = , Received = , Lost = (% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms PC>
PC>ping 192.168.5.1 Pinging 192.168.5.1 with bytes of data: Ping statistics for 192.168.5.1:
Packets: Sent = , Received = , Lost = (% loss), Control-C
^C
PC>ping 192.168.5.2 Pinging 192.168.5.2 with bytes of data: Ping statistics for 192.168.5.2:
Packets: Sent = , Received = , Lost = (% loss), Control-C
^C
PC>ping 192.168.5.20 Pinging 192.168.5.20 with bytes of data: Ping statistics for 192.168.5.20:
Packets: Sent = , Received = , Lost = (% loss), Control-C
^C
PC>

pc1测试结果

左边交换机的配置如下:

 Switch#show run
Building configuration... Current configuration : bytes
!
version 12.1
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Switch
!
!
spanning-tree mode pvst
!
interface FastEthernet0/
!
interface FastEthernet0/
switchport access vlan
!
interface FastEthernet0/
switchport access vlan
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
switchport mode trunk
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface Vlan1
no ip address
shutdown
!
interface Vlan2
ip address 192.168.5.1 255.255.255.0
!
interface Vlan3
ip address 192.168.10.1 255.255.255.0
!
!
line con
!
line vty
login
line vty
login
!
!
end Switch#

switch3配置信息

右边交换机的配置如下:

 Switch#show running-config
Building configuration... Current configuration : bytes
!
version 12.1
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Switch
!
!
spanning-tree mode pvst
!
interface FastEthernet0/
!
interface FastEthernet0/
switchport access vlan
!
interface FastEthernet0/
switchport access vlan
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
switchport mode trunk
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface FastEthernet0/
!
interface Vlan1
no ip address
shutdown
!
interface Vlan2
ip address 192.168.5.2 255.255.255.0
!
interface Vlan3
ip address 192.168.10.2 255.255.255.0
!
interface Vlan10
no ip address
!
interface Vlan20
no ip address
!
!
line con
!
line vty
login
line vty
login
!
!
end Switch#

switch1配置信息

  实现过程其实很简单只需要分别在2个交换机上创建相同的vlan,然后讲两个交换机相连的口设置为trunk口,将pc机遇交换机的直连的端口设置为access口即可。这样就实现了2个交换机中相同VLAN可以互通不同VLAM不能互通的功能,但是如果你非要让同一个交换机中的2个VLAN互通的话其实也可以的,需要在三层交换机上开启路由功能,注意:这个功能傻瓜交换机是不支持的哟!所以你要在实际生产环境中要考虑你的设备是否支持该功能哟。再去考虑交互机VLAN互通的问题。

2.配置DHCP服务器

在路由器上配置DHCP服务为客户端自动分配IP地址架构图如下:

cisco常用命令详解

我是在路由器上做的配置,让路由器当DHCP服务器,配置过程如下:

 yinzhengjie>en  #进入特权模式
yinzhengjie#configure terminal #进入全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
yinzhengjie(config)#interface fastEthernet 0/0 #进入接入的网口地址
yinzhengjie(config-if)#ip address 172.16.1.254 255.255.255.0 #为该网口配置一个网管地址
yinzhengjie(config-if)#no shutdown #开启这个端口 yinzhengjie(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 yinzhengjie(config)#ip dhcp pool wancheng #添加一个地址池起别名为“wancheng”
yinzhengjie(dhcp-config)#network 172.16.1.0 255.255.255.0 #分配地址池
yinzhengjie(dhcp-config)#default-router 172.16.1.254 #指定分配地址的网关地址
yinzhengjie(dhcp-config)#dns-server 219.141.136.10 #配置DNS服务器
yinzhengjie(dhcp-config)#exit #退出DHCP配置模式
yinzhengjie(config)#ip dhcp excluded-address 172.16.1.1 172.16.1.100 #配置预留的IP,意思是从172.16.1.1~172.16.1.100都不分配
yinzhengjie(config)#

路由器的配置过程

测试结果如下:

pc0:

cisco常用命令详解

pc1:

cisco常用命令详解

在路由器上查看目前分配IP地址的情况如下:

 yinzhengjie#show run   #查看配置
Building configuration... Current configuration : 602 bytes
!
version 12.2
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname yinzhengjie
!
!
!
!
ip dhcp excluded-address 172.16.1.1 172.16.1.100
!
ip dhcp pool wancheng #DHCP配置信息
network 172.16.1.0 255.255.255.0
default-router 172.16.1.254
dns-server 219.141.136.10
!
!
!
!
!
!
!
!
!
!
!
!
!
interface FastEthernet0/0
ip address 172.16.1.254 255.255.255.0
duplex auto
speed auto
!
interface FastEthernet0/1
no ip address
duplex auto
speed auto
shutdown
!
ip classless
!
!
!
!
!
!
!
line con 0
!
line aux 0
!
line vty 0 4
login
!
!
!
end yinzhengjie#show ip dhcp binding #查看当前地址的在线情况
IP address Client-ID/ Lease expiration Type
Hardware address
172.16.1.101 00E0.A357.0E96 -- Automatic
172.16.1.102 0009.7C6D.C274 -- Automatic
yinzhengjie#

查看当前地址的在线情况

3.单臂路由配置

要求VLAN20和VLAN30可以互相访问,需要在交换机设置access口(与pc机器相连)和trunk口(与路由相连)

cisco常用命令详解

pc0测试环境如下:

 PC>ipconfig   #查看本机地址

 FastEthernet0 Connection:(default port)
Link-local IPv6 Address.........: FE80::2D0:BAFF:FEE4:777E
IP Address......................: 192.168.20.1
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.20.254 PC>ping 192.168.20.2 #vlan20的另外一台pc1 Pinging 192.168.20.2 with 32 bytes of data: Reply from 192.168.20.2: bytes=32 time=0ms TTL=128
Reply from 192.168.20.2: bytes=32 time=0ms TTL=128
Reply from 192.168.20.2: bytes=32 time=0ms TTL=128
Reply from 192.168.20.2: bytes=32 time=0ms TTL=128 Ping statistics for 192.168.20.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms PC>ping 172.16.30.254 #vlan30的网关地址 Pinging 172.16.30.254 with 32 bytes of data: Reply from 172.16.30.254: bytes=32 time=1ms TTL=255
Reply from 172.16.30.254: bytes=32 time=1ms TTL=255
Reply from 172.16.30.254: bytes=32 time=0ms TTL=255
Reply from 172.16.30.254: bytes=32 time=0ms TTL=255 Ping statistics for 172.16.30.254:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms PC>ping 172.16.30.1 #VLAN30的机器 Pinging 172.16.30.1 with 32 bytes of data: Request timed out.
Reply from 172.16.30.1: bytes=32 time=0ms TTL=127
Reply from 172.16.30.1: bytes=32 time=0ms TTL=127
Reply from 172.16.30.1: bytes=32 time=0ms TTL=127 Ping statistics for 172.16.30.1:
Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms PC>

pc0测试结果

交换机配置如下:

 yinzhengjie>en
yinzhengjie#vlan database
% Warning: It is recommended to configure VLAN from config mode,
as VLAN database mode is being deprecated. Please consult user
documentation for configuring VTP/VLAN in config mode. yinzhengjie(vlan)#vlan 20 name test_1
VLAN 20 added:
Name: test_1
yinzhengjie(vlan)#vlan 30 name test_2
VLAN 30 added:
Name: test_2
yinzhengjie(vlan)#exit
APPLY completed.
Exiting....
yinzhengjie#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
yinzhengjie(config)#interface range fastEthernet 0/1-2
yinzhengjie(config-if-range)#switchport access vlan 20
yinzhengjie(config-if-range)#exit
yinzhengjie(config)#interface range fastEthernet 0/3-4
yinzhengjie(config-if-range)#switchport access vlan 30
yinzhengjie(config-if-range)#exit
yinzhengjie(config)#interface fastEthernet 0/10
yinzhengjie(config-if)#switchport mode trunk yinzhengjie(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/10, changed state to down %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/10, changed state to up yinzhengjie(config-if)#
yinzhengjie(config-if)#
yinzhengjie(config-if)#

交换机配置过程

 yinzhengjie#show run
Building configuration... Current configuration : 1107 bytes
!
version 12.1
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname yinzhengjie
!
!
spanning-tree mode pvst
!
interface FastEthernet0/1
switchport access vlan 20
!
interface FastEthernet0/2
switchport access vlan 20
!
interface FastEthernet0/3
switchport access vlan 30
!
interface FastEthernet0/4
switchport access vlan 30
!
interface FastEthernet0/5
!
interface FastEthernet0/6
!
interface FastEthernet0/7
!
interface FastEthernet0/8
!
interface FastEthernet0/9
!
interface FastEthernet0/10
switchport mode trunk
!
interface FastEthernet0/11
!
interface FastEthernet0/12
!
interface FastEthernet0/13
!
interface FastEthernet0/14
!
interface FastEthernet0/15
!
interface FastEthernet0/16
!
interface FastEthernet0/17
!
interface FastEthernet0/18
!
interface FastEthernet0/19
!
interface FastEthernet0/20
!
interface FastEthernet0/21
!
interface FastEthernet0/22
!
interface FastEthernet0/23
!
interface FastEthernet0/24
!
interface Vlan1
no ip address
shutdown
!
!
line con 0
!
line vty 0 4
login
line vty 5 15
login
!
!
end yinzhengjie#

交换机的配置信息

路由器配置如下:

 yinzhengjie#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
yinzhengjie(config)#interface fastEthernet 0/0
yinzhengjie(config-if)#no shutdown
yinzhengjie(config-if)#exit
yinzhengjie(config)#interface fastEthernet 0/0.1
yinzhengjie(config-subif)#encapsulation dot1Q 20 #配置trunk的封装协议,如果不配置会无法配置成功IP地址的哟~
yinzhengjie(config-subif)#ip address 192.168.20.254 255.255.255.0
yinzhengjie(config-subif)#exit
yinzhengjie(config)#interface fastEthernet 0/0.2
yinzhengjie(config-subif)#encapsulation dot1Q 30
yinzhengjie(config-subif)#ip address 172.16.30.254 255.255.255.0
yinzhengjie(config-subif)#exit
yinzhengjie(config)#exit
yinzhengjie#
%SYS-5-CONFIG_I: Configured from console by console yinzhengjie#show run
Building configuration... Current configuration : 528 bytes
!
version 12.2
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname yinzhengjie
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
interface FastEthernet0/0
no ip address
duplex auto
speed auto
!
interface FastEthernet0/0.1
encapsulation dot1Q 20
ip address 192.168.20.254 255.255.255.0
!
interface FastEthernet0/0.2
encapsulation dot1Q 30
ip address 172.16.30.254 255.255.255.0
!
ip classless
!
!
!
!
!
!
!
line con 0
!
line aux 0
!
line vty 0 4
login
!
!
!
end yinzhengjie# ‘’‘
扩充:
1:在路由器上配置trunk的封装协议的命令:
encapsulation [isl/dot1q] vlan#
2:上面的路由器配置了dot1q中继封装,20是vlan 20。
3:Trunk的封装类型一共有 ISL和802.1Q两种,而802.1Q在输入的时候则为dot1q ’‘’

路由器配置过程

 yinzhengjie#show run
Building configuration... Current configuration : 528 bytes
!
version 12.2
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname yinzhengjie
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
interface FastEthernet0/0
no ip address
duplex auto
speed auto
!
interface FastEthernet0/0.1
encapsulation dot1Q 20
ip address 192.168.20.254 255.255.255.0
!
interface FastEthernet0/0.2
encapsulation dot1Q 30
ip address 172.16.30.254 255.255.255.0
!
ip classless
!
!
!
!
!
!
!
line con 0
!
line aux 0
!
line vty 0 4
login
!
!
!
end yinzhengjie#

路由器的配置信息

4.如下图所示,通过动态路由RIP实现三个路由器之间的全网互通。

cisco常用命令详解

pc0测试结果如下:

 PC>
PC>ping 192.168.1.254 #网关地址 Pinging 192.168.1.254 with 32 bytes of data: Reply from 192.168.1.254: bytes=32 time=1ms TTL=255
Reply from 192.168.1.254: bytes=32 time=1ms TTL=255
Reply from 192.168.1.254: bytes=32 time=0ms TTL=255
Reply from 192.168.1.254: bytes=32 time=1ms TTL=255 Ping statistics for 192.168.1.254:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms PC>ping 192.168.2.1 #路由器0/1地址 Pinging 192.168.2.1 with 32 bytes of data: Reply from 192.168.2.1: bytes=32 time=1ms TTL=255
Reply from 192.168.2.1: bytes=32 time=0ms TTL=255
Reply from 192.168.2.1: bytes=32 time=0ms TTL=255
Reply from 192.168.2.1: bytes=32 time=0ms TTL=255 Ping statistics for 192.168.2.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms PC>ping 192.168.3.1 #中间路由地址 Pinging 192.168.3.1 with 32 bytes of data: Reply from 192.168.3.1: bytes=32 time=1ms TTL=254
Reply from 192.168.3.1: bytes=32 time=0ms TTL=254
Reply from 192.168.3.1: bytes=32 time=2ms TTL=254
Reply from 192.168.3.1: bytes=32 time=0ms TTL=254 Ping statistics for 192.168.3.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 2ms, Average = 0ms PC>ping 192.168.4.1 #pc1机器地址 Pinging 192.168.4.1 with 32 bytes of data: Reply from 192.168.4.1: bytes=32 time=11ms TTL=125
Reply from 192.168.4.1: bytes=32 time=1ms TTL=125
Reply from 192.168.4.1: bytes=32 time=0ms TTL=125
Reply from 192.168.4.1: bytes=32 time=0ms TTL=125 Ping statistics for 192.168.4.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 11ms, Average = 3ms PC>

pc测试结果

路由器配置信息

 yinzhengjie(config)#interface fastEthernet 0/0
yinzhengjie(config-if)#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
yinzhengjie(config-if)#ip address 192.168.1.254 255.255.255.0
yinzhengjie(config-if)#exit
yinzhengjie(config)#interface fastEthernet 0/1
yinzhengjie(config-if)#no shutdown
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
yinzhengjie(config-if)#ip address 192.168.2.1 255.255.255.0
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
yinzhengjie(config-if)#ex
yinzhengjie(config)#router rip #进入动态路由配置模式
yinzhengjie(config-router)#version 2
yinzhengjie(config-router)#no auto-summary
yinzhengjie(config-router)#network 192.168.1.0 #与路由直连网段
yinzhengjie(config-router)#network 192.168.2.0 #与路由直连网段
yinzhengjie#show run
Building configuration... Current configuration : 538 bytes
!
version 12.2
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname yinzhengjie
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
interface FastEthernet0/0
ip address 192.168.1.254 255.255.255.0
duplex auto
speed auto
!
interface FastEthernet0/1
ip address 192.168.2.1 255.255.255.0
duplex auto
speed auto
!
router rip
version 2
network 192.168.1.0
network 192.168.2.0
no auto-summary
!
ip classless
!
!
!
!
!
!
!
line con 0
!
line aux 0
!
line vty 0 4
login
!
!
!
end yinzhengjie#

Route0配置过程

 Router>en
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface fastEthernet 0/0
Router(config-if)#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)#ip address 192.168.2.2 255.255.255.0
Router(config-if)#exit
Router(config)#interface fastEthernet 0/1
Router(config-if)#no shutdown Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
Router(config-if)#ip address 192.168.3.1 255.255.255.0
Router(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up Router(config-if)#ex
Router(config)#router rip
Router(config-router)#version 2
Router(config-router)#no auto-summary
Router(config-router)#network 192.168.2.0
Router(config-router)#network 192.168.3.0
Router(config-router)#

Route1配置过程

 yinzhengjie(config)#interface fastEthernet 0/0
yinzhengjie(config-if)#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
yinzhengjie(config-if)#ip address 192.168.3.2 255.255.255.0
yinzhengjie(config-if)#exit
yinzhengjie(config)#interface fastEthernet 0/1
yinzhengjie(config-if)#no shutdown
yinzhengjie(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
yinzhengjie(config-if)#ip address 192.168.4.254 255.255.255.0
yinzhengjie(config-if)#exit
yinzhengjie(config)#router rip
yinzhengjie(config-router)#version 2
yinzhengjie(config-router)#no auto-summary
yinzhengjie(config-router)#network 192.168.3.0
yinzhengjie(config-router)#network 192.168.4.0
yinzhengjie(config-router)#

Route2配置过程