Skip to main content

1.常用命令汇总

系统配置

配置主机名

sysname <hostname>			#设置设备的主机名

为管理接口(通常是VLAN接口)设置IP地址和子网掩码。

interface vlanif <vlan-id>
ip address <ip-address> <subnet-mask>

配置Telnet和SSH远程访问方式,并指定认证模式为AAA(通常指定为本地或外部认证)

line vty 0 4
authentication-mode aaa
protocol inbound ssh
protocol inbound telnet
user privilege level 3

undo telnet server enable #禁用Telnet服务
undo ftp server enable #禁用FTP服务

创建本地用户,指定用户密码以及授权级别,并指定允许的服务类型。

配置设备的SSH客户端和用户的远程管理方式。

local-user <username>
password cipher <password>
authorization-attribute level <privilege-level>
service-type telnet ssh

#或
local-user <username> password irreversible-cipher <password>
local-user <username> service-type ssh telnet

系统时间配置

clock datetime <year> <month> <day> <hour> <minute> <second>	#配置设备的系统时间
clock timezone GMT+X #设置设备的时区,X为与GMT的时差。
ntp-service unicast-server <IP_address> #配置设备与指定的NTP服务器进行时钟同步

SSH配置

配置SSH密钥对。生成本地SSH密钥对,用于设备与其他设备之间的安全通信。

rsa local-key-pair create

系统备份和恢复

系统备份

backup configuration <file-name>		#备份当前设备配置到指定文件中
save [force] #保存当前配置

auto-save interval <minutes> #配置设备的自动备份功能,指定备份的时间间隔。

系统恢复。

restore configuration <file-name>		#指定的配置文件中恢复设备配置
reset save-configuration #清空交换机配置

系统升级

使用BootLoader进行设备软件的升级。

system-view
bootloader update file <file-name>

接口配置

创建VLAN并为管理接口(通常是VLAN接口)设置IP地址和子网掩码

vlan batch <vlan-id1> <vlan-id2> ...
interface vlanif <vlan-id>
ip address <ip-address> <subnet-mask>

配置端口

interface <interface-type> <interface-number>
port link-type <access/trunk/hybrid>
port default vlan <vlan-id>

设置接口连接模式(接入、中继、混合)和链路类型(接入、中继)。

端口安全

启用端口安全功能,并指定安全模式和最大允许的MAC地址数量。

port-security enable
port-security port-mode <secure-mode>
port-security max-mac-num <max-mac-num>

子接口配置

interface GigabitEthernet0/0/0.<subinterface-number>
encapsulation dot1q <vlan-id>
ip address <ip-address> <subnet-mask>

配置子接口,实现在单个物理接口上支持多个逻辑接口,每个逻辑接口对应一个VLAN。

端口状态检测

启用端口隔离功能,可以防止不同端口之间的通信。

port-isolate enable

路由配置

配置IP路由

配置静态IP路由,指定目标网络、子网掩码和下一跳IP地址。

ip route-static <destination> <mask> <next-hop-ip-address>

路由策略

配置静态路由,可选地指定VPN实例名称。

ip route-static <destination> <mask> <next-hop-ip-address> [vpn-instance <vpn-instance-name>]

配置设备的IP前缀列表,用于路由策略。

ip ip-prefix <prefix-name> index <index_number> permit <ip-address> <mask>

VLAN间路由(SVI)

为VLAN接口配置IP地址,实现不同VLAN之间的路由。

interface Vlanif <vlan-id>
ip address <ip-address> <subnet-mask>

ACL配置

创建和配置ACL,定义允许或拒绝的流量。

acl number <acl-number>
rule <rule-id> permit/deny ip source <source-address> <source-mask> destination <destination-address> <destination-mask>

链路聚合(LACP)配置

配置端口的链路聚合组(Trunk),用于增加带宽和提高冗余。

interface Eth-Trunk <trunk-number>
trunkport <interface-type> <interface-number>

冗余接口组(Eth-Trunk)

配置冗余接口组并指定LACP协议模式和优先级。

interface Eth-Trunk <trunk-number>
mode lacp
lacp priority <priority>

动态路由协议(例如OSPF、BGP)配置

配置OSPF路由协议,指定路由器ID、区域ID和接口网络。

ospf <process-id>
router-id <router-id>
area <area-id>
network <network-address> <mask> [type <type>]

交换机堆叠配置

配置交换机堆叠,将多个交换机组成一个逻辑堆叠单元。

stack
stack slot <slot-number> renumber <new-slot-number>

QoS策略配置

配置流量控制策略,限制接口上的流量速率。

