《2022年CISCO基本命令配置 .pdf》由会员分享,可在线阅读,更多相关《2022年CISCO基本命令配置 .pdf(15页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、为路由器或交换机配置密码#config t#enable password lqihdx(明文密码)#enable secret lqihdx(加密密码)路由器远程连接制配置#config t#line vty 0 4(配置为五个虚拟终端)#password lqihdx#login 注释:远程登入IP为端口 IP 交换机远程连接配置(CISCO 2950和 3550 就要这样配,其他的不清楚)#config t#interface vlan 1#ip add 110.110.110.254 255.255.255.0#exit#line vty 0 4#enable secret 123#l
2、ogin 注释:必须和管理地址在同一网段在三层交换机中配置vlan 的子网关(同VLAN中配置多个网关)#interface vlan 10#ip add 192.168.2.1 255.255.255.0#ip add 192.168.3.1 255.255.255.0 secondary 在路由器中配置单臂路由(子接口)(使不同 VLAN不同网段之间通信)#interface f0/0#no shu#ip add 192.168.1.0 255.255.255.0#interface f0/0.1#encapsulation dot1Q 10(10 表示 VLAN 10)#ip add 1
3、92.168.2.1 255.255.255.0#interface f0/0.2#encapsulation dot1Q 20#ip add 192.168.3.1 255.255.255.0 vlan 配置(在虚拟机中只能在数据库模式下)#en#vlan database#vlan 20 name lqihdx#vlan 10#exit 名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 15 页 -Vlan(虚拟局域网)#config t#vlan 10#name lxg(给 VLAN 10命名)#configure terminal#interface f0/0#switch
4、port mode access(永久性关闭接口中继,一般在直连PC的接口上才需要)#switchport access vlan 10#show vlan-switch(查看 VLAN状态)vlan(在真实机中一般在全局模式下,数据库模式正在被淘汰)#en#configure terminal#vlan 10#name lqihdx#exit vlan trunk(中继链路)#interface f0/0#switchport trunk encapsulation dot1q(把封装类型设为dot1q)#switchport mode trunk loopback 接口#interface
5、 loopback 0#ip add 192.168.0.1 255.255.255.0 以太网通道(PAgP,LACP)PAgp#interface range fastethernet 0/1-2#channel-protocol pagp(默认可不输此命令(pagp 是 CISCO专有的协议。LACP是 IEEE802.3ad标准协议)#channel-group 1 mode desirable(1 为以太网道号可是1-48)#show etherchannel summary 在三层交换机中配置路由和IP#en#config terminal#ip routing#interface
6、 vlan 10(以 VLAN配 IP使不同 vlan 间可通信)#ip address 192.168.1.1 255.255.255.0#no shu(可不输)#interface f0/0#no switchport(关闭交换机功能,使其进入路由状态)#no shu#ip address 192.168.2.1 255.255.255.0#router rip 名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 15 页 -#version 2#no auto-summary#network 192.168.1.0#network 192.168.2.0 三层交换机配置DHCP
7、中继#interface vlan 2#ip add 192.168.2.1 255.255.255.0#ip helper-address 192.168.100.100(192.168.100.100为 DHCP服务器的IP地址)注释:需在每个VLAN中配置此命令,只要是想动态获得IP的 VLAN都需要(ip helper-address 192.168.100.100)VTP#en#vlan database(在小凡中只能在数据库模式中创建VTP)#vtp domain lqihdx(vtp域名为 lqihdx)#vtp servervtp 模式为 Server.有三种模式server:
8、服务器|client:客户机|transparent:透明#vtp password hehe(vtp 密码为 HEHE)#vtp pruning(VTP 修剪)#vlan 10 name lqihdx#vlan 20 STP(生成树配置)SW#config terminal SW#spanning-tree vlan 5,10-20 priority 4096(修改优先级指定根网桥)#SW#spanning-tree vlan 50 root primary(用命令指定根网桥,交换机的优先级变成24576。secondary 优先级变成28672)#SW#spanning-tree vlan
9、 100 cost 10(用命令更改F0/1 端口成本)SW#spanning-tree vlan 100 port-priority 96(用命令更改F0/1 端口的优先级)#spanning-tree portfast(配置速端口)#end#show spanning-tree MST(多生成树)#en#config t#spanning-tree mode mst(启用 MST 模式)(不知道为什么在虚拟机上启用不了MST。10:30 2010-6-7)#spanning-tree mst configuration(进入 MST模式)#name lqihdx(MST 区域名)#revi
10、sion 10(配置修订号)#instance 1 vlan 10-20,31,40(将 VLAN映射到 MST实例)#instance 2 valn 5-8#exit 名师资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 15 页 -#spanning-tree mst 1 root primary(设置 MST 实例的优先级)01 或#spanning-tree mst 1 priority 4096(设置 MST 实例的优先级)02#spanning-tree mst 2 priority 4096 在其它需要配置负载均衡的交换机上做相同的配置即可实现VLAN的负载均衡HSRP(
11、热备份)sw1#interface vlan 2#ip address 192.168.2.1 255.255.255.0#standby 2 ip 192.168.2.254 255.255.255.0(配置虚拟IP 地址)#standby 2 priority 150(配置优先级)#standby 2 preempt(配置占先权)#standby 2 track fastethernet 0/1 100(配置端口跟踪)#standby 2 track f0/23 100#exit#interface vlan 3#ip add 192.168.3.1 255.255.255.0#stand
12、by 3 ip 192.168.3.254#standby 3 preempt#sw2#interface vlan 2#ip add 192.168.2.2 255.255.255.0#standby 2 ip 192.168.2.254 255.255.255.0#standby 2 preempt#exit#interface vlan 3#ip add 192.168.3.2 255.255.255.0#standby 3 ip add 192.168.3.254 255.255.255.0#standby 3 priority 150#standby 3 preempt#standb
13、y 3 track f0/1 100#standby 3 track f0/23 100#end#show standby(查看 HSRP详细信息)#show standby brief(查看 HSRP简要信息)ACL(标准访问控制列表)#en#config t#access-list 10 permit 192.168.1.0 0.0.0.255(充许 192.168.1.0 网段通过)#access-list 10 deny any(拒绝所有流量,除192.168.1.0)#interface f0/0#ip access-group 10 in(将配置应用到F0/0 接口中,OUT:出站
14、。IN:进站)#end 名师资料总结-精品资料欢迎下载-名师精心整理-第 4 页,共 15 页 -#show access-lists 扩展访问控制列表#en#config t#access-list 101 permit ip 192.168.1.0 0.0.0.255 192.168.2.0 0.0.0.255#access-list 101 deny ip any any#access-list 101 deny icmp 192.168.1.0 0.0.0.255 host 192.168.2.2 echo#exit#interface f0/0#ip access-group 101
15、 in#no access-list 101(删除 101 列表)命名访问控制列表#en#config t#ip access-list standard lqihdx(标准访问列表)#permit host 192.168.1.1(充许主机192.168.1.1 的流量通过)或 15 permit host 192.168.2.1(配置 ACL语句序列号为15)#deny any any#end#show access-lists(查看 ACL配置)#ip access-list extended lqihdx(扩展访问列表)#permit tcp 192.168.1.0 0.0.0.255
16、 192.168.2.0 0.0.0.255 eq 21#interface f0/0#ip access-group lqihdx out mac access-list extended lxg(基于 MAC 命名的扩展访问控制列表)per host 001a.4d8d.fa04 any exit interface f0/1 mac access-group lxg in 注释:主要用于接口绑定PC的 MAC 地址配置时间范围router(config)#time-range mytime(名叫 MYTIME)#periodic weekdays 8:30 to 17:30(周一至周五的
17、8:30 到 17:30)(weekend:周六和周日。monday:一。tuesday:二。wednesday:三。daily:每天)#exit#access-list 101 permit ip any any time-range mytime(将时间应用到ACL中)#int f0/0#ip access-group 101 in NAT 静态 NAT 名师资料总结-精品资料欢迎下载-名师精心整理-第 5 页,共 15 页 -#en#config t#ip nat inside source static 192.168.100.2 61.159.62.130(将内部局部地址192.16
18、8.100.2 转换为内部全局地址61.159.62.130)#interface f0/0#ip nat outside#interface f1/0#ip nat inside#ip route 0.0.0.0 0.0.0.0 61.159.62.129#ip nat inside source tcp 192.168.100.2 80 61.159.62.131 8080 extendable(将 WEB服务器192.168.100.2 的 80 端口转换成了61.159.62.131 的 8080 端口中)动态 NAT#ip nat pool lqihdx01 61.159.62.13
19、1 61.159.62.190 netmask 255.255.255.192(动态地址池)#ip nat inside source list 1 pool lqihdx01(访问控制列表1 中的局部地址转换为lqihdx01 地址池中定义的全局IP地址)#interface f0/0#ip nat outside pat(端口复用)#access-list 1 permit 10.1.1.0 0.0.0.255#ip nat inside source list 1 interface f0/0 overload#interface f0/0#ip nat oudisde#interfac
20、e f1/0#ip nat inside RIP(动态路由协议)#router rip#version 2#no auto-summary#network 192.168.1.0#network 192.168.2.0 ospf#router ospf 10#router-id 1.1.1.1#network 192.168.1.0 0.0.0.255 area 0#network 1.1.1.1 0.0.0.0 ar 0#network 192.168.2.0 0.0.0.255 area 1#network 192.168.4.0 0.0.0.255 ar 1#interface f0/0
21、#ip ospf priority 200(给接口配置优先级,选举DR与 BDR由路由器)#只要一台路由器的两个接口被配置到不同的区域,那么这台路由器就会成为ABR 名师资料总结-精品资料欢迎下载-名师精心整理-第 6 页,共 15 页 -#clear ip ospf(清空 OSPF)配置末梢区域和完成末梢区域#只有一个默认路由作为其区域的出口#区域不能作为虚链路的穿越区域#Stub 区域里无自治系统边界路由器ASBR#不是骨干区域AREA 0#末梢区域#router ospf 10#net 10.10.10.0 0.0.0.255 ar 0#area 2 stub(此命令需要在Stub 区域
22、内的所有路由器上配置)#完全末梢区域#router ospf 10#net 10.10.10.0 0.0.0.255 ar 0#net 10.10.20.0 0.0.0.255 ar 2#area 2 stub no-summary(no-summary 使用此参数来生成Totally Stubby 区域,仅用于ABR,以阻止 ABR发送汇总链路通告到完全末梢区域内)#router ospf 10#net 10.10.11.0 0.0.0.255 ar 2#net 10.10.20.0 0.0.0.255 ar 2#area 2 stub 路由重分发#route ospf 1#redistri
23、bute rip subnets(重分发 RIP路由)#redistribute staic subnets(重分发静态路由)#redistribute connected subnets(重分发直连路由)#default-information originate(重分发默认路由)#redistribute eigrp 10 subnets(重分发 EIGRP路由)#route rip#redistribute ospf 1 metric 15(重分发 OSPF路由,在 RIP重分发 OSPF时需要指定METRIC度量值,否则在RIP中无法学到重分发的路由条目)#redistribute e
24、igrp 10 metric 15#route eigrp 10#redistribute ospf 10 metric 1544 5 255 1 150(那五个数字分别为:带宽、延迟、可靠性、负载、MTU)下图为接口F0/0 信息。BW:带宽DLY:延迟reliability:可靠性load:负载名师资料总结-精品资料欢迎下载-名师精心整理-第 7 页,共 15 页 -#redistribute rip metric 1544 5 255 1 150#由于 OSPF网络中 Stub 区域不允许存在ASBR,所以在一台属于Stub 区域的路由器上配置重分发路由到OSPF区域中是无法实现的。NS
25、SA(非纯末梢区域)#router ospf 1#router-id 192.168.1.2#area 1 nssa#network 192.168.1.2 0.0.0.0 ar 0#net 10.0.0.4 0.0.0.3 ar 0#NSSA运行的是 LSA7类路由连接在末梢网络的某台路由器必须通过Area 2 的其中一台路由器和OSPF网络相连。但是,该路由器仅支持,因此,AREA 2的那台路由器将同时运行RIP协议和 OSPF协议,并利用路由重分发把该路由器学到的RIP路由信息注入到OSPF区域。ASA防火墙ASA#configure terminal ASA#hostname lqih
26、dx(配置主机名为LQIHDX)ASA#domain-name (配置域名为LQIHDX。COM)ASA#enable password lqihdx(配置特权密码为LQIHDX)名师资料总结-精品资料欢迎下载-名师精心整理-第 8 页,共 15 页 -ASA#passwd cisco(配置远程登录密码)#接口配置ASA#interface e0/0 ASA#nameif inside(inside 默认安全级别为100。DMZ 为 50。OUTSIDE为 0)ASA#security-level 100(安全级别为100。值越大表示安全级别越高。0100)ASA#ip add 10.1.1.
27、1 255.255.255.0#默认路由#route outside 0.0.0.0 0.0.0.0 200.0.0.1#NAT转换ASA#nat-control ASA#nat(inside)1 0 0(inside 上的所有IP)#global(outside)1 int(inside 上 IP将被成 OUTSIDE上的 IP)从高安全级别访问低高全级别要配NAT转换.#ACL访问列表ASA#static(dmz,outside)200.1.1.253 192.168.1.1(静态 NAT转换)#access-list lqihdx permit tcp any host 200.1.1.
28、253 eq www#access-group lqihdx in int outside(将 ACL列表加入到OUTSIDE接口)从低安全级别接口访问高安全级别接口要配置ACL#access-list lqihdx02 permit icmp any any echo-reply(禁止 ICMP的 PING 包穿越 ASA防火墙)#配置日志没写,在S2 网络安全高级应用书中的第57 面。(本人还没有怎么去理解此文,日后可能会添加)0.0 流量整形配置(qos)1)基本流量整形配置#interface ethernet 0/0#traffic-shape rate 1000000(缓存区流量)
29、#2)基于 ACL的流量整形配置#access-list 100 permit udp any any#interface e0/1#traffic-shape group 100 1000000 1000000 1000000(三个 1000000 各为:整形限定速率。突发量。过量突发量.)#end#show traffic-shape e0/0(查看 GTS配置信息)#承诺访问速率1)基本承诺访问速率#interface f0/0#rate-limit input 8000000 2000 4000 conform-action transmit exceed-action drop(in
30、put:端口入名师资料总结-精品资料欢迎下载-名师精心整理-第 9 页,共 15 页 -方向的流量,出方向的是OUTPUT。8000000:承诺访问速率(bt),2000:普通突发量。4000:最大突发量。transmit:合规流量被转发,drop:违规流量被丢弃。)#interface f0/0#rate-limit input 8000000 2000 4000 conform-action set-prec-transmit 5 exceed-action set-prec-transmit 0(符合的流量被标记IP优先级 5 后进行转发,超出的流量被标记IP优行级 0 后进行转发)2)
31、扩展的承诺访问速率#access-list 100 permit udp any any#interface f0/0#rate-limit input access-group 100 8000000 2000 4000 conform-action transmit exceed-action drop CAR的另一种配置r2(config)#access-list 90 permit host 192.168.0.1 r2(config)#class-map lxg r2(config-cmap)#mat access 90 r2(config-cmap)#exit r2(config)
32、#policy-map lxg02 r2(config-pmap)#class lxg r2(config-pmap-c)#police 8000000 8000 conform-action transmit exceed-action drop(比特为单位)(8000000 为承诺流量,8000 突发流量)r2(config-pmap-c-police)#interface f0/0 r2(config-if)#service-policy input lxg02 r2(config-if)#service-policy output lxg02 拥塞管理配置 CBWFQ#access-l
33、ist 100 permit ip host 10.0.1.2 host 10.0.0.7#access-list 101 permit ip host 10.0.1.2 host 10.0.0.1#class-map match-all ihdx02(定义匹配策略。match-all:匹配 class-map 定义的所有条件。)#match access-group 101#class-map match-all ihdx01#match access-group 100#policy-map ihdx(调用 class map 配置策略)#class ihdx01#bandwidth 80
34、000(拥塞时带宽为80000kbits/s)#exit#class ihdx02#bandwidth 40000#exit 名师资料总结-精品资料欢迎下载-名师精心整理-第 10 页,共 15 页 -#class class-default(其他流量为缺省类)#fair-queue(启用公平队列)#exit#exit#interface f0/1#service-policy output ihdx#end#show policy-map(查看 POLICY-MAP配置信息)路由器 IPSec VPN ASA#crypto isakmp policy 1(管理策略)#encryption 3
35、des(管理连接时采用的加密算法,用于身份验证)#hash sha(验证过程采用HMAC 的功能)#authentication pre-share(身分验证的方式)#group 2(指定 DH 密钥组,组号越大算法越安全,占用资源越多)#lifetime 10000(生存周期,默认不写也可)#crypto isakmp key 6 lqihdx address 200.0.0.1(预共享密钥)#access-list 100 permit ip 172.16.10.0 0.0.0.255 10.10.33.0 0.0.0.255(指定需要被保护的流量)#crypto ipsec transf
36、orm-set lqihdx-set esp-des ah-sha-hamc(定义匹配的传输集.esp-3des esp-sha-hmac)#mode tunnel(隧道模式,默认为此模式。MODE TRANSPORT:传输模式)#exit#crypto map lqihdx-map 1 ipsec-isakmp#set peer 200.0.0.1#set transform-set lqihdx-set#match address 100#interface f0/0#crypto map lqihdx-map AH 协议只提认证的功能,而ESP协议同时提供加密和认证功能。NAT豁免ASA
37、#access-list nonat extended permit ip 192.168.1.0 255.255.255.0 10.10.1.0 255.255.255.0#nat(inside)0 access-list nonat#防火墙(ASA)VPN#crypto isakmp enable outside#crypto isakmp policy 1#encryption aes#hash sha#authentication pre-share#group 1#isakmp key benet address 200.0.0.1#access-list yfvpn extende
38、d permit ip 172.16.10.0 255.255.255.0 10.10.33.0 255.255.255.0#crypto ipsec transform-set benet-set esp-aes esp-sha-hmac 名师资料总结-精品资料欢迎下载-名师精心整理-第 11 页,共 15 页 -#crypto map bennet-map 1 match address yfvpn#crypto map benet-map 1 set peer 200.0.0.1#crypto map benet-map 1 set transform-set benet-set#cry
39、pto map benet-map interface outside(将 Crypto Map 应用到 OUTSIDE接口)#end#show crypto isakmap sa(查看管理连接所处的状态)远程 VPN(Easy VPN)服务器#当路由器作为Easy VPN服务器时,不支持以下选项1)采用 RSA加密随机数或者DSS证书来做设备验证2)DH 组织 1 密钥3)AH 用作数据封装4)传输模式用作数据连接5)IPSec over TCP和 IPSec over UDP,但支持标准的NAT-T 路由器与软件客户端的配置#en#config t#aaa net-model(启动 AAA
40、)#aaa authentication login vpn_authen local(启用 AAA 登录身份验证,名为vpn_authen.验证方法为 LOCAL:本地)#aaa authorization network vpn_author local(启用 AAA 网络授权,授权列表名为VPNAUTHOR,授权方法为LOCAL)#username cisco password cisco(定义用户名和密码。验证方法为LOCAL时,需要在路由器本地定义用户名和密码)#crypto isakmp policy 10#encryption aes 128#hash sha#authentic
41、ation pre-share#group 2#exit#ip local pool vpn_pool 192.168.1.1 192.168.1.200(给远程用户分配一个内部IP地址池,名为VPN_POOL)#access-list 101 permit ip 101.10.1.0 0.0.0.255 any(定义需要被保护的流量)#crypto isakmp client configuration group vpn_group(定义组)#key groupkey(建立预共享密钥,用于组的验证)#pool vpn_pool(指定地址池)#acl 101(建立分离隧道)#exit#cry
42、pto ipsec transform-set vpn_transform esp-aes esp-sha-hmac(传输集)#exit#crypto dynamic-map vpn_dymap 10(动态 Crypto Map)#set transform-set vpn_transform#exit#crypto map mymap client authentication list vpn_authen(使用 vpn_authen 列表名验证用户)名师资料总结-精品资料欢迎下载-名师精心整理-第 12 页,共 15 页 -#crypto map mymap isakmp authori
43、zationlist vpn_author(定义授权列表名VPN_author)#crypto map mymap client configuration address respond(指定客户端发起了IKE模式配置(respond))#crypto map mymap 1000 ipsec-isakmp dynamic vpn_dymap(引用之前定义的动态的crypto map#int s1/0#crypto map mymap eigrp 协议(也是一种路由发布协议)#interface f0/0#no shu#ip add 192.168.0.1 255.255.255.0#exi
44、t#route eigrp 10(区域 10)#no auto-summary(关闭路由自动汇总)#network 192.168.0.0 0.0.0.255#show ip route eigrp(.)#show ip eigrp neighbor(查看 EIGRP邻居路由器)#show ip protocols(查看当前路由器上运行的协议及其相关参数)#随文笔记no shutdown(打开端口)知道某个IP查找 IP对应在交换机上的接口(1)在三层交换机上查看那个接口的MAC 地址(show arp 用这个命令就能查看到IP对应接口的 MAC 地址)(2)查到对应MAC 地址后然后就在那台
45、二层交换机上查看MAC 地址对应的接口就行了(show mac|i 0050.7966.6800)查看交换机2950 f0/1 接口的流量(show interface f0/1)在二层交换机中查看对应PC接口?答:打开交换机输入terminal monitor 命令,然后在对应的PC上禁用或打开其中的一个网卡,然后在交换机就会有相应的提示,就能知道 PC对应的接口了。知道了其中一台PC的 IP然后查看在交换机上对应的接口?答:先在三层交换机上查接口MAC地址(show arp|include 192.168.1.10)然后在二层交换机上用对应的MAC 地址查接口(show mac-addre
46、ss-table i 002casd44)在三层交换机上用show mac-address-table|include f6/24查看 f6/24 接口学了哪些MAC地址名师资料总结-精品资料欢迎下载-名师精心整理-第 13 页,共 15 页 -show cdp neighbors(显示连接了多少个接口,如果其中的一个接口shudown 了就不会有显示)交换机重起命令reload 交换机恢复出厂默认恢复命令switch enable switch#erase startup-configure switch#reload csico2950 的密码恢复拔下交换机电源线。用手按着交换机的MODE
47、 键,插上电源线在 switch:后执行flash_ini 命令:switch:flash_ini查看 flash 中的文件:switch:dir flash:把“config.text”文件改名为“config.old”:switch:rename flash:config.text flash:config.old执行 boot:switch:boot交换机进入是否进入配置的对话,执行no:进入特权模式察看flash 里的文件:show flash:把“config.old”文件改名为“config.text”:switch:rename flash:config.old flash:co
48、nfig.text 把“config.text”拷 入 系 统 的“running-configure”:copy flash:config.text system:running-configure 把配置模式重新设置密码存盘,密码恢复成功。路由器文件操作:router#copy running-config startup-config;保存配置router#copy running-config tftp;保存配置到tftp router#copy startup-config tftp;开机配置存到tftp router#copy tftp flash:;下传文件到flash rout
49、er#copy tftp startup-config;下载配置文件在 CISCO设备上 PING 对应 IP 时:!响应成功接收名师资料总结-精品资料欢迎下载-名师精心整理-第 14 页,共 15 页 -?请求超时U 目的不可达P 协议不可达N 网络不可达Q 源抑制M 不能分段?不可知报文类型端口安全Interface f0/1 Sw port-security Sw port-security maximum 1 Sw port violation protect Sw po mac 001a.4d8d.fa04 Sw po mac sticky End Show port-security Show port-security add Show port-security interface f0/1 注释:主要用于接口与PC绑定双工和半双工模式的切换Interface f0/1 duplex full(全双工)(要是我们希望目标交换端口在发送信息包的同时也能够接受信息包,这个时候我们就应该将目标端口设置成全双工模式状态)duplex half(半双工)(希望目标交换端口在某一时刻只能从外面接受信息包或向外发送信息包时)名师资料总结-精品资料欢迎下载-名师精心整理-第 15 页,共 15 页 -
限制150内