思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版),cisco常用命令详解

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

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

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

2.修改主机名

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

1 123(config)#hostname yinzhengjie #注意:需要在全局配置模式下敲击哟
2 yinzhengjie(config)#
全局配置模式下修改主机名

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

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 yinzhengjie(config)#enable password yinzhengjie #配置在用户模式进入特权模式的密码是:yinzhengjie, 但是这种配置方法可以通过show run来进行查看
 2 yinzhengjie(config)#
 4 yinzhengjie enable #验证过程,注意,
 5 Password: 
 6 yinzhengjie#
10 #可以在特权模式下查看你做了哪些配置
11 yinzhengjie#show run
12 Building configuration...
14 Current configuration : 457 bytes
16 version 12.2
17 no service timestamps log datetime msec
18 no service timestamps debug datetime msec
19 no service password-encryption
21 hostname yinzhengjie
25 enable password yinzhengjie #这个就是进入特权模式的密码
明文加密特权模式密码

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

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

4.查看命令用法

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 yinzhengjie#show hosts #查看主机表
 2 Default Domain is not set
 3 Name/address lookup uses domain service
 4 Name servers are 255.255.255.255
 6 Codes: UN - unknown, EX - expired, OK - OK, ?? - revalidate
 7 temp - temporary, perm - permanent
 8 NA - Not Applicable None - Not defined
10 Host Port Flags Age Type Address(es)
11 yinzhengjie#
13 yinzhengjie#show ip interface #查看端口的IP配置信息 
14 FastEthernet0/0 is administratively down, line protocol is down (disabled)
15 Internet protocol processing disabled
16 FastEthernet0/1 is administratively down, line protocol is down (disabled)
17 Internet protocol processing disabled
18 yinzhengjie# 
常用查询命令

5.VLAN的创建与删除

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 yinzhengjie#vlan data #进入VLAN配置模式
 2 % Warning: It is recommended to configure VLAN from config mode,
 3 as VLAN database mode is being deprecated. Please consult user
 4 documentation for configuring VTP/VLAN in config mode.
 6 yinzhengjie(vlan)#vlan 10 name test_1 #创建VLAN10并其名称为test_1
 7 VLAN 10 added: #输出信息,创建VLAN10
 8 Name: test_1 #输出信息,名称为test_1
 9 yinzhengjie(vlan)#vlan 20 name test_2 #创建VLAN20
10 VLAN 20 added:
11 Name: test_2 
12 yinzhengjie(vlan)#vlan 30 name test_3 #创建VLAN30
13 VLAN 30 added:
14 Name: test_3
15 yinzhengjie(vlan)
17 思科VLAN的创建
VLAN的添加

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 yinzhengjie#show vlan brief #查看VLAN信息
 3 VLAN Name Status Ports
 4 ---- -------------------------------- --------- -------------------------------
 5 1 default active Fa0/1, Fa0/2, Fa0/3, Fa0/4
 6 Fa0/5, Fa0/6, Fa0/7, Fa0/8
 7 Fa0/9, Fa0/10, Fa0/11, Fa0/12
 8 Fa0/13, Fa0/14, Fa0/15, Fa0/16
 9 Fa0/17, Fa0/18, Fa0/19, Fa0/20
10 Fa0/21, Fa0/22, Fa0/23, Fa0/24
11 10 test_1 active #之前已经存在的VLAN
12 20 test_2 active #之前已经存在的VLAN
13 30 test_3 active #之前已经存在的VLAN
14 1002 fddi-default active 
15 1003 token-ring-default active 
16 1004 fddinet-default active 
17 1005 trnet-default active 
18 yinzhengjie#
19 yinzhengjie#vlan database #进入VLAN的配置模式
20 % Warning: It is recommended to configure VLAN from config mode,
21 as VLAN database mode is being deprecated. Please consult user
22 documentation for configuring VTP/VLAN in config mode.
24 yinzhengjie(vlan)#no vlan 10 #删除VLAN10
25 Deleting VLAN 10...
26 yinzhengjie(vlan)#no vlan 20 #删除VLAN20
27 Deleting VLAN 20...
28 yinzhengjie(vlan)#exit 
29 APPLY completed.
30 Exiting....
31 yinzhengjie#show vlan brief 
33 VLAN Name Status Ports
34 ---- -------------------------------- --------- -------------------------------
35 1 default active Fa0/1, Fa0/2, Fa0/3, Fa0/4
36 Fa0/5, Fa0/6, Fa0/7, Fa0/8
37 Fa0/9, Fa0/10, Fa0/11, Fa0/12
38 Fa0/13, Fa0/14, Fa0/15, Fa0/16
39 Fa0/17, Fa0/18, Fa0/19, Fa0/20
40 Fa0/21, Fa0/22, Fa0/23, Fa0/24
41 30 test_3 active #只剩下VLAN30了,10和20都被删除了
42 1002 fddi-default active 
43 1003 token-ring-default active 
44 1004 fddinet-default active 
45 1005 trnet-default active 
46 yinzhengjie#
VLAN的删除

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

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 yinzhengjie#show vlan brief #查看VLAN信息
 3 VLAN Name Status Ports
 4 ---- -------------------------------- --------- -------------------------------
 5 1 default active Fa0/1, Fa0/2, Fa0/3, Fa0/4
 6 Fa0/5, Fa0/6, Fa0/7, Fa0/8
 7 Fa0/9, Fa0/10, Fa0/11, Fa0/12
 8 Fa0/13, Fa0/14, Fa0/15, Fa0/16
 9 Fa0/17, Fa0/18, Fa0/19, Fa0/20
