博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cisco常用命令详解
阅读量:7035 次
发布时间:2019-06-28

本文共 35135 字,大约阅读时间需要 117 分钟。

                    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 run12 Building configuration...13 14 Current configuration : 457 bytes15 !16 version 12.217 no service timestamps log datetime msec18 no service timestamps debug datetime msec19 no service password-encryption20 !21 hostname yinzhengjie22 !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 bytes10 !11 version 12.212 no service timestamps log datetime msec13 no service timestamps debug datetime msec14 no service password-encryption15 !16 hostname yinzhengjie17 !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 disabled16 FastEthernet0/1 is administratively down, line protocol is down (disabled)17   Internet protocol processing disabled18 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   #创建VLAN2010 VLAN 20 added:11     Name: test_2  12 yinzhengjie(vlan)#vlan 30 name test_3   #创建VLAN3013 VLAN 30 added:14     Name: test_315 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/2010                                                 Fa0/21, Fa0/22, Fa0/23, Fa0/2411 10   test_1                           active      #之前已经存在的VLAN12 20   test_2                           active      #之前已经存在的VLAN13 30   test_3                           active      #之前已经存在的VLAN14 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 user22   documentation for configuring VTP/VLAN in config mode.23 24 yinzhengjie(vlan)#no vlan 10     #删除VLAN1025 Deleting VLAN 10...26 yinzhengjie(vlan)#no vlan 20      #删除VLAN2027 Deleting VLAN 20...28 yinzhengjie(vlan)#exit 29 APPLY completed.30 Exiting....31 yinzhengjie#show vlan brief 32 33 VLAN Name                             Status    Ports34 ---- -------------------------------- --------- -------------------------------35 1    default                          active    Fa0/1, Fa0/2, Fa0/3, Fa0/436                                                 Fa0/5, Fa0/6, Fa0/7, Fa0/837                                                 Fa0/9, Fa0/10, Fa0/11, Fa0/1238                                                 Fa0/13, Fa0/14, Fa0/15, Fa0/1639                                                 Fa0/17, Fa0/18, Fa0/19, Fa0/2040                                                 Fa0/21, Fa0/22, Fa0/23, Fa0/2441 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/2010                                                 Fa0/21, Fa0/22, Fa0/23, Fa0/2411 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 console28 yinzhengjie#show  vlan brief 29 30 VLAN Name                             Status    Ports31 ---- -------------------------------- --------- -------------------------------32 1    default                          active    Fa0/6, Fa0/7, Fa0/8, Fa0/933                                                 Fa0/10, Fa0/11, Fa0/12, Fa0/1334                                                 Fa0/14, Fa0/15, Fa0/16, Fa0/1735                                                 Fa0/18, Fa0/19, Fa0/20, Fa0/2136                                                 Fa0/22, Fa0/23, Fa0/2437 30   test_3                           active    Fa0/1, Fa0/2, Fa0/3, Fa0/438                                                 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/2410 30   test_3                           active    Fa0/1, Fa0/2, Fa0/3, Fa0/411                                                 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 console24 25 yinzhengjie#show vlan brief 26 27 VLAN Name                             Status    Ports28 ---- -------------------------------- --------- -------------------------------29 1    default                          active    Fa0/1, Fa0/2, Fa0/3, Fa0/430                                                 Fa0/5, Fa0/6, Fa0/7, Fa0/831                                                 Fa0/9, Fa0/10, Fa0/11, Fa0/1232                                                 Fa0/13, Fa0/14, Fa0/15, Fa0/1633                                                 Fa0/17, Fa0/18, Fa0/19, Fa0/2034                                                 Fa0/21, Fa0/22, Fa0/23, Fa0/2435 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 up4 5 %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up6 7 yinzhengjie(config-if)#ip add 192.168.10.1 255.255.255.0   #配置管理IP8 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  shutdown100 !101 interface Vlan5102  ip address 192.168.5.1 255.255.255.0103 !104 interface Vlan10105  no ip address     #此时我们发现IP被清空了106 !107 !108 line con 0109 !110 line vty 0 4111  login112 line vty 5 15113  login114 !115 !116 end117 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=25514 Reply from 192.168.5.1: bytes=32 time=0ms TTL=25515 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 = 0ms20 21 Control-C22 ^C23 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=25528 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 = 0ms33 34 Control-C35 ^C36 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=12841 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 = 0ms46 47 Control-C48 ^C49 PC>ping 192.168.10.150 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-C58 ^C59 PC>ping 192.168.10.1060 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-C68 ^C69 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=25515 Reply from 192.168.10.1: bytes=32 time=0ms TTL=25516 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 = 0ms21 22 Control-C23 ^C24 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=25529 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 = 1ms34 35 Control-C36 ^C37 PC>ping 192.168.10.2038 39 Pinging 192.168.10.20 with 32 bytes of data:40 41 Reply from 192.168.10.20: bytes=32 time=0ms TTL=12842 Reply from 192.168.10.20: bytes=32 time=0ms TTL=12843 Reply from 192.168.10.20: bytes=32 time=0ms TTL=12844 Reply from 192.168.10.20: bytes=32 time=1ms TTL=12845 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 = 0ms50 51 PC>52 PC>ping 192.168.5.153 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-C61 ^C62 PC>ping 192.168.5.263 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-C71 ^C72 PC>ping 192.168.5.2073 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-C81 ^C82 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-encryption10 !11 hostname Switch12 !13 !14 spanning-tree mode pvst15 !16 interface FastEthernet0/117 !18 interface FastEthernet0/219  switchport access vlan 220 !21 interface FastEthernet0/322  switchport access vlan 323 !24 interface FastEthernet0/425 !26 interface FastEthernet0/527 !28 interface FastEthernet0/629 !30 interface FastEthernet0/731 !32 interface FastEthernet0/833 !34 interface FastEthernet0/935 !36 interface FastEthernet0/1037  switchport mode trunk38 !39 interface FastEthernet0/1140 !41 interface FastEthernet0/1242 !43 interface FastEthernet0/1344 !45 interface FastEthernet0/1446 !47 interface FastEthernet0/1548 !49 interface FastEthernet0/1650 !51 interface FastEthernet0/1752 !53 interface FastEthernet0/1854 !55 interface FastEthernet0/1956 !57 interface FastEthernet0/2058 !59 interface FastEthernet0/2160 !61 interface FastEthernet0/2262 !63 interface FastEthernet0/2364 !65 interface FastEthernet0/2466 !67 interface Vlan168  no ip address69  shutdown70 !71 interface Vlan272  ip address 192.168.5.1 255.255.255.073 !74 interface Vlan375  ip address 192.168.10.1 255.255.255.076 !77 !78 line con 079 !80 line vty 0 481  login82 line vty 5 1583  login84 !85 !86 end87 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-encryption10 !11 hostname Switch12 !13 !14 spanning-tree mode pvst15 !16 interface FastEthernet0/117 !18 interface FastEthernet0/219  switchport access vlan 220 !21 interface FastEthernet0/322  switchport access vlan 323 !24 interface FastEthernet0/425 !26 interface FastEthernet0/527 !28 interface FastEthernet0/629 !30 interface FastEthernet0/731 !32 interface FastEthernet0/833 !34 interface FastEthernet0/935 !36 interface FastEthernet0/1037  switchport mode trunk38 !39 interface FastEthernet0/1140 !41 interface FastEthernet0/1242 !43 interface FastEthernet0/1344 !45 interface FastEthernet0/1446 !47 interface FastEthernet0/1548 !49 interface FastEthernet0/1650 !51 interface FastEthernet0/1752 !53 interface FastEthernet0/1854 !55 interface FastEthernet0/1956 !57 interface FastEthernet0/2058 !59 interface FastEthernet0/2160 !61 interface FastEthernet0/2262 !63 interface FastEthernet0/2364 !65 interface FastEthernet0/2466 !67 interface Vlan168  no ip address69  shutdown70 !71 interface Vlan272  ip address 192.168.5.2 255.255.255.073 !74 interface Vlan375  ip address 192.168.10.2 255.255.255.076 !77 interface Vlan1078  no ip address79 !80 interface Vlan2081  no ip address82 !83 !84 line con 085 !86 line vty 0 487  login88 line vty 5 1589  login90 !91 !92 end93 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 up10 11 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up12 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-encryption10 !11 hostname yinzhengjie12 !13 !14 !15 !16 ip dhcp excluded-address 172.16.1.1 172.16.1.10017 !18 ip dhcp pool wancheng   #DHCP配置信息19  network 172.16.1.0 255.255.255.020  default-router 172.16.1.25421  dns-server 219.141.136.1022 !23 !24 !25 !26 !27 !28 !29 !30 !31 !32 !33 !34 !35 interface FastEthernet0/036  ip address 172.16.1.254 255.255.255.037  duplex auto38  speed auto39 !40 interface FastEthernet0/141  no ip address42  duplex auto43  speed auto44  shutdown45 !46 ip classless47 !48 !49 !50 !51 !52 !53 !54 line con 055 !56 line aux 057 !58 line vty 0 459  login60 !61 !62 !63 end64 65 yinzhengjie#show ip dhcp binding   #查看当前地址的在线情况66 IP address       Client-ID/              Lease expiration        Type67                  Hardware address68 172.16.1.101     00E0.A357.0E96           --                     Automatic69 172.16.1.102     0009.7C6D.C274           --                     Automatic70 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的另外一台pc110 11 Pinging 192.168.20.2 with 32 bytes of data:12 13 Reply from 192.168.20.2: bytes=32 time=0ms TTL=12814 Reply from 192.168.20.2: bytes=32 time=0ms TTL=12815 Reply from 192.168.20.2: bytes=32 time=0ms TTL=12816 Reply from 192.168.20.2: bytes=32 time=0ms TTL=12817 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 = 0ms22 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=25528 Reply from 172.16.30.254: bytes=32 time=1ms TTL=25529 Reply from 172.16.30.254: bytes=32 time=0ms TTL=25530 Reply from 172.16.30.254: bytes=32 time=0ms TTL=25531 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 = 0ms36 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=12743 Reply from 172.16.30.1: bytes=32 time=0ms TTL=12744 Reply from 172.16.30.1: bytes=32 time=0ms TTL=12745 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 = 0ms50 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_110 yinzhengjie(vlan)#vlan 30 name test_211 VLAN 30 added:12     Name: test_213 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-219 yinzhengjie(config-if-range)#switchport access vlan 2020 yinzhengjie(config-if-range)#exit 21 yinzhengjie(config)#interface range fastEthernet 0/3-422 yinzhengjie(config-if-range)#switchport access vlan 3023 yinzhengjie(config-if-range)#exit 24 yinzhengjie(config)#interface fastEthernet 0/1025 yinzhengjie(config-if)#switchport mode trunk 26 27 yinzhengjie(config-if)#28 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/10, changed state to down29 30 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/10, changed state to up31 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-encryption10 !11 hostname yinzhengjie12 !13 !14 spanning-tree mode pvst15 !16 interface FastEthernet0/117  switchport access vlan 2018 !19 interface FastEthernet0/220  switchport access vlan 2021 !22 interface FastEthernet0/323  switchport access vlan 3024 !25 interface FastEthernet0/426  switchport access vlan 3027 !28 interface FastEthernet0/529 !30 interface FastEthernet0/631 !32 interface FastEthernet0/733 !34 interface FastEthernet0/835 !36 interface FastEthernet0/937 !38 interface FastEthernet0/1039  switchport mode trunk40 !41 interface FastEthernet0/1142 !43 interface FastEthernet0/1244 !45 interface FastEthernet0/1346 !47 interface FastEthernet0/1448 !49 interface FastEthernet0/1550 !51 interface FastEthernet0/1652 !53 interface FastEthernet0/1754 !55 interface FastEthernet0/1856 !57 interface FastEthernet0/1958 !59 interface FastEthernet0/2060 !61 interface FastEthernet0/2162 !63 interface FastEthernet0/2264 !65 interface FastEthernet0/2366 !67 interface FastEthernet0/2468 !69 interface Vlan170  no ip address71  shutdown72 !73 !74 line con 075 !76 line vty 0 477  login78 line vty 5 1579  login80 !81 !82 end83 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.211 yinzhengjie(config-subif)#encapsulation dot1Q 3012 yinzhengjie(config-subif)#ip address 172.16.30.254 255.255.255.013 yinzhengjie(config-subif)#exit 14 yinzhengjie(config)#exit 15 yinzhengjie#16 %SYS-5-CONFIG_I: Configured from console by console17 18 yinzhengjie#show run19 Building configuration...20 21 Current configuration : 528 bytes22 !23 version 12.224 no service timestamps log datetime msec25 no service timestamps debug datetime msec26 no service password-encryption27 !28 hostname yinzhengjie29 !30 !31 !32 !33 !34 !35 !36 !37 !38 !39 !40 !41 !42 !43 !44 !45 !46 !47 interface FastEthernet0/048  no ip address49  duplex auto50  speed auto51 !52 interface FastEthernet0/0.153  encapsulation dot1Q 2054  ip address 192.168.20.254 255.255.255.055 !56 interface FastEthernet0/0.257  encapsulation dot1Q 3058  ip address 172.16.30.254 255.255.255.059 !60 ip classless61 !62 !63 !64 !65 !66 !67 !68 line con 069 !70 line aux 071 !72 line vty 0 473  login74 !75 !76 !77 end78 79 80 yinzhengjie#81 82 ‘’‘83 扩充:84 1:在路由器上配置trunk的封装协议的命令:85 encapsulation [isl/dot1q] vlan#86 2:上面的路由器配置了dot1q中继封装,20是vlan 20。87 3:Trunk的封装类型一共有 ISL和802.1Q两种,而802.1Q在输入的时候则为dot1q88 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-encryption10 !11 hostname yinzhengjie12 !13 !14 !15 !16 !17 !18 !19 !20 !21 !22 !23 !24 !25 !26 !27 !28 !29 !30 interface FastEthernet0/031  no ip address32  duplex auto33  speed auto34 !35 interface FastEthernet0/0.136  encapsulation dot1Q 2037  ip address 192.168.20.254 255.255.255.038 !39 interface FastEthernet0/0.240  encapsulation dot1Q 3041  ip address 172.16.30.254 255.255.255.042 !43 ip classless44 !45 !46 !47 !48 !49 !50 !51 line con 052 !53 line aux 054 !55 line vty 0 456  login57 !58 !59 !60 end61 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=25510 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 = 0ms15 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=25521 Reply from 192.168.2.1: bytes=32 time=0ms TTL=25522 Reply from 192.168.2.1: bytes=32 time=0ms TTL=25523 Reply from 192.168.2.1: bytes=32 time=0ms TTL=25524 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 = 0ms29 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=25435 Reply from 192.168.3.1: bytes=32 time=0ms TTL=25436 Reply from 192.168.3.1: bytes=32 time=2ms TTL=25437 Reply from 192.168.3.1: bytes=32 time=0ms TTL=25438 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 = 0ms43 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=12549 Reply from 192.168.4.1: bytes=32 time=1ms TTL=12550 Reply from 192.168.4.1: bytes=32 time=0ms TTL=12551 Reply from 192.168.4.1: bytes=32 time=0ms TTL=12552 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 = 3ms57 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 up10 yinzhengjie(config-if)#ip address 192.168.2.1 255.255.255.011 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up    12 yinzhengjie(config-if)#ex13 yinzhengjie(config)#router rip  #进入动态路由配置模式14 yinzhengjie(config-router)#version 215 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 run19 Building configuration...20 21 Current configuration : 538 bytes22 !23 version 12.224 no service timestamps log datetime msec25 no service timestamps debug datetime msec26 no service password-encryption27 !28 hostname yinzhengjie29 !30 !31 !32 !33 !34 !35 !36 !37 !38 !39 !40 !41 !42 !43 !44 !45 !46 !47 interface FastEthernet0/048  ip address 192.168.1.254 255.255.255.049  duplex auto50  speed auto51 !52 interface FastEthernet0/153  ip address 192.168.2.1 255.255.255.054  duplex auto55  speed auto56 !57 router rip58  version 259  network 192.168.1.060  network 192.168.2.061  no auto-summary62 !63 ip classless64 !65 !66 !67 !68 !69 !70 !71 line con 072 !73 line aux 074 !75 line vty 0 476  login77 !78 !79 !80 end81 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.010 Router(config-if)#exit 11 Router(config)#interface fastEthernet 0/112 Router(config-if)#no shutdown 13 14 Router(config-if)#15 %LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up16 Router(config-if)#ip address 192.168.3.1 255.255.255.017 Router(config-if)#18 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up19 20 Router(config-if)#ex21 Router(config)#router rip 22 Router(config-router)#version 223 Router(config-router)#no auto-summary 24 Router(config-router)#network 192.168.2.025 Router(config-router)#network 192.168.3.026 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 up11 %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up12 yinzhengjie(config-if)#ip address 192.168.4.254 255.255.255.013 yinzhengjie(config-if)#exit 14 yinzhengjie(config)#router rip 15 yinzhengjie(config-router)#version 216 yinzhengjie(config-router)#no auto-summary 17 yinzhengjie(config-router)#network 192.168.3.018 yinzhengjie(config-router)#network 192.168.4.019 yinzhengjie(config-router)#
Route2配置过程

 

转载于:https://www.cnblogs.com/yinzhengjie/p/6514932.html

你可能感兴趣的文章
ShiroFilterFactoryBean源码及拦截原理深入分析
查看>>
boost mutex以及scoped_lock应用
查看>>
小鸡吃米
查看>>
FFmpeg AVFMT_NOFILE宏定义剖析
查看>>
Windows Server 2008 R2活动目录回收站
查看>>
能吃遍全世界的方便面,你也是人生赢家
查看>>
为什么使用LR11录制完,发现脚本每个页面都被录制了两遍?
查看>>
Fedora 删除旧内核
查看>>
浏览器静态资源的版本控制新思路.强制更新指定资源缓存.的探讨
查看>>
NSCalendar
查看>>
Ios 入门 ----WebView 控件
查看>>
scala编译错误
查看>>
VMware Horizon 6 介绍
查看>>
ansible的使用
查看>>
2012年2月10日
查看>>
Linux下Web服务器应用之网站安全-https
查看>>
关于循环嵌套循环
查看>>
Scala中常见的容器 Option(选项)
查看>>
算法-蛇型矩阵
查看>>
路由交换IOS的备份与还原
查看>>