cisco常用命令詳解


                    cisco常用命令詳解

                                  作者:尹正傑

版權聲明:原創作品,謝絕轉載!否則將追究法律責任。

 

 

一.常用命令用法展示

1.命令行模式的來回切換

 1 yinzhengjie>enable         #從用戶模式切換到特權模式,權限最低,可以說是無功能,啥也不能做。
 2 yinzhengjie#       #特權模式,可以進行查看端口的IP配置信息,查看主機表等,重啟路由器等等操作。 
 3 
 4 yinzhengjie#configure terminal    #從特權模式切換到全局配置模式,權限最高,可以在這里配置vlan等等
 5 Enter configuration commands, one per line. End with CNTL/Z.
 6 yinzhengjie(config)#
 7 
 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)#
 3 
 4 yinzhengjie>enable                   #驗證過程,注意,
 5 Password: 
 6 yinzhengjie#
 7 
 8 
 9 
10 #可以在特權模式下查看你做了哪些配置
11 yinzhengjie#show run
12 Building configuration...
13 
14 Current configuration : 457 bytes
15 !
16 version 12.2
17 no service timestamps log datetime msec
18 no service timestamps debug datetime msec
19 no service password-encryption
20 !
21 hostname yinzhengjie
22 !
23 !
24 !
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
 5 
 6 yinzhengjie#show run
 7 Building configuration...
 8 
 9 Current configuration : 504 bytes
10 !
11 version 12.2
12 no service timestamps log datetime msec
13 no service timestamps debug datetime msec
14 no service password-encryption
15 !
16 hostname yinzhengjie
17 !
18 !
19 !
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
 5 
 6 Codes: UN - unknown, EX - expired, OK - OK, ?? - revalidate
 7        temp - temporary, perm - permanent
 8        NA - Not Applicable None - Not defined
 9 
10 Host                      Port  Flags      Age Type   Address(es)
11 yinzhengjie#
12 
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.
 5 
 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)
16 
17 思科VLAN的創建
VLAN的添加
 1 yinzhengjie#show vlan brief      #查看VLAN信息
 2 
 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.
23 
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 
32 
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信息
 2 
 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.
18     
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 
29 
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 
 2 
 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
24 
25 yinzhengjie#show vlan brief 
26 
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
4 
5 %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up
6 
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
  4 !
  5 interface Vlan5
  6  ip address 192.168.5.1 255.255.255.0
  7 !
  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...
 33 
 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
117 
118 
119 yinzhengjie#
刪除管理IP

 

二.簡單網絡配置練習

小試牛刀:好了,學了以上的命令,我們一起來做一個簡單的練習:

1.在交換機上划分vlan,PC1PC3加入到vlan2,PC2PC4加入vlan3,並實現跨交換機的同vlan之間的通訊,如圖-1所示:

pc0的cmd窗口測試結果如下:

 1 PC>ipconfig
 2 
 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
 8 
 9 PC>ping 192.168.5.1 #網關地址
10 
11 Pinging 192.168.5.1 with 32 bytes of data:
12 
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
15 
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
20 
21 Control-C
22 ^C
23 PC>ping 192.168.5.2  #右邊的交換機
24 
25 Pinging 192.168.5.2 with 32 bytes of data:
26 
27 Reply from 192.168.5.2: bytes=32 time=0ms TTL=255
28 
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
33 
34 Control-C
35 ^C
36 PC>ping 192.168.5.20  #右邊的PC機器
37 
38 Pinging 192.168.5.20 with 32 bytes of data:
39 
40 Reply from 192.168.5.20: bytes=32 time=0ms TTL=128
41 
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
46 
47 Control-C
48 ^C
49 PC>ping 192.168.10.1
50 
51 Pinging 192.168.10.1 with 32 bytes of data:
52 
53 
54 Ping statistics for 192.168.10.1:
55     Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
56 
57 Control-C
58 ^C
59 PC>ping 192.168.10.10
60 
61 Pinging 192.168.10.10 with 32 bytes of data:
62 
63 
64 Ping statistics for 192.168.10.10:
65     Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
66 
67 Control-C
68 ^C
69 PC>
PC0測試結果

pc1的cmd窗口測試結果如下:

 1 PC>
 2 PC>ipconfig
 3 
 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
 9 
