交换机命令

交换机命令

该命令是cisco交换机的,其他交换机可能不一样。

下面的命令都可以缩写,如enable缩写成en,但不能有歧义(即这个缩写的英语单词只有那个)

路由器命令与交换机类似

1)用户模式:
    switch>
    	可以查看交换机的基本简单信息,但不能做任何修改配置!
    	
2)特权模式
    switch> enable
    switch#>
        可以查看所有配置,不能修改配置,但可以做测试、保存、初始化等操作
        
3)全局配置模式
    switch# configure terminal
    switch(config)#
        默认不能查看配置!
        可以修改配置,且全局生效!
        
4)接口配置模式:
    switch(config)#interface f0/1
    switch(config-if)#
        默认不能查看配置!
        可以修改配置,且对该接口生效!
        
5)console口/线/控制台配置模式:
    switch(config)#line console 0
        默认不能查看配置!
        可以修改配置,且对console口生效!

命令:
6、 exit 退出一级
    end 直接退到特权模式
7、支持命令缩写
8、?的用法:不用写/,直接写?
9、历史命令
10、tab补全键

11、配置主机名:
    configure terminal    #进入全局配置模式
    hostname 设置设备名

12、设置用户密码:
    line console 0    #进入console口/线/控制台配置模式
    password 密码
    login
    exit

13、快捷键:
    ctrl+u : 快速删除光标前所有字符
    ctrl+a : 快速定位光标到行首
    ctrl+e : 快速定位光标到行尾

14、
    在内存中存在一个文件:
    running-config
    第一次开机,系统会在内存中自动创建一个新的干净的running-config
15、配置
    enable    #进入特权模式
    copy running-config startup-config
    或
    write    #将当前的做好的配置写入【启动】中
    
16、交换机开机动作:
    先去硬盘中查找startup-config是否存在:
    如果不存在,内存中创建新的running-config
    如果存在,则复制到内存中并改名为running-config
    
17、查看running-config配置
    enable    #特权模式
    show running-config
18、查看startup-config配置
    enable    #特权模式
    show startup-config
    
19、重启设备:
    enable
    reload
    
20、配置特权密码:
    configure terminal    #全局配置模式
    enable password 密码(明文)   #查看时会显示密码
    enable secret 密码 (密文)   #查看时会显示md5加密后信息,同时设置两个,使用secret密码才能登录
    
21、查看MAC地址表
    enable
    show mac-address-table
22、查看接口状态列表:
    show ip interface brief
    ==show ip int b
    
23、手工关闭接口
	configure terminal
    interface f0/x    #x表示任意(交换机有的才行)
    shutdown
    exit
23、手工开启接口
    int f0/x
    no shutdown
    exit
    
24、do的用法
    其他模式加do空格可以强制使用特权模式的命令	
    如:
        do show running-config    #用do不能补全,难受
        do sh ip int b    #缩写
        do wr
        
25、删除配置
    1)在哪配置的,就在哪删!
    2)命令前加no 空格
    3)原命令中有参数,并且参数具有唯一性,则删除时不需要加参数
    如:
        conf t    #全局配置模式
        hostname sw1
 
        conf t
        no hostname
 
26、清空/擦除/初始化配置
    en    #特权模式
    erase start-config
    
27、为3层端口 配置IP:(路由器最初一般是人工down状态)
    int f0/0
    ip add 10.1.1.254 255.255.255.0
    no shutdown

28、开启远程控制:
    conf t    #全局配置模式
    line vty 0 4    #可同时4人同时控制(默认是telnet)
    transport input telnet/ssh/none/all
    password 密码	
    login    #开启密码验证,不用用户名
    exit
 
 	conf t    #ssh(比telnet安全)
    hostname r1
    ip domain-name r1.qf.com
    crypto key generate rsa   //生成密钥对
    line vty 0 4
    transport input telnet/ssh/none/all
    login local    #开启密码验证,需要用户名和密码
    exit
    username xx password 123.com
    
29、为交换机配置管理IP:
    conf t
    interface vlan 1
    ip address 10.1.1.253 255.255.255.0
    no shut
    
30、为交换机配置默认网关
    目的:可跨网段管理
    conf t
    ip defaut-gateway 10.1.1.254
    
31、关闭自动解析功能:
    conf t
    no ip domain-lookup

32、简写:
    interface range f0/1 - 24    #同时控制1到24的端口

33、静态路由配置
    conf t
    ip route 目标IP地址所处的网段 子网掩码 下一跳地址
    ip route 10.1.1.0 255.255.255.0 40.1.1.1

34、路由表和端口查看
    show ip route    #查看路由表
    show ip interface b    #查看端口状态

VLAN:
35、静态VLAN命令
    1)创建VLAN
       conf t
       vlan ID,ID,ID-ID
       [name 自定义名称](给VLAN取备注名字)
    2)查看VLAN表
      show vlan brief
    3)将端口加入到VLAN
      int f0/x
      switchport access vlan ID
      exit