10 Fa0/21, Fa0/22, Fa0/23, Fa0/24
11 30 test_3 active #当前VLAN30是没用任何的接口在这个VLAN之中的
12 1002 fddi-default active 
13 1003 token-ring-default active 
14 1004 fddinet-default active 
15 1005 trnet-default active 
16 yinzhengjie#configure terminal 
17 Enter configuration commands, one per line. End with CNTL/Z.
19 yinzhengjie(config)#interface fastEthernet 0/1 #只进入f0/1接口
20 yinzhengjie(config-if)#switchport access vlan 30 #将该接口下允许VLAN30通过
21 yinzhengjie(config-if)#exit #退出当前接口
22 yinzhengjie(config)#interface range fastEthernet 0/2-5 #同时进入f0/2到f0/5的接口
23 yinzhengjie(config-if-range)#switchport access vlan 30 #允许vlan30通过
24 yinzhengjie(config-if-range)#exit 
25 yinzhengjie(config)#exit #退到特权模式中
26 yinzhengjie#
27 %SYS-5-CONFIG_I: Configured from console by console
28 yinzhengjie#show vlan brief 
30 VLAN Name Status Ports
31 ---- -------------------------------- --------- -------------------------------
32 1 default active Fa0/6, Fa0/7, Fa0/8, Fa0/9
33 Fa0/10, Fa0/11, Fa0/12, Fa0/13
34 Fa0/14, Fa0/15, Fa0/16, Fa0/17
35 Fa0/18, Fa0/19, Fa0/20, Fa0/21
36 Fa0/22, Fa0/23, Fa0/24
37 30 test_3 active Fa0/1, Fa0/2, Fa0/3, Fa0/4
38 Fa0/5 #观察发现,f0/1到f0/5都从vlan1中跑到了vlan30中去了
39 1002 fddi-default active 
40 1003 token-ring-default active 
41 1004 fddinet-default active 
42 1005 trnet-default active 
43 yinzhengjie#
配置access口

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 yinzhengjie#show vlan brief 
 3 VLAN Name Status Ports
 4 ---- -------------------------------- --------- -------------------------------
 5 1 default active Fa0/6, Fa0/7, Fa0/8, Fa0/9
 6 Fa0/10, Fa0/11, Fa0/12, Fa0/13
 7 Fa0/14, Fa0/15, Fa0/16, Fa0/17
 8 Fa0/18, Fa0/19, Fa0/20, Fa0/21
 9 Fa0/22, Fa0/23, Fa0/24