10 PC>ping 192.168.10.1 #網關地址
11 
12 Pinging 192.168.10.1 with 32 bytes of data:
13 
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
16 
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
21 
22 Control-C
23 ^C
24 PC>ping 192.168.10.2  #右邊交換機的網關地址
25 
26 Pinging 192.168.10.2 with 32 bytes of data:
27 
28 Reply from 192.168.10.2: bytes=32 time=1ms TTL=255
29 
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
34 
35 Control-C
36 ^C
37 PC>ping 192.168.10.20
38 
39 Pinging 192.168.10.20 with 32 bytes of data:
40 
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
45 
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
50 
51 PC>
52 PC>ping 192.168.5.1
53 
54 Pinging 192.168.5.1 with 32 bytes of data:
55 
56 
57 Ping statistics for 192.168.5.1:
58     Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
59 
60 Control-C
61 ^C
62 PC>ping 192.168.5.2
63 
64 Pinging 192.168.5.2 with 32 bytes of data:
65 
66 
67 Ping statistics for 192.168.5.2:
68     Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
69 
70 Control-C
71 ^C
72 PC>ping 192.168.5.20
73 
74 Pinging 192.168.5.20 with 32 bytes of data:
75 
76 
77 Ping statistics for 192.168.5.20:
78     Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),
79 
80 Control-C
81 ^C
82 PC>
pc1測試結果

左邊交換機的配置如下:

 1 Switch#show run
 2 Building configuration...
 3 
 4 Current configuration : 1159 bytes
 5 !
 6 version 12.1
 7 no service timestamps log datetime msec
 8 no service timestamps debug datetime msec
 9 no service password-encryption
10 !
11 hostname Switch
12 !
13 !
14 spanning-tree mode pvst
15 !
16 interface FastEthernet0/1
17 !
18 interface FastEthernet0/2
19  switchport access vlan 2
20 !
21 interface FastEthernet0/3
22  switchport access vlan 3
23 !
24 interface FastEthernet0/4
25 !
26 interface FastEthernet0/5
27 !
28 interface FastEthernet0/6
29 !
30 interface FastEthernet0/7
31 !
32 interface FastEthernet0/8
33 !
34 interface FastEthernet0/9
35 !
36 interface FastEthernet0/10
37  switchport mode trunk
38 !
39 interface FastEthernet0/11
40 !
41 interface FastEthernet0/12
42 !
43 interface FastEthernet0/13
44 !
45 interface FastEthernet0/14
46 !
47 interface FastEthernet0/15
48 !
49 interface FastEthernet0/16
50 !
51 interface FastEthernet0/17
52 !
53 interface FastEthernet0/18
54 !
55 interface FastEthernet0/19
56 !
57 interface FastEthernet0/20
58 !
59 interface FastEthernet0/21
60 !
61 interface FastEthernet0/22
62 !
63 interface FastEthernet0/23
64 !
65 interface FastEthernet0/24
66 !
67 interface Vlan1
68  no ip address
69  shutdown
70 !
71 interface Vlan2
72  ip address 192.168.5.1 255.255.255.0
73 !
74 interface Vlan3
75  ip address 192.168.10.1 255.255.255.0
76 !
77 !
78 line con 0
79 !
80 line vty 0 4
81  login
82 line vty 5 15
83  login
84 !
85 !
86 end
87 
88 
89 Switch# 
switch3配置信息

右邊交換機的配置如下:

 1 Switch#show running-config 
 2 Building configuration...
 3 
 4 Current configuration : 1227 bytes
 5 !
 6 version 12.1
 7 no service timestamps log datetime msec
 8 no service timestamps debug datetime msec
 9 no service password-encryption
10 !
11 hostname Switch
12 !
13 !
14 spanning-tree mode pvst
15 !
16 interface FastEthernet0/1
17 !
18 interface FastEthernet0/2
19  switchport access vlan 2
20 !
21 interface FastEthernet0/3
22  switchport access vlan 3
23 !
24 interface FastEthernet0/4
25 !
26 interface FastEthernet0/5
27 !
28 interface FastEthernet0/6
29 !
30 interface FastEthernet0/7
31 !
32 interface FastEthernet0/8
33 !
34 interface FastEthernet0/9
35 !
36 interface FastEthernet0/10
37  switchport mode trunk
38 !
39 interface FastEthernet0/11
40 !
41 interface FastEthernet0/12
42 !
43 interface FastEthernet0/13
44 !
45 interface FastEthernet0/14
46 !
47 interface FastEthernet0/15
48 !
49 interface FastEthernet0/16
50 !
51 interface FastEthernet0/17
52 !
53 interface FastEthernet0/18
54 !
55 interface FastEthernet0/19
56 !
57 interface FastEthernet0/20
58 !
59 interface FastEthernet0/21
60 !
61 interface FastEthernet0/22
62 !
63 interface FastEthernet0/23
64 !
65 interface FastEthernet0/24
66 !
67 interface Vlan1
68  no ip address
69  shutdown
70 !
71 interface Vlan2
72  ip address 192.168.5.2 255.255.255.0
73 !
74 interface Vlan3
75  ip address 192.168.10.2 255.255.255.0
76 !
77 interface Vlan10
78  no ip address
79 !
80 interface Vlan20
81  no ip address
82 !
83 !
84 line con 0
85 !
86 line vty 0 4
87  login
88 line vty 5 15
89  login
90 !
91 !
92 end
93 
94 
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 #開啟這個端口
 7 
 8 yinzhengjie(config-if)#
 9 %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