36、trunk中继
    int f0/x 
    switchport trunk encapsulation dotlq/isl    #配置中继端口的协议
    switchport mode trunk    #设置端口模式为trunk
37、单臂路由
    interface f0/0.1
    encapsulation dot1q 10    #为该子端口封装dot1q协议,并与VLAN10关联
    ip add 。 。    #配置IP
38、路由器上部署DHCP服务器
    configure terminal
    ip helper 192.168.5.1    #可帮该地址转发广播包
    ip dhcp excluded - address 10.1.1.1 10.1.1.99    #地址池不给分配的IP地址
    ip dhcp pool v10    #对VLAN10端口配置地址池
    network 10.1.1.0 255.255.255.0    #分配的IP地址
    default-router 10.1.1.254    #默认网关
    dns-server 40.1.1.1    #设定dns服务器
    lease 1 0 0    #租约
    vtp domain 域名    #使其他设备可以学习到vlan
    vtp domain xiao
39、HRSP
    interface f0/0
    standby 1 ip 192.168.1.252    #设置热备份组的虚拟路由器IP
    standby 1 priority 200    #设置该端口网关的优先级
    standby 1 preempt     #设置拥有占先权
    standby 1 track f0/1    #开启追踪

    show standby br    #查看hsrp表
    show standby

40、ACL
show ip access-list [表ID]    #查看ACL表
no access-list 表号    #删除整张ACL表

int f0/x
ip access-group 表号 in/out    #将ACL应用到接口

标准ACL
access-list 表号 permit/deny 源IP或源网段 反子网掩码
access-list 1 deny 10.0.0.0 0.255.255.255    #拒绝所有源IP为10开头的标准ACL表
access-list 1 deny 10.1.1.1 0.0.0.0/access-list 1 deny host 10.1.1.1    #拒绝所有源IP为10.1.1.1的主机
access-list 1 deny 0.0.0.0 255.255.255.255/access-list 1 deny any    #拒绝所有人

扩展ACL
acc 表号 permint/deny 协议 源IP或源网段 反子网掩码 目标IP 或源网段 反子网掩码 [eq端口号]
acc 100 permit tcp host 10.1.1.1 host 20.1.1.3 eq 80    #允许10.1.1.1主机访问20.1.1.3的80端口的扩展ACL表

命名ACL
ip access-list standard/extended 自定义表名    #创建/进入某一ACL表
no 条目ID    #删除该ACL表中的一条记录
条目ID 动作 条件    #插入一条记录


41、动态路由配置
router rip    #使用RIP路由协议
version 1/2    #版本(用2好)
network 10.0.0.0    #激活端口
network 20.0.0.0
no auto-summary    #不自动更改(更新)学习到的子网掩码,保留对方的


42、NAT
int f0/0 
ip nat inside    #定义内网端口
int f0/1
ip nat outside    #定义外网端口

acc 1 permit 192.168.0.0 0.0.255.255    #定义内部地址池 
ip nat inside source list 1 int f0/1 overload    #PAT动态映射

ip nat inside source static tcp 192.168.1.3 80 100.1.1.2 80    #配置静态端口转换


43、VPN
第一阶段:管理连接
conf t
crypto isakmp policy 1       (传输集/策略集)配置模式,1为该策略集表号(ID),可配多个策略集
encryption des/3des/aes    设置对称加密算法
hash md5/sha    设置哈希算法
group 1/2/5     IPsecVPN默认DH非对称加密算法,选择DH的1/2/5
authentication pre-share    预共享秘钥(验证是否为对方,类似数字签名)
lifetime 秒    (默认86400秒)对称秘钥失效时间,失效后重新协商
exit
crypto isakmp key (预共享密钥) address (对方的公网IP地址)

第二阶段:数据连接
conf t
access-list 100 permit ip 192.168.0.0 0.0.255.255 172.16.0.0 0.0.255.255    #定义VPN允许访问的条件
crypto ipsec transform-set 传输模式 esp/sh-des/3des/ase esp/ah-md5/sha-hmac    #定义加密及认证方式
例如:
crypto ipsec transform-set chenchuying esp-aes esp-sha-hmac

创建MAP映射表(map映射表相当于把前面配置的东西都集中在这张表上,最后应用在外网端口,一个端口只能应用一张表):
conf t
crypto map map名 1 ipsec-isakmp    #
match address acl表名    #
set tansform-set 传输模式名
set peer 对方的公网IP
exit
如:
crypto map xiaomap 1 ipsec-isakmp 
match address 100    #第二阶段的ACL匹配表(类似ACL)
set tansform-set wentran    #第二阶段的加密及认证方式的传输模式名
set peer 200.1.1.2
exit

int f0/1(外网端口)
crypto map xiaomap    #将map表应用到外网端口
exit

show crypto isakmp sa    #查看第一阶段状态
show crypto ipsec sa     #查看第二阶段状态
show crypto isakmp policy    #查看第一阶段的策略配置集
show crypto ipsec transform-set    #查看第二阶段的传输模式



posted @ 2023-08-07 13:49  ^cyi^  阅读(129)  评论(0编辑  收藏  举报