网工小白,这些命令一定要焊死在自己脑子里!
以下是思科 CCNA 入门常用的核心命令总结,按功能分类整理:
一、基本设备管理
- 主机名与标语
Router> enable # 进入特权模式
Router# configure terminal # 进入全局配置模式
Router(config)# hostname R1 # 设置设备名称(如 R1)
R1(config)# banner motd #文本# # 设置登录标语(#为分隔符)
- 密码与远程访问
R1(config)# enable secret 密码 # 设置特权加密密码
R1(config)# line console 0 # 配置控制台端口
R1(config-line)# password 密码
R1(config-line)# login
R1(config-line)# line vty 0 4 # 配置 Telnet/SSH 访问
R1(config-line)# password 密码
R1(config-line)# login
R1(config-line)# transport input ssh # 仅允许 SSH
R1(config)# username admin secret 密码 # 创建本地用户
R1(config)# ip domain-name example
R1(config)# crypto key generate rsa # 生成 RSA 密钥(SSH 必需)
二、接口与 IP 配置
- 接口 IP 地址
R1(config)# interface gigabitethernet0/0
R1(config-if)# ip address 192.168.1.1 255.255.255.0
R1(config-if)# no shutdown # 启用接口
- 查看接口状态
R1# show ip interface brief # 查看接口 IP 和状态
R1# show interfaces # 查看详细接口信息
三、路由配置
- 静态路由
R1(config)# ip route 目标网络 子网掩码 下一跳IP/出接口
R1(config)# ip route 0.0.0.0 0.0.0.0 10.0.0.1 # 默认路由
- 动态路由协议
- OSPF
R1(config)# router ospf 1 # 启用 OSPF 进程 ID 1
R1(config-router)# network 192.168.1.0 0.0.0.255 area 0
R1(config-router)# passive-interface gig0/0 # 指定被动接口
- EIGRP
R1(config)# router eigrp 100 # 启用 EIGRP AS 100
R1(config-router)# network 192.168.1.0
四、交换与 VLAN
- VLAN 配置
Switch(config)# vlan 10 # 创建 VLAN 10
Switch(config-vlan)# name Sales # 命名 VLAN
Switch(config)# interface gig0/1
Switch(config-if)# switchport mode access # 设置为接入端口
Switch(config-if)# switchport access vlan 10 # 分配 VLAN
- Trunk 端口
Switch(config-if)# switchport mode trunk # 配置 Trunk
Switch(config-if)# switchport trunk allowed vlan 10,20 # 允许的 VLAN
- 生成树协议(STP)
Switch(config)# spanning-tree vlan 1 root primary # 设置根桥
五、安全配置
- 访问控制列表(ACL)
- 标准 ACL
R1(config)# access-list 1 permit 192.168.1.0 0.0.0.255
R1(config)# interface gig0/0
R1(config-if)# ip access-group 1 in # 应用 ACL
- 扩展 ACL
R1(config)# access-list 100 permit tcp 192.168.1.0 0.0.0.255 any eq 80
- 端口安全
Switch(config-if)# switchport port-security # 启用端口安全
Switch(config-if)# switchport port-security maximum 1 # 限制 MAC 数量
Switch(config-if)# switchport port-security violation shutdown # 违规关闭端口
六、IP 服务
- NAT 配置
R1(config)# ip nat inside source static 192.168.1.10 200.1.1.1 # 静态 NAT
R1(config)# ip nat inside source list 1 interface gig0/0 overload # PAT
R1(config)# access-list 1 permit 192.168.1.0 0.0.0.255
- DHCP 服务
R1(config)# ip dhcp pool LAN-POOL # 创建地址池
R1(dhcp-config)# network 192.168.1.0 255.255.255.0
R1(dhcp-config)# default-router 192.168.1.1
R1(config)# ip dhcp excluded-address 192.168.1.1 # 排除地址
七、排错命令
代码语言:javascript代码运行次数:0运行复制R1# ping 192.168.1.1 # 测试连通性
R1# traceroute 8.8.8.8 # 追踪路径
R1# show running-config # 查看当前配置
R1# show ip route # 查看路由表
R1# show arp # 查看 ARP 表
R1# show cdp neighbors # 查看 CDP 邻居
八、无线网络(基础)
代码语言:javascript代码运行次数:0运行复制AP(config)# dot11 ssid WLAN-NAME # 创建 WLAN
AP(config-ssid)# guest-mode # 启用广播 SSID
AP(config)# interface dot11Radio0
AP(config-if)# ssid WLAN-NAME # 将 SSID 绑定到接口
提示:
- 所有配置后使用
copy running-config startup-config
保存配置。 - 命令模式需注意(如
config
模式与interface
模式)。 - 实验环境中务必通过模拟器(如 Packet Tracer、GNS3)练习验证。