10 
11 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
12 
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...
 3 
 4 Current configuration : 602 bytes
 5 !
 6 version 12.2
 7 no service timestamps log datetime msec
 8 no service timestamps debug datetime msec
 9 no service password-encryption
10 !
11 hostname yinzhengjie
12 !
13 !
14 !
15 !
16 ip dhcp excluded-address 172.16.1.1 172.16.1.100
17 !
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
22 !
23 !
24 !
25 !
26 !
27 !
28 !
29 !
30 !
31 !
32 !
33 !
34 !
35 interface FastEthernet0/0
36  ip address 172.16.1.254 255.255.255.0
37  duplex auto
38  speed auto
39 !
40 interface FastEthernet0/1
41  no ip address
42  duplex auto
43  speed auto
44  shutdown
45 !
46 ip classless
47 !
48 !
49 !
50 !
51 !
52 !
53 !
54 line con 0
55 !
56 line aux 0
57 !
58 line vty 0 4
59  login
60 !
61 !
62 !
63 end
64 
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   #查看本機地址
 2 
 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
 8 
 9 PC>ping 192.168.20.2   #vlan20的另外一台pc1
10 
11 Pinging 192.168.20.2 with 32 bytes of data:
12 
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
17 
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
22 
23 PC>ping 172.16.30.254  #vlan30的網關地址
24 
25 Pinging 172.16.30.254 with 32 bytes of data:
26 
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
31 
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
36 
37 PC>ping 172.16.30.1  #VLAN30的機器
38 
39 Pinging 172.16.30.1 with 32 bytes of data:
40 
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
45 
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
50 
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.
 6 
 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 
26 
27 yinzhengjie(config-if)#
28 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/10, changed state to down
29 
30 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/10, changed state to up
31 
32 yinzhengjie(config-if)#
33 yinzhengjie(config-if)#
34 yinzhengjie(config-if)#
交換機配置過程
 1 yinzhengjie#show run
 2 Building configuration...
 3 
 4 Current configuration : 1107 bytes
 5 !
 6 version 12.1
 7 no service timestamps log datetime msec
 8 no service timestamps debug datetime msec
 9 no service password-encryption