qos car <car-name> cir <cir> cbs <cbs>
interface <interface-type> <interface-number>
qos car <car-name> inbound

安全策略配置

配置防火墙安全区域和信任接口,用于实施安全策略。

firewall zone trust
add interface <interface-type> <interface-number>

VPN隧道配置

配置IPSec VPN隧道的加密和认证算法。

ipsec proposal <proposal-name>
authentication-algorithm <algorithm>
encryption-algorithm <algorithm>

SNMP配置

snmp-agent
snmp-agent community <community-string> [read-only | read-write] [acl <acl-number>]

DHCP配置

启用DHCP服务,并在指定接口上启用DHCP服务器功能。

dhcp enable
interface <interface-type> <interface-number>
dhcp server enable

DHCP Relay配置

interface Vlanif <vlan-id>
dhcp select relay
dhcp relay server-ip <dhcp-server-ip-address>

在VLAN接口上配置DHCP中继功能,并指定DHCP服务器的IP地址。

DHCP Snooping

启用DHCP Snooping功能,并在指定接口上信任DHCP服务器发送的DHCP报文。

dhcp snooping enable
interface <interface-type> <interface-number>
dhcp snooping trust

DNS配置

配置设备的DNS服务器

dns resolve
dns server <IP_address>

NAT(网络地址转换)配置

配置NAT实例,定义ACL和转换规则,以实现私有IP地址到公共IP地址的转换。

nat instance <instance-id>
acl <acl-number> [match-order {auto | config}]
rule <rule-id> [name <rule-name>] source <source-address> <source-wildcard> [destination <destination-address> <destination-wildcard>] [translation {source | static | pool <pool-name>}]

VRRP(虚拟路由冗余协议)配置

配置VRRP实例,定义虚拟路由器ID和虚拟IP地址,可选地跟踪接口状态。

interface <interface-type> <interface-number>
vrrp vrid <vrid> virtual-ip <virtual-ip-address> [track interface <interface-type> <interface-number>]

日志记录配置

配置日志记录,指定日志来源和日志主机,可选地指定通道和加密方式。

info-center source <source>
info-center loghost <ip-address>
info-center loghost <ip-address> channel <channel-id> [syncid <sync-id>] [encrypt <cipher-suite>]

示例:

info-center source default channel 2 log state on		#配置系统日志记录
info-center loghost <IP_address> channel 2 #将日志发送到指定的日志主机

配置系统日志缓冲区大小和日志级别。

info-center logbuffer <buffer-size>
info-center logbuffer size <buffer-size>
info-center logbuffer severity <severity-level>

ACL日志记录

配置ACL规则时添加log参数,使匹配到该规则的流量被记录到系统日志中。

acl number <acl-number>
rule <rule-id> permit/deny icmp source <source-address> <source-mask> destination <destination-address> <destination-mask> log

链路监测

启用链路层OAM(Operations, Administration, and Maintenance)功能,用于监测链路状态和故障检测。

interface <interface-type> <interface-number>
oam enable

多播配置

启用多播路由和IGMP,配置PIM-SM(Protocol Independent Multicast - Sparse Mode)。

multicast routing-enable
igmp enable
pim sm

跨域安全配置

在设备上创建一个域,并为域中的用户配置SSH登录权限。

domain <domain-name>
quit
ssh user <username> service-type stelnet <user-password>

端口镜像配置

配置端口镜像,将指定接口的流量镜像到指定的监视端口,可以选择镜像方向。

interface <interface-type> <interface-number>
port-mirroring to <monitor-port> [both | inbound | outbound]

SPF(Shortest Path First)算法配置

在OSPF进程中配置SPF算法的计算计划,指定起始时间和计算间隔。

ospf <process-id>
spf-schedule start-time <hh:mm:ss> interval <seconds>

ARP防护配置

启用ARP防护功能,检查用户绑定和源MAC地址。

arp anti-attack check user-bind enable
arp anti-attack check source-mac enable

端口速率限制

为指定接口配置流量策略,可以限制接口的入流量。

interface <interface-type> <interface-number>
traffic-policy <policy-name> inbound

邮件通知(SMTP)

配置设备的SMTP服务器,用于发送邮件通知。

smtp server <IP_address> port <port_number>
smtp server <IP_address> port <port_number> timeout <timeout_value>

网络测量配置

nqa test-instance <test-name>
test-type icmp
destination-address ipv4 <destination-ip>
source-interface <interface-type> <interface-number>
frequency <interval>

配置网络测量(Network Quality Analyzer),用于周期性地测试指定目标的连通性。