10 30 test_3 active Fa0/1, Fa0/2, Fa0/3, Fa0/4
11 Fa0/5 #当前VLAN存在着5个接口
12 1002 fddi-default active 
13 1003 token-ring-default active 
14 1004 fddinet-default active 
15 1005 trnet-default active 
16 yinzhengjie#configure terminal 
17 Enter configuration commands, one per line. End with CNTL/Z.
18 yinzhengjie(config)#interface range fastEthernet 0/1-5 #同时进入f0/1到f0/5的接口之中
19 yinzhengjie(config-if-range)#no switchport access vlan 30 #不允许vlan30通过
20 yinzhengjie(config-if-range)#exit 
21 yinzhengjie(config)#exit 
22 yinzhengjie#
23 %SYS-5-CONFIG_I: Configured from console by console
25 yinzhengjie#show vlan brief 
27 VLAN Name Status Ports
28 ---- -------------------------------- --------- -------------------------------
29 1 default active Fa0/1, Fa0/2, Fa0/3, Fa0/4
30 Fa0/5, Fa0/6, Fa0/7, Fa0/8
31 Fa0/9, Fa0/10, Fa0/11, Fa0/12
32 Fa0/13, Fa0/14, Fa0/15, Fa0/16
33 Fa0/17, Fa0/18, Fa0/19, Fa0/20
34 Fa0/21, Fa0/22, Fa0/23, Fa0/24
35 30 test_3 active #该VLAN的接口全部被清空了,默认被情况的接口又回到了VLAN1中去了
36 1002 fddi-default active 
37 1003 token-ring-default active 
38 1004 fddinet-default active 
39 1005 trnet-default active 
40 yinzhengjie#
删除access口

 7.配置vlan的管理IP

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

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

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 interface Vlan1
 2 no ip address
 3 shutdown
 5 interface Vlan5
 6 ip address 192.168.5.1 255.255.255.0
 8 interface Vlan10
 9 ip address 192.168.10.1 255.255.255.0 #我们查看当前是有IP地址的
 10 !
 11 line con 0
 12 !
 13 line vty 0 4
 14 login
 15 line vty 5 15
 16 login
 17 !
 18 !
 19 end
 20 yinzhengjie#configure terminal #进入全局配置模式
 21 Enter configuration commands, one per line. End with CNTL/Z.
 22 yinzhengjie(config)#interface vlan 10 #进入VLAN10的接口
 23 yinzhengjie(config-if)#no ip address #情况当前vlan中的IP地址
 24 yinzhengjie(config-if)#exit 
 25 yinzhengjie(config)#exit 
 26 yinzhengjie#
 27 %SYS-5-CONFIG_I: Configured from console by console
 28 s
 29 % Ambiguous command: "s"
 30 yinzhengjie#
 31 yinzhengjie#show run #查看当前配置
 32 Building configuration...
 34 Current configuration : 1142 bytes
 35 !
 36 version 12.1
 37 no service timestamps log datetime msec
 38 no service timestamps debug datetime msec
 39 no service password-encryption
 40 !
 41 hostname yinzhengjie
 42 !
 43 !
 44 spanning-tree mode pvst
 45 !
 46 interface FastEthernet0/1
 47 switchport access vlan 5
 48 switchport mode trunk
 49 !
 50 interface FastEthernet0/2
 51 switchport access vlan 10
 52 !
 53 interface FastEthernet0/3
 54 !
 55 interface FastEthernet0/4
 56 !
 57 interface FastEthernet0/5
 58 !
 59 interface FastEthernet0/6
 60 !
 61 interface FastEthernet0/7
 62 !
 63 interface FastEthernet0/8
 64 !
 65 interface FastEthernet0/9
 66 !
 67 interface FastEthernet0/10
 68 !
 69 interface FastEthernet0/11
 70 !
 71 interface FastEthernet0/12
 72 !
 73 interface FastEthernet0/13
 74 !
 75 interface FastEthernet0/14
 76 !
 77 interface FastEthernet0/15
 78 !
 79 interface FastEthernet0/16
 80 !
 81 interface FastEthernet0/17
 82 !
 83 interface FastEthernet0/18
 84 !
 85 interface FastEthernet0/19
 86 !
 87 interface FastEthernet0/20
 88 !
 89 interface FastEthernet0/21
 90 !
 91 interface FastEthernet0/22
 92 !
 93 interface FastEthernet0/23
 94 !
 95 interface FastEthernet0/24
 96 !
 97 interface Vlan1
 98 no ip address
 99 shutdown
100 !
101 interface Vlan5
102 ip address 192.168.5.1 255.255.255.0
103 !
104 interface Vlan10
105 no ip address #此时我们发现IP被清空了
106 !
107 !
108 line con 0
109 !
110 line vty 0 4
111 login
112 line vty 5 15
113 login
114 !
115 !
116 end
119 yinzhengjie#
删除管理IP

 

二.简单网络配置练习

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

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

思科命令,思科命令大全(完整版)

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

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 PC ipconfig
 3 FastEthernet0 Connection:(default port)
 4 Link-local IPv6 Address.........: FE80::20B:BEFF:FEC2:A4BD
 5 IP Address......................: 192.168.5.10
 6 Subnet Mask.....................: 255.255.255.0
 7 Default Gateway.................: 192.168.5.1
 9 PC ping 192.168.5.1 #网关地址
11 Pinging 192.168.5.1 with 32 bytes of data:
13 Reply from 192.168.5.1: bytes=32 time=0ms TTL=255
14 Reply from 192.168.5.1: bytes=32 time=0ms TTL=255
16 Ping statistics for 192.168.5.1:
17 Packets: Sent = 2, Received = 2, Lost = 0 (0% loss),
18 Approximate round trip times in milli-seconds:
19 Minimum = 0ms, Maximum = 0ms, Average = 0ms
21 Control-C
22 ^C
23 PC ping 192.168.5.2 #右边的交换机
25 Pinging 192.168.5.2 with 32 bytes of data:
27 Reply from 192.168.5.2: bytes=32 time=0ms TTL=255
29 Ping statistics for 192.168.5.2:
30 Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
31 Approximate round trip times in milli-seconds:
32 Minimum = 0ms, Maximum = 0ms, Average = 0ms
34 Control-C
35 ^C
36 PC ping 192.168.5.20 #右边的PC机器
38 Pinging 192.168.5.20 with 32 bytes of data:
40 Reply from 192.168.5.20: bytes=32 time=0ms TTL=128
42 Ping statistics for 192.168.5.20:
43 Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
44 Approximate round trip times in milli-seconds:
45 Minimum = 0ms, Maximum = 0ms, Average = 0ms
47 Control-C
48 ^C
49 PC ping 192.168.10.1
51 Pinging 192.168.10.1 with 32 bytes of data:
54 Ping statistics for 192.168.10.1:
55 Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
57 Control-C
58 ^C
59 PC ping 192.168.10.10
61 Pinging 192.168.10.10 with 32 bytes of data:
64 Ping statistics for 192.168.10.10:
65 Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
67 Control-C
68 ^C
69 PC 
PC0测试结果

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

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 PC 
 2 PC ipconfig
 4 FastEthernet0 Connection:(default port)
 5 Link-local IPv6 Address.........: FE80::230:A3FF:FE0D:B465
 6 IP Address......................: 192.168.10.10
 7 Subnet Mask.....................: 255.255.255.0
 8 Default Gateway.................: 192.168.10.1
10 PC ping 192.168.10.1 #网关地址
12 Pinging 192.168.10.1 with 32 bytes of data:
14 Reply from 192.168.10.1: bytes=32 time=0ms TTL=255
15 Reply from 192.168.10.1: bytes=32 time=0ms TTL=255
17 Ping statistics for 192.168.10.1:
18 Packets: Sent = 2, Received = 2, Lost = 0 (0% loss),
19 Approximate round trip times in milli-seconds:
20 Minimum = 0ms, Maximum = 0ms, Average = 0ms
22 Control-C
23 ^C
24 PC ping 192.168.10.2 #右边交换机的网关地址
26 Pinging 192.168.10.2 with 32 bytes of data:
28 Reply from 192.168.10.2: bytes=32 time=1ms TTL=255
30 Ping statistics for 192.168.10.2:
31 Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
32 Approximate round trip times in milli-seconds:
33 Minimum = 1ms, Maximum = 1ms, Average = 1ms
35 Control-C
36 ^C
37 PC ping 192.168.10.20
39 Pinging 192.168.10.20 with 32 bytes of data:
41 Reply from 192.168.10.20: bytes=32 time=0ms TTL=128
42 Reply from 192.168.10.20: bytes=32 time=0ms TTL=128
43 Reply from 192.168.10.20: bytes=32 time=0ms TTL=128
44 Reply from 192.168.10.20: bytes=32 time=1ms TTL=128
46 Ping statistics for 192.168.10.20:
47 Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
48 Approximate round trip times in milli-seconds:
49 Minimum = 0ms, Maximum = 1ms, Average = 0ms
51 PC 
52 PC ping 192.168.5.1
54 Pinging 192.168.5.1 with 32 bytes of data:
57 Ping statistics for 192.168.5.1:
58 Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
60 Control-C
61 ^C
62 PC ping 192.168.5.2
64 Pinging 192.168.5.2 with 32 bytes of data:
67 Ping statistics for 192.168.5.2:
68 Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
70 Control-C
71 ^C
72 PC ping 192.168.5.20
74 Pinging 192.168.5.20 with 32 bytes of data:
77 Ping statistics for 192.168.5.20:
78 Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
80 Control-C
81 ^C
82 PC 
pc1测试结果

左边交换机的配置如下:

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 Switch#show run
 2 Building configuration...
 4 Current configuration : 1159 bytes
 6 version 12.1
 7 no service timestamps log datetime msec
 8 no service timestamps debug datetime msec
 9 no service password-encryption
11 hostname Switch
14 spanning-tree mode pvst
16 interface FastEthernet0/1
18 interface FastEthernet0/2
19 switchport access vlan 2
21 interface FastEthernet0/3
22 switchport access vlan 3
24 interface FastEthernet0/4
26 interface FastEthernet0/5
28 interface FastEthernet0/6
30 interface FastEthernet0/7
32 interface FastEthernet0/8
34 interface FastEthernet0/9
36 interface FastEthernet0/10
37 switchport mode trunk
39 interface FastEthernet0/11
41 interface FastEthernet0/12
43 interface FastEthernet0/13
45 interface FastEthernet0/14
47 interface FastEthernet0/15
49 interface FastEthernet0/16
51 interface FastEthernet0/17
53 interface FastEthernet0/18
55 interface FastEthernet0/19
57 interface FastEthernet0/20
59 interface FastEthernet0/21
61 interface FastEthernet0/22
63 interface FastEthernet0/23
65 interface FastEthernet0/24
67 interface Vlan1
68 no ip address
69 shutdown
71 interface Vlan2
72 ip address 192.168.5.1 255.255.255.0
74 interface Vlan3
75 ip address 192.168.10.1 255.255.255.0
78 line con 0
80 line vty 0 4
81 login
82 line vty 5 15
83 login
86 end
89 Switch# 
switch3配置信息

右边交换机的配置如下:

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 Switch#show running-config 
 2 Building configuration...
 4 Current configuration : 1227 bytes
 6 version 12.1
 7 no service timestamps log datetime msec
 8 no service timestamps debug datetime msec
 9 no service password-encryption
11 hostname Switch
14 spanning-tree mode pvst
16 interface FastEthernet0/1
18 interface FastEthernet0/2
19 switchport access vlan 2
21 interface FastEthernet0/3
22 switchport access vlan 3
24 interface FastEthernet0/4
26 interface FastEthernet0/5
28 interface FastEthernet0/6
30 interface FastEthernet0/7
32 interface FastEthernet0/8
34 interface FastEthernet0/9
36 interface FastEthernet0/10
37 switchport mode trunk
39 interface FastEthernet0/11
41 interface FastEthernet0/12
43 interface FastEthernet0/13
45 interface FastEthernet0/14
47 interface FastEthernet0/15
49 interface FastEthernet0/16
51 interface FastEthernet0/17
53 interface FastEthernet0/18
55 interface FastEthernet0/19
57 interface FastEthernet0/20
59 interface FastEthernet0/21
61 interface FastEthernet0/22
63 interface FastEthernet0/23
65 interface FastEthernet0/24
67 interface Vlan1
68 no ip address
69 shutdown
71 interface Vlan2
72 ip address 192.168.5.2 255.255.255.0
74 interface Vlan3
75 ip address 192.168.10.2 255.255.255.0
77 interface Vlan10
78 no ip address
80 interface Vlan20
81 no ip address
84 line con 0
86 line vty 0 4
87 login
88 line vty 5 15
89 login
92 end
95 Switch#
switch1配置信息

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

 

2.配置DHCP服务器

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

思科命令,思科命令大全(完整版)

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

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 yinzhengjie en #进入特权模式
 2 yinzhengjie#configure terminal #进入全局配置模式
 3 Enter configuration commands, one per line. End with CNTL/Z.
 4 yinzhengjie(config)#interface fastEthernet 0/0 #进入接入的网口地址
 5 yinzhengjie(config-if)#ip address 172.16.1.254 255.255.255.0 #为该网口配置一个网管地址
 6 yinzhengjie(config-if)#no shutdown #开启这个端口
 8 yinzhengjie(config-if)#
 9 %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
11 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
13 yinzhengjie(config)#ip dhcp pool wancheng #添加一个地址池起别名为“wancheng”
14 yinzhengjie(dhcp-config)#network 172.16.1.0 255.255.255.0 #分配地址池
15 yinzhengjie(dhcp-config)#default-router 172.16.1.254 #指定分配地址的网关地址
16 yinzhengjie(dhcp-config)#dns-server 219.141.136.10 #配置DNS服务器
17 yinzhengjie(dhcp-config)#exit #退出DHCP配置模式
18 yinzhengjie(config)#ip dhcp excluded-address 172.16.1.1 172.16.1.100 #配置预留的IP,意思是从172.16.1.1~172.16.1.100都不分配
19 yinzhengjie(config)#
路由器的配置过程

 测试结果如下:

pc0:

思科命令,思科命令大全(完整版)

pc1:

思科命令,思科命令大全(完整版)

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

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 yinzhengjie#show run #查看配置
 2 Building configuration...
 4 Current configuration : 602 bytes
 6 version 12.2
 7 no service timestamps log datetime msec
 8 no service timestamps debug datetime msec
 9 no service password-encryption
11 hostname yinzhengjie
16 ip dhcp excluded-address 172.16.1.1 172.16.1.100
18 ip dhcp pool wancheng #DHCP配置信息
19 network 172.16.1.0 255.255.255.0
20 default-router 172.16.1.254
21 dns-server 219.141.136.10
35 interface FastEthernet0/0
36 ip address 172.16.1.254 255.255.255.0
37 duplex auto
38 speed auto
40 interface FastEthernet0/1
41 no ip address
42 duplex auto
43 speed auto
44 shutdown
46 ip classless
54 line con 0
56 line aux 0
58 line vty 0 4
59 login
63 end
65 yinzhengjie#show ip dhcp binding #查看当前地址的在线情况
66 IP address Client-ID/ Lease expiration Type
67 Hardware address
68 172.16.1.101 00E0.A357.0E96 -- Automatic
69 172.16.1.102 0009.7C6D.C274 -- Automatic
70 yinzhengjie#
查看当前地址的在线情况

 

3.单臂路由配置

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

 

思科命令,思科命令大全(完整版)