10 !
11 hostname yinzhengjie
12 !
13 !
14 spanning-tree mode pvst
15 !
16 interface FastEthernet0/1
17  switchport access vlan 20
18 !
19 interface FastEthernet0/2
20  switchport access vlan 20
21 !
22 interface FastEthernet0/3
23  switchport access vlan 30
24 !
25 interface FastEthernet0/4
26  switchport access vlan 30
27 !
28 interface FastEthernet0/5
29 !
30 interface FastEthernet0/6
31 !
32 interface FastEthernet0/7
33 !
34 interface FastEthernet0/8
35 !
36 interface FastEthernet0/9
37 !
38 interface FastEthernet0/10
39  switchport mode trunk
40 !
41 interface FastEthernet0/11
42 !
43 interface FastEthernet0/12
44 !
45 interface FastEthernet0/13
46 !
47 interface FastEthernet0/14
48 !
49 interface FastEthernet0/15
50 !
51 interface FastEthernet0/16
52 !
53 interface FastEthernet0/17
54 !
55 interface FastEthernet0/18
56 !
57 interface FastEthernet0/19
58 !
59 interface FastEthernet0/20
60 !
61 interface FastEthernet0/21
62 !
63 interface FastEthernet0/22
64 !
65 interface FastEthernet0/23
66 !
67 interface FastEthernet0/24
68 !
69 interface Vlan1
70  no ip address
71  shutdown
72 !
73 !
74 line con 0
75 !
76 line vty 0 4
77  login
78 line vty 5 15
79  login
80 !
81 !
82 end
83 
84 
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
17 
18 yinzhengjie#show run
19 Building configuration...
20 
21 Current configuration : 528 bytes
22 !
23 version 12.2
24 no service timestamps log datetime msec
25 no service timestamps debug datetime msec
26 no service password-encryption
27 !
28 hostname yinzhengjie
29 !
30 !
31 !
32 !
33 !
34 !
35 !
36 !
37 !
38 !
39 !
40 !
41 !
42 !
43 !
44 !
45 !
46 !
47 interface FastEthernet0/0
48  no ip address
49  duplex auto
50  speed auto
51 !
52 interface FastEthernet0/0.1
53  encapsulation dot1Q 20
54  ip address 192.168.20.254 255.255.255.0
55 !
56 interface FastEthernet0/0.2
57  encapsulation dot1Q 30
58  ip address 172.16.30.254 255.255.255.0
59 !
60 ip classless
61 !
62 !
63 !
64 !
65 !
66 !
67 !
68 line con 0
69 !
70 line aux 0
71 !
72 line vty 0 4
73  login
74 !
75 !
76 !
77 end
78 
79 
80 yinzhengjie#
81 
82 ‘’‘
83 擴充:
84 1:在路由器上配置trunk的封裝協議的命令:
85 encapsulation [isl/dot1q] vlan#
86 2:上面的路由器配置了dot1q中繼封裝,20是vlan 2087 3:Trunk的封裝類型一共有 ISL和802.1Q兩種,而802.1Q在輸入的時候則為dot1q
88 
89 ’‘’
路由器配置過程
 1 yinzhengjie#show run
 2 Building configuration...
 3 
 4 Current configuration : 528 bytes
 5 !
 6 version 12.2
 7 no service timestamps log datetime msec
 8 no service timestamps debug datetime msec
 9 no service password-encryption
10 !
11 hostname yinzhengjie
12 !
13 !
14 !
15 !
16 !
17 !
18 !
19 !
20 !
21 !
22 !
23 !
24 !
25 !
26 !
27 !
28 !
29 !
30 interface FastEthernet0/0
31  no ip address
32  duplex auto
33  speed auto
34 !
35 interface FastEthernet0/0.1
36  encapsulation dot1Q 20
37  ip address 192.168.20.254 255.255.255.0
38 !
39 interface FastEthernet0/0.2
40  encapsulation dot1Q 30
41  ip address 172.16.30.254 255.255.255.0
42 !
43 ip classless
44 !
45 !
46 !
47 !
48 !
49 !
50 !
51 line con 0
52 !
53 line aux 0
54 !
55 line vty 0 4
56  login
57 !
58 !
59 !
60 end
61 
62 
63 yinzhengjie# 
路由器的配置信息

 

4.如下圖所示,通過動態路由RIP實現三個路由器之間的全網互通。

pc0測試結果如下:

 1 PC>
 2 PC>ping 192.168.1.254   #網關地址
 3 
 4 Pinging 192.168.1.254 with 32 bytes of data:
 5 
 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
10 
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
15 
16 PC>ping 192.168.2.1 #路由器0/1地址
17 
18 Pinging 192.168.2.1 with 32 bytes of data:
19 
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
24 
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
29 
30 PC>ping 192.168.3.1 #中間路由地址
31 
32 Pinging 192.168.3.1 with 32 bytes of data:
33 
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
38 
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
43 
44 PC>ping 192.168.4.1 #pc1機器地址
45 
46 Pinging 192.168.4.1 with 32 bytes of data:
47 
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
52 
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
57 
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...
20 
21 Current configuration : 538 bytes
22 !
23 version 12.2
24 no service timestamps log datetime msec
25 no service timestamps debug datetime msec
26 no service password-encryption
27 !
28 hostname yinzhengjie
29 !
30 !
31 !
32 !
33 !
34 !
35 !
36 !
37 !
38 !
39 !
40 !
41 !
42 !
43 !
44 !
45 !
46 !
47 interface FastEthernet0/0
48  ip address 192.168.1.254 255.255.255.0
49  duplex auto
50  speed auto
51 !
52 interface FastEthernet0/1
53  ip address 192.168.2.1 255.255.255.0
54  duplex auto
55  speed auto
56 !
57 router rip
58  version 2
59  network 192.168.1.0
60  network 192.168.2.0
61  no auto-summary
62 !
63 ip classless
64 !
65 !
66 !
67 !
68 !
69 !
70 !
71 line con 0
72 !
73 line aux 0
74 !
75 line vty 0 4
76  login
77 !
78 !
79 !
80 end
81 
82 
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
 7 
 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 
13 
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
19 
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配置過程

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM