思科、华为全系列交换机路由器常用命令.doc
交换机/路由器配置综合复习交换机/路由器常用命令汇总HTTP:/本课内容交换机常用命令路由器常用命令2交换机常用命令重点难点路由器常用命令交换机常用命令路由器常用命令31.交换机常用命令·>Enable 进入特权模式··#Exit#End返回上一级操作模式返回到特权模式·#write memory 或copy running-configstartup-config保存配置文件·#del flash:config.text删除配置文件(交换机及1700系列路由器)·#del flash:vlan.dat 删除Vlan配置信息(交换机)·(config)# hostname switchA配置设备名称为switchA41.交换机常用命令·(config)#enable secret level 1 0 star配置远程登陆密码为star·(config)#enable secret level 15 0 star 配置特权密码为star·Level 1为普通用户级别,可选为115,15为最高权限级别;0表示密码不加密·(config)#enable services web-server 开启交换机WEB管理功能·Services 可选以下:web-server(WEB管理)、telnet-server(远程登陆)等51.交换机常用命令查看信息·#show running-config查看当前生效的配置信息·#show interface fastethernet 0/3查看F0/3端口信息·#show interface serial 1/2 查看S1/2端口信息·#show interface查看所有端口信息·#show ip interface brief 以简洁方式汇总查看所有端口信息·#show ip interface 查看所有端口信息·#show version查看版本信息61.交换机常用命令查看信息·#show mac-address-table查看交换机当前MAC地址表信息·#show running-config 查看当前生效的配置信息··#show vlan#show vlan id 10查看所有VLAN信息查看某一VLAN (如VLAN10)的信息·#show interface fastethernet 0/1switchport 查看某一端口模式(如F 0/1)·#show aggregateport 1 summary查看聚合端口AG1的信息71.交换机常用命令查看信息·#show spanning-tree查看生成树配置信息·#show spanning-tree interface fastethernet0/1 查看该端口的生成树状态·#show port-security 查看交换机的端口安全配置信息·#show port-security address查看地址安全绑定配置信息·#show ip access-lists listname 查看名为listname的列表的配置信息·#show access-lists81.交换机常用命令端口的基本配置·(config)#Interface fastethernet 0/3 进入F0/3的端口配置模式·(config)#interface range fa 0/1-2,0/5,0/7-9 进入F0/1、F0/2、F0/5、F0/7、F0/8、F0/9的端口配置模式·(config-if)#speed 10 配置端口速率为10M,可选10,100,auto91.交换机常用命令端口的基本配置·(config-if)#duplex full配置端口为全双工模式,可选full(全双工),half(半双式),auto(自适应)··(config-if)#no shutdown 开启该端口(config-if)#switchport access vlan 10 将该端口划入VLAN10中,用于VLAN·(config-if)#switchport mode trunk将该端口设为trunk模式, 可选模式为access , trunk·(config-if)#port-group 1将该端口划入聚合端口AG1中,用于聚合端口101.交换机常用命令聚合端口的创建·(config)# interface aggregateport 1创建聚合接口AG1·(config-if)# switchport mode trunk配置并保证AG1为 trunk 模式·(config)#int f0/23-24·(config-if-range)#port-group 1将端口(端口组)划入聚合端口AG1中111.交换机常用命令生成树·(config)#spanning-tree开启生成树协议·(config)#spanning-tree mode stp 指定生成树类型为stp可选模式stp , rstp , mstp·(config)#spanning-tree priority 4096 设置交换机的优先级为4096 , 优先级值小为高。优先级可选值为0,4096,8192,为4096的倍数。交换机默认值为32768121.交换机常用命令VLAN的基本配置·(config)#vlan 10创建VLAN10··(config-vlan)#name abc 命名VLAN为abc(config-if)#switchport access vlan 10 将该端口划入VLAN10中某端口的接口配置模式下进行·(config)#interface vlan 10进入VLAN 10的虚拟端口配置模式·(config-if)#ip address 192.168.1.1255.255.255.0 为VLAN10的虚拟端口配置IP及掩码,二层交换机只能配置一个IP,此IP是作为管理IP使用,例如,使用Telnet的方式登录的IP地址·(config-if)#no shutdown启用该端口131.交换机常用命令端口安全·(config-if)# switchport port-security开启该端口的安全功能配置最大连接数限制·(config-if)# switchport port-secruitymaxmum 1 配置端口的最大连接数为1,默认最大为128·(config-if)# switchport port-secruityviolation shutdown 配置安全违例的处理方式为shutdown,可选为protect (当安全地址数满后,将未知名地址丢弃)、restrict(当违例时,发送一个Trap通知)、shutdown(当违例时将端口关闭,并发送Trap14通知,可在全局模式下用errdisable recovery来恢复)1.交换机常用命令三层路由功能(针对三层交换机)·功能(config)# ip routing开启三层交换机的路由·(config)# interface fastethernet 0/1·(config-if)# no switchport开启端口的三层路由功能(这样就可以为某一端口配置IP)·(config-if)# ip address 192.168.1.1255.255.255.0·(config-if)# no shutdown151.交换机常用命令三层交换机路由协议·(config)# ip route 172.16.1.0255.255.255.0 172.16.2.1 配置静态路由·注:172.16.1.0 255.255.255.0 为目标网络的网络号及子网掩码·172.16.2.1 为下一跳的地址,也可用接口表示,如ip route 172.16.1.0 255.255.255.0 serial1/2(172.16.2.0所接的端口)·(config)# router rip开启RIP协议进程·(config-router)# network 172.16.1.0申明本设备的直连网段信息161.交换机常用命令三层交换机路由协议·(config-router)# version 2开启RIP V2,可选为version 1(RIPV1)、version 2(RIPV2)·(config-router)# no auto-summary关闭路由信息的自动汇总功能(只有在RIPV2支持)·(config)# router ospf 1开启OSPF路由协议进程(部分型号需要加OSPF进程ID)·(config-router)# network 192.168.1.00.0.0.255 area 0申明直连网段信息,并分配区域号(area0为骨干区域)171.交换机常用命令IP ACL:··交换机采用标准和扩展命名的访问控制列表1.标准ACL(config)#ip access-list stand listname 定义命名标准列表,命名为listname,stand为标准列表·(config-std-nacl)#deny 192.168.30.00.0.0.255 拒绝来自192.168.30.0网段的IP流量通过·注:deny:拒绝通过;可选:deny(拒绝通过)、permit(允许通过)·192.168.30.0 0.0.0.255:源地址及源地址通配符;可使用any表示任何IP·(config-std-nacl)#permit any181.交换机常用命令2.扩展ACL··扩展·(config)#ip access-list extended listname定义命名扩展列表,命名为listname,extended为(config-ext-nacl)#deny tcp目的地址及目的地址通配符 源地址及源地址通配符 eq www 拒绝源地址为192.168.30.0网段的IP访问目的地址为192.168.10.0网段的WWW服务·tcp: 协议名称,协议可以是udp, ip,eigrp,gre, icmp, igmp, igrp等等。·eq:操作符(lt-<,eq-=,gt->,neg-<>,19range-包含)1.交换机常用命令··www:端口号,可使用名称或具体编号可以使用的协议名称(或编号)和端口名称(或编号)请打?查询。·(config-ext-nacl)#permit ip any any允许其它通过··(config)#interface vlan 10进入端口配置模式(config-if)# ip access-group listname in访问控制列表在端口下in方向应用;可选:in(入栈)、out(出栈)·注:配置ACL时,若只想对其中部分IP进行限制访问时,必须配置允许其流量通过,否则设备只会对限20制IP进行处理,不会对非限制IP进行允许通过处理。1.交换机常用命令2.扩展ACL··(config)#ip access-list extended listname定义命名扩展列表(config-ext-nacl)#deny tcp目的地址及目的地址通配符 源地址及源地址通配符 eq www 拒绝源地址为192.168.30.0网段的IP访问目的地址为192.168.10.0网段的WWW服务·tcp: 协议名称,协议可以是udp, ip,eigrp,gre, icmp, igmp, igrp等等。·eq:操作符(lt-小于,eq-等于,gt-大于,neg-不等于,range-包含)·www:端口号,可使用名称或具体编号211.交换机常用命令2.扩展ACL·(config-ext-nacl)#permit ip any any允许其它通过·(config-ext-nacl)#end返回··(config)#interface vlan 10 进入端口配置模式(config-if)# ip access-group listname in访问控制列表在端口下in方向应用;可选:in(入栈)、out(出栈)·注:配置ACL时,若只想对其中部分IP进行限制访问时,必须配置允许其流量通过,否则设备只会对限制IP进行处理,不会对非限制IP进行允许通过处理。222.路由器常用命令·远程登陆(telnet)(config)# line vty 0 4 进入线路04的配置模式,4为连续线路最后一位的编号,线路为04(conifg-line)#login(config-line)#password star为star配置远程登陆密码(config-line)#end返回上层232.路由器常用命令·端口的基本配置(config)# interface serial 1/2 进入端口S1/2的配置模式(config-if)#ip address 1.1.1.1 255.255.255.0配置端口IP及掩码(config-if)# clock rate 64000 配置时钟频率(DCE)(config-if)# bandwidth 512 配置端口带宽速率为512KB(单位为KB)(config-if)# no shutdown 开启该端口(config-if)#encapsulation PPP 定义封装类型,可选项:Frame-relay帧中继、Hdlc高级数据链路控制协议、lapb X.25的二层协议、PPP PPP点到点协议、 24X25 X.25协议2.路由器常用命令·路由协议(config)# ip route 172.16.1.0 255.255.255.0172.16.2.1 配置静态路由172.16.2.1 为下一跳的地址,也可用接口表示,如iproute 172.16.1.0 255.255.255.0 serial1/2(172.16.2.0所接的端口)(config)# router rip开启RIP协议进程(config-router)# network 172.16.1.0备的直连网段信息(config-router)# version 2申明本设开启RIPV2,可选为version 1(RIPV1)、version 2(RIPV2)(config-router)# no auto-summary息的自动汇总功能(只有在RIPV2支持)关闭路由信252.路由器常用命令路由协议·(config)# router ospf 1 开启OSPF路由协议进程(部分机型需要加OSPF进程ID)(config-router)# network 192.168.1.0 0.0.0.255area 0申明直连网段信息,并分配区域号(area0为骨干区域)RA(config)#int serial/0RA(config-if)#ip address 172.16.2.1255.255.255.0RB(config)#int serial/0RB(config-if)#ip address 172.16.2.2255.255.255.0 secondary262.路由器常用命令·PAP路由器Ra为被验证方、 Rb为验证方; 两路由器用V.35线连接(串口线),分别配置各端口的IP及时钟频率后:Rb(config)# username Ra password 0 star验证方配置被验证方的用户名,密码Rb(config)# interface serial 1/2 进入S1/2端口Rb(config-if)# encapsulation ppp 定义封装类型Rb(config-if)# ppp authentication papPPP启用PAP认证方式272.路由器常用命令·PAP路由器Ra为被验证方、 Rb为验证方; 两路由器用V.35线连接(串口线),分别配置各端口的IP及时钟频率后:Ra(config)# interface serial 1/2Ra(config-if)# encapsulation ppp进入S1/2端口定义封装类型为PPPRa(config-if)# ppp pap sent-username Rapassword 0 star 设置用户名为ra 密码为star,用于发送到验证方进行验证#debug ppp authentication可选命令:观察PAP验证过程(如果没看到验证消息,则将端口shutdown,28然后再no shutdown,即可看到验证过程的相关信息)2.路由器常用命令·CHAP路由器Ra、 Rb, 两路由器用V.35线连接(串口线),分别配置各端口的IP及时钟频率后:·被验证方配置:Ra(config)# username Rb password 0star以对方的主机名作为用户名,密码和对方的路由器一致Ra(config)# interface serial 1/2Ra(config-if)# encapsulation PPP进入S1/2端口定义封装类型为PPP292.路由器常用命令·CHAP路由器Ra、 Rb, 两路由器用V.35线连接(串口线),分别配置各端口的IP及时钟频率后:·验证方配置:Rb(config)# username Ra password 0 star以对方的主机名作为用户名,密码和对方的路由器一致Rb(config)# interface serial 1/2Rb(config-if)# encapsulation PPP型为PPP进入S1/2端口定义封装类Rb(config-if)# ppp authentication chap用CHAP方式验证PPP启302.路由器常用命令·PAP与CHAP的区别:1. PAP:被验证方发送用户名、密码到验证方进行身份验证,所以需要在端口模式下设置Ra(config)#ppp pap sent-username Ra password 0 star;验证方需要定义用户和密码配对数据库记录,所以要定义命令:Rb(config)# username Ra password 0 star2. Chap:CHAP由验证方主动发起挑战,由被验证方应答进行验证(三次握手),所以验证方要配置命令:Rb(config-if)#ppp authentication chap。验证方与被验证方双方都要配置用户名和密码,验证期间双方密码要相同,用户名就用对方路由器的名称。312.路由器常用命令静态NAT:用于IP到IP的转换(config)# ip nat inside source static192.168.1.1 10.10.10.1定义内部源地址静态转换关系,192.168.1.1为内部本地地址,10.10.10.1为内部全局地址(即外网地址)。(conifg)# interface fastethernet 0进入端口配置模式,用于连接内网的端口(config-if)# ip nat inside 定义该端口为连接内部网络(config)# interface serial 0进入端口配置模式,用于连接外网的端口(config-if)# ip nat outside 定义该端口为连接外32部网络2.路由器常用命令动态NAT:如果有多个已注册的公有IP,则这些公有IP可以作为内部全局地址。内网的多个内部本地地址可以转换为前面的多个内部全局地址。 (config)#ip nat pool poolname 202.16.1.1 202.16.1.10netmask 255.255.255.0(config)# access-list 1 permit 172.16.1.00.0.0.255定义允许转换的本地IP地址(config)# ip nat inside source list 1 poolpoolname(conifg)# interface fastethernet 0(config-if)# ip nat inside(config)# interface serial 0(config-if)# ip nat outside332.路由器常用命令动态NAPT:常用于多个内网的IP共用一个外网的IP上网,是“IP+端口号”到“IP+端口号”的转换。(config)# ip nat pool poolname 202.16.1.1202.16.1.1 netmask 255.255.255.0(config)# access-list 1 permit 192.168.1.00.0.0.255内网待转换的IP地址(config)# ip nat inside source list 1 poolpoolname overload定义内部源地址转换关系*动态NAT与动态NAPT的命令差别在关键字overload,有则为动态NAPT,无则为动态NAT(conifg)# interface fastethernet 0(config-if)# ip nat inside(config)# interface serial 0(config-if)# ip nat outside34本课小结交换机常用命令路由器常用命令35谢谢!