pc0测试环境如下:

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 PC ipconfig #查看本机地址
 3 FastEthernet0 Connection:(default port)
 4 Link-local IPv6 Address.........: FE80::2D0:BAFF:FEE4:777E
 5 IP Address......................: 192.168.20.1
 6 Subnet Mask.....................: 255.255.255.0
 7 Default Gateway.................: 192.168.20.254
 9 PC ping 192.168.20.2 #vlan20的另外一台pc1
11 Pinging 192.168.20.2 with 32 bytes of data:
13 Reply from 192.168.20.2: bytes=32 time=0ms TTL=128
14 Reply from 192.168.20.2: bytes=32 time=0ms TTL=128
15 Reply from 192.168.20.2: bytes=32 time=0ms TTL=128
16 Reply from 192.168.20.2: bytes=32 time=0ms TTL=128
18 Ping statistics for 192.168.20.2:
19 Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
20 Approximate round trip times in milli-seconds:
21 Minimum = 0ms, Maximum = 0ms, Average = 0ms
23 PC ping 172.16.30.254 #vlan30的网关地址
25 Pinging 172.16.30.254 with 32 bytes of data:
27 Reply from 172.16.30.254: bytes=32 time=1ms TTL=255
28 Reply from 172.16.30.254: bytes=32 time=1ms TTL=255
29 Reply from 172.16.30.254: bytes=32 time=0ms TTL=255
30 Reply from 172.16.30.254: bytes=32 time=0ms TTL=255
32 Ping statistics for 172.16.30.254:
33 Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
34 Approximate round trip times in milli-seconds:
35 Minimum = 0ms, Maximum = 1ms, Average = 0ms
37 PC ping 172.16.30.1 #VLAN30的机器
39 Pinging 172.16.30.1 with 32 bytes of data:
41 Request timed out.
42 Reply from 172.16.30.1: bytes=32 time=0ms TTL=127
43 Reply from 172.16.30.1: bytes=32 time=0ms TTL=127
44 Reply from 172.16.30.1: bytes=32 time=0ms TTL=127
46 Ping statistics for 172.16.30.1:
47 Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
48 Approximate round trip times in milli-seconds:
49 Minimum = 0ms, Maximum = 0ms, Average = 0ms
51 PC 
pc0测试结果

交换机配置如下:

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 yinzhengjie en
 2 yinzhengjie#vlan database 
 3 % Warning: It is recommended to configure VLAN from config mode,
 4 as VLAN database mode is being deprecated. Please consult user
 5 documentation for configuring VTP/VLAN in config mode.
 7 yinzhengjie(vlan)#vlan 20 name test_1
 8 VLAN 20 added:
 9 Name: test_1
10 yinzhengjie(vlan)#vlan 30 name test_2
11 VLAN 30 added:
12 Name: test_2
13 yinzhengjie(vlan)#exit 
14 APPLY completed.
15 Exiting....
16 yinzhengjie#configure terminal 
17 Enter configuration commands, one per line. End with CNTL/Z.
18 yinzhengjie(config)#interface range fastEthernet 0/1-2
19 yinzhengjie(config-if-range)#switchport access vlan 20
20 yinzhengjie(config-if-range)#exit 
21 yinzhengjie(config)#interface range fastEthernet 0/3-4
22 yinzhengjie(config-if-range)#switchport access vlan 30
23 yinzhengjie(config-if-range)#exit 
24 yinzhengjie(config)#interface fastEthernet 0/10
25 yinzhengjie(config-if)#switchport mode trunk 
27 yinzhengjie(config-if)#
28 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/10, changed state to down
30 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/10, changed state to up
32 yinzhengjie(config-if)#
33 yinzhengjie(config-if)#
34 yinzhengjie(config-if)#
交换机配置过程

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 yinzhengjie#show run
 2 Building configuration...
 4 Current configuration : 1107 bytes
 6 version 12.1
 7 no service timestamps log datetime msec
 8 no service timestamps debug datetime msec
 9 no service password-encryption
11 hostname yinzhengjie
14 spanning-tree mode pvst
16 interface FastEthernet0/1
17 switchport access vlan 20
19 interface FastEthernet0/2
20 switchport access vlan 20
22 interface FastEthernet0/3
23 switchport access vlan 30
25 interface FastEthernet0/4
26 switchport access vlan 30
28 interface FastEthernet0/5
30 interface FastEthernet0/6
32 interface FastEthernet0/7
34 interface FastEthernet0/8
36 interface FastEthernet0/9
38 interface FastEthernet0/10
39 switchport mode trunk
41 interface FastEthernet0/11
43 interface FastEthernet0/12
45 interface FastEthernet0/13
47 interface FastEthernet0/14
49 interface FastEthernet0/15
51 interface FastEthernet0/16
53 interface FastEthernet0/17
55 interface FastEthernet0/18
57 interface FastEthernet0/19
59 interface FastEthernet0/20
61 interface FastEthernet0/21
63 interface FastEthernet0/22
65 interface FastEthernet0/23
67 interface FastEthernet0/24
69 interface Vlan1
70 no ip address
71 shutdown
74 line con 0
76 line vty 0 4
77 login
78 line vty 5 15
79 login
82 end
85 yinzhengjie#
交换机的配置信息

路由器配置如下:

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 yinzhengjie#configure terminal 
 2 Enter configuration commands, one per line. End with CNTL/Z.
 3 yinzhengjie(config)#interface fastEthernet 0/0
 4 yinzhengjie(config-if)#no shutdown 
 5 yinzhengjie(config-if)#exit 
 6 yinzhengjie(config)#interface fastEthernet 0/0.1
 7 yinzhengjie(config-subif)#encapsulation dot1Q 20 #配置trunk的封装协议,如果不配置会无法配置成功IP地址的哟~
 8 yinzhengjie(config-subif)#ip address 192.168.20.254 255.255.255.0
 9 yinzhengjie(config-subif)#exit 
10 yinzhengjie(config)#interface fastEthernet 0/0.2
11 yinzhengjie(config-subif)#encapsulation dot1Q 30
12 yinzhengjie(config-subif)#ip address 172.16.30.254 255.255.255.0
13 yinzhengjie(config-subif)#exit 
14 yinzhengjie(config)#exit 
15 yinzhengjie#
16 %SYS-5-CONFIG_I: Configured from console by console
18 yinzhengjie#show run
19 Building configuration...
21 Current configuration : 528 bytes
23 version 12.2
24 no service timestamps log datetime msec
25 no service timestamps debug datetime msec
26 no service password-encryption
28 hostname yinzhengjie
47 interface FastEthernet0/0
48 no ip address
49 duplex auto
50 speed auto
52 interface FastEthernet0/0.1
53 encapsulation dot1Q 20
54 ip address 192.168.20.254 255.255.255.0
56 interface FastEthernet0/0.2
57 encapsulation dot1Q 30
58 ip address 172.16.30.254 255.255.255.0
60 ip classless
68 line con 0
70 line aux 0
72 line vty 0 4
73 login
77 end
80 yinzhengjie#
82 ‘’‘
83 扩充:
84 1:在路由器上配置trunk的封装协议的命令:
85 encapsulation [isl/dot1q] vlan#
86 2:上面的路由器配置了dot1q中继封装,20是vlan 20。
87 3:Trunk的封装类型一共有 ISL和802.1Q两种,而802.1Q在输入的时候则为dot1q
89 ’‘’
路由器配置过程

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 yinzhengjie#show run
 2 Building configuration...
 4 Current configuration : 528 bytes
 6 version 12.2
 7 no service timestamps log datetime msec
 8 no service timestamps debug datetime msec
 9 no service password-encryption
11 hostname yinzhengjie
30 interface FastEthernet0/0
31 no ip address
32 duplex auto
33 speed auto
35 interface FastEthernet0/0.1
36 encapsulation dot1Q 20
37 ip address 192.168.20.254 255.255.255.0
39 interface FastEthernet0/0.2
40 encapsulation dot1Q 30
41 ip address 172.16.30.254 255.255.255.0
43 ip classless
51 line con 0
53 line aux 0
55 line vty 0 4
56 login
60 end
63 yinzhengjie# 
路由器的配置信息

 

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

思科命令,思科命令大全(完整版)

pc0测试结果如下:

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 PC 
 2 PC ping 192.168.1.254 #网关地址
 4 Pinging 192.168.1.254 with 32 bytes of data:
 6 Reply from 192.168.1.254: bytes=32 time=1ms TTL=255
 7 Reply from 192.168.1.254: bytes=32 time=1ms TTL=255
 8 Reply from 192.168.1.254: bytes=32 time=0ms TTL=255
 9 Reply from 192.168.1.254: bytes=32 time=1ms TTL=255
11 Ping statistics for 192.168.1.254:
12 Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
13 Approximate round trip times in milli-seconds:
14 Minimum = 0ms, Maximum = 1ms, Average = 0ms
16 PC ping 192.168.2.1 #路由器0/1地址
18 Pinging 192.168.2.1 with 32 bytes of data:
20 Reply from 192.168.2.1: bytes=32 time=1ms TTL=255
21 Reply from 192.168.2.1: bytes=32 time=0ms TTL=255
22 Reply from 192.168.2.1: bytes=32 time=0ms TTL=255
23 Reply from 192.168.2.1: bytes=32 time=0ms TTL=255
25 Ping statistics for 192.168.2.1:
26 Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
27 Approximate round trip times in milli-seconds:
28 Minimum = 0ms, Maximum = 1ms, Average = 0ms
30 PC ping 192.168.3.1 #中间路由地址
32 Pinging 192.168.3.1 with 32 bytes of data:
34 Reply from 192.168.3.1: bytes=32 time=1ms TTL=254
35 Reply from 192.168.3.1: bytes=32 time=0ms TTL=254
36 Reply from 192.168.3.1: bytes=32 time=2ms TTL=254
37 Reply from 192.168.3.1: bytes=32 time=0ms TTL=254
39 Ping statistics for 192.168.3.1:
40 Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
41 Approximate round trip times in milli-seconds:
42 Minimum = 0ms, Maximum = 2ms, Average = 0ms
44 PC ping 192.168.4.1 #pc1机器地址
46 Pinging 192.168.4.1 with 32 bytes of data:
48 Reply from 192.168.4.1: bytes=32 time=11ms TTL=125
49 Reply from 192.168.4.1: bytes=32 time=1ms TTL=125
50 Reply from 192.168.4.1: bytes=32 time=0ms TTL=125
51 Reply from 192.168.4.1: bytes=32 time=0ms TTL=125
53 Ping statistics for 192.168.4.1:
54 Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
55 Approximate round trip times in milli-seconds:
56 Minimum = 0ms, Maximum = 11ms, Average = 3ms
58 PC 
pc测试结果

路由器配置信息

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 yinzhengjie(config)#interface fastEthernet 0/0
 2 yinzhengjie(config-if)#no shutdown 
 3 %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
 4 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
 5 yinzhengjie(config-if)#ip address 192.168.1.254 255.255.255.0
 6 yinzhengjie(config-if)#exit 
 7 yinzhengjie(config)#interface fastEthernet 0/1
 8 yinzhengjie(config-if)#no shutdown 
 9 %LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
10 yinzhengjie(config-if)#ip address 192.168.2.1 255.255.255.0
11 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up 
12 yinzhengjie(config-if)#ex
13 yinzhengjie(config)#router rip #进入动态路由配置模式
14 yinzhengjie(config-router)#version 2
15 yinzhengjie(config-router)#no auto-summary 
16 yinzhengjie(config-router)#network 192.168.1.0 #与路由直连网段
17 yinzhengjie(config-router)#network 192.168.2.0 #与路由直连网段
18 yinzhengjie#show run
19 Building configuration...
21 Current configuration : 538 bytes
23 version 12.2
24 no service timestamps log datetime msec
25 no service timestamps debug datetime msec
26 no service password-encryption
28 hostname yinzhengjie
47 interface FastEthernet0/0
48 ip address 192.168.1.254 255.255.255.0
49 duplex auto
50 speed auto
52 interface FastEthernet0/1
53 ip address 192.168.2.1 255.255.255.0
54 duplex auto
55 speed auto
57 router rip
58 version 2
59 network 192.168.1.0
60 network 192.168.2.0
61 no auto-summary
63 ip classless
71 line con 0
73 line aux 0
75 line vty 0 4
76 login
80 end
83 yinzhengjie# 
Route0配置过程

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 Router en
 2 Router#configure terminal 
 3 Enter configuration commands, one per line. End with CNTL/Z.
 4 Router(config)#interface fastEthernet 0/0
 5 Router(config-if)#no shutdown 
 6 %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
 8 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
 9 Router(config-if)#ip address 192.168.2.2 255.255.255.0
10 Router(config-if)#exit 
11 Router(config)#interface fastEthernet 0/1
12 Router(config-if)#no shutdown 
14 Router(config-if)#
15 %LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
16 Router(config-if)#ip address 192.168.3.1 255.255.255.0
17 Router(config-if)#
18 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
20 Router(config-if)#ex
21 Router(config)#router rip 
22 Router(config-router)#version 2
23 Router(config-router)#no auto-summary 
24 Router(config-router)#network 192.168.2.0
25 Router(config-router)#network 192.168.3.0
26 Router(config-router)#
Route1配置过程

思科命令,思科命令大全(完整版)

思科命令,思科命令大全(完整版)

 1 yinzhengjie(config)#interface fastEthernet 0/0
 2 yinzhengjie(config-if)#no shutdown 
 3 %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
 4 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
 5 yinzhengjie(config-if)#ip address 192.168.3.2 255.255.255.0
 6 yinzhengjie(config-if)#exit 
 7 yinzhengjie(config)#interface fastEthernet 0/1
 8 yinzhengjie(config-if)#no shutdown 
 9 yinzhengjie(config-if)#
10 %LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
11 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
12 yinzhengjie(config-if)#ip address 192.168.4.254 255.255.255.0
13 yinzhengjie(config-if)#exit 
14 yinzhengjie(config)#router rip 
15 yinzhengjie(config-router)#version 2
16 yinzhengjie(config-router)#no auto-summary 
17 yinzhengjie(config-router)#network 192.168.3.0
18 yinzhengjie(config-router)#network 192.168.4.0
19 yinzhengjie(config-router)#
Route2配置过程