Tổng hợp lệnh Cisco IOS cơ bản: Switch, Router, Debug & Copy | Cheat Sheet đầy đủ
Network

Tổng hợp lệnh Cisco IOS cơ bản: Switch, Router, Debug & Copy | Cheat Sheet đầy đủ

⏱ 13 phút đọc 👁 51 lượt xem

Tìm hiểu cấu hình Cisco IOS cơ bản

Việc nắm được những lệnh cơ bản trong CCNA là nền tảng vừng chắc để đi xa trên con đường Networking.

Lệnh Cisco truy cập vào các chế độ

Mô tả Lệnh
User mode (chế độ user) Switch>
Enter Privilege mode (vào chế độ đặc quyền) Switch>enable
Privileged mode (chế độ đặc quyền) Switch#
Enter configuration mode (vào chế độ cấu hình) Switch#configure terminal
Global Config mode Switch(config)#
Vào Interface mode Switch(config)#interface fa0/1
Interface mode Switch(config-if)
Return to global configuration Switch(config-if)exit
Exit Global Config mode Switch(config)#exit
Return to user mode Switch#disable
Logout (Đăng xuất) Switch>exit

Các phím tắt thông dụng

Mô tả Phím tắt
Recall Previous command Mũi tên lên hoặc <Ctrl> p
Recall Next command Mũi tên xuống hoặc <Ctrl> n
Bắt đầu lệnh <Ctrl> a
Kết thúc lệnh <Ctrl> e
Xóa input <Ctrl> d
Thoát Configuration Mode <Ctrl> z
Làm mới output trên màn hình <Ctrl> R
Hoàn thành lệnh TAB

Lệnh cấu hình Switch Cisco

Mô tả Lệnh
Configure device system name (Cấu hình tên thiết bị) Switch(config)#hostname sw1
Sets the encrypted enable password (Thiết lập mật khẩu mã hóa) Switch(config)#enable secret cisco
Sets the unencrypted enable password (Đặt mật khẩu không mã hóa) Switch(config)#enable password cisco
Enable password encryption on all clear text password (Mã hóa tất cả mật khẩu trong file cấu hình) Switch(config)#service password-encryption
Configure a Message Of The Day Banner (Cài thông báo banner, kết thúc bằng $) Switch(config)#banner motd $
Assign IP address to vlan (Gán IP cho vlan) Switch(config)#int vlan 1 Switch(config-if)#ip addr 172.22.1.11 255.255.255.0
Assign Default gateway (Gán default gateway) Switch(config)#ip default-gateway 10.1.1.1
Select one interface (Chọn 1 interface) Switch(config)#int fa0/1
Select a range of interfaces (Chọn 1 dải interface) Switch(config)#int range fa0/1 – 12
Set the interface description (Viết mô tả cho interface) Switch(config-if)#description
Add vlan using config mode (Thêm vlan sử dụng config mode) switch(config)#vlan 11 switch(config-vlan)#name test
Configure Interface fa0/1 @ speed 100 Mbps and full duplex Switch(config-if)#speed 100 Switch(config-if)#duplex full
Assign interface to vlan (Gán int cho vlan) switch(config-if)#switchport access vlan 11
Enable Port Security (Bật bảo mật port) Switch(config-if)#switchport mode access Switch(config-if)#switchport port-security Switch(config-if)#switchport port-security mac-address sticky
Disable Interface (Tắt interface) Switch(config-if)shutdown
Enable Interface (Cho phép interface hoạt động) Switch(config-if)no shutdown
Configures 5 Telnet sessions each with a password of 'cisco' Switch(config)#line vty 0 4 Switch(config-line)#login Switch(config-line)#password cisco
Enable and define console password of 'cisco' Switch(config)#line con 0 Switch(config-line)#login Switch(config-line)#password cisco
Synchronise console messages (Đồng bộ thông báo console) Switch(config-line)#logging synchronous
Set the timezone and automatically adjust (Thiết lập timezone và tự động thay đổi) Switch(config)#clock timezone gmt 0 Switch(config)#clock summer-time gmt recurring
Sets the switch priority for the vlan (Thiết lập priority cho vlan) Switch(config)#spanning-tree vlan 1 priority 4096
Enables portfast (Kích hoạt portfast) Switch(config)#int fa0/1 Switch(config-if)#spanning-tree portfast
Enables RSTP (Bật RSTP, tùy chọn khác là PVST và MST) Switch(config)#spanning-tree mode rapid-pvst
Creates a vlan (Tạo vlan trong config mode) Switch(config)#vlan 2 Switch(config-vlan)#name sales
Assign an interface to vlan 2 (Gán int cho vlan 2) Switch(config-if)#switchport access vlan 2
Buộc int là trunk vô điều kiện (Có thể chọn access hoặc dynamic) Switch(config-if)#switchport mode trunk
Gán thủ công switch vào miền VTP Switch(config)#vtp domain lab
Thay đổi VTP mode từ server sang client Switch(config)#vtp mode client

Lệnh cấu hình Router Cisco

Mô tả Lệnh
Set a console password to cisco (Đặt mật khẩu console là cisco) Router(config)#line con 0 Router(config-line)#login Router(config-line)#password cisco
Set a telnet password (Đặt mật khẩu telnet) Router(config)#line vty 0 4 Router(config-line)#login Router(config-line)#password cisco
Stop console timing out (Console không bị log off) Router(config)#line con 0 Router(config-line)#exec-timeout 0 0
Set the enable password to cisco Router(config)#enable password cisco
Set the enable secret password to peter (Ghi đè enable password, được mã hóa) Router(config)#enable secret peter
Enable an interface (Bật interface) Router(config-if)#no shutdown
To disable an interface (Tắt interface) Router(config-if)#shutdown
Set the clock rate for a router with a DCE cable to 64K Router(config-if)clock rate 64000
Set a logical bandwidth assignment of 64K to the serial interface Router(config-if)bandwidth 64
To add an IP address to an interface (Thêm IP cho interface) Router(config-if)#ip addr 10.1.1.1 255.255.255.0
To enable RIP on all 172.16.x.y interfaces Router(config)#router rip Router(config-router)#network 172.16.0.0
Disable RIP (Tắt RIP) Router(config)#no router rip
To enable IGRP with AS of 200 Router(config)#router igrp 200 Router(config-router)#network 172.16.0.0
Disable IGRP (Tắt IGRP) Router(config)#no router igrp 200
Định tuyến tĩnh remote network 172.16.1.0, next hop 172.16.2.1, cost 5 hop Router(config)#ip route 172.16.1.0 255.255.255.0 172.16.2.1 5
Disable CDP for the whole router (Tắt CDP cho cả router) Router(config)#no cdp run
Enable CDP for the whole router (Bật CDP cho cả router) Router(config)#cdp run
Disable CDP on an interface (Tắt CDP trên interface) Router(config-if)#no cdp enable
Enable the http server to SDM (Bật http server để dùng SDM) Router(config)#ip http server
Defines a username and password (Đặt username sue, mật khẩu cisco) Router(config)#username sue password cisco
Xác định file local host (tương tự /etc/hosts trong unix) Router(config)#ip host mypc 10.1.1.3
Vô hiệu hóa DNS lookup (Hữu ích khi lệnh bị gõ lỗi) Router(config)#no ip domain-lookup
Thiết lập băng thông logic cho interface Router(config)#int s0 Router(config-if)#bandwidth
Thiết lập physical clock Router(config-if)#clock rate 64000
Set the serial interface WAN encapsulation (Tùy chọn: PPP, frame-relay) Router(config-if)#encapsulation hdlc
Authentication on PPP (Bật chap trên interface, tùy chọn khác là PAP) Router(config-if)#ppp authentication chap
Chọn kiểu LMI (Tự động phát hiện nếu không cấu hình đúng) Router(config-if)#frame-relay lmi-type cisco
Định tuyến tĩnh (AD = 1, ghi đè định tuyến động) Router(config)#ip route 50.0.0.0 255.0.0.0 10.1.2.1
Enables RIP version 2 trên tất cả LOCAL interfaces có địa chỉ 10.x.x.x Router(config)#router rip Router(config-router)#network 10.0.0.0 Router(config-router)#version 2
Enable the router to provide a DHCP service (Thiết lập DHCP trên router) Router(config)#ip dhcp pool MYPOOL Router(dhcp-config)#network 10.1.1.0 255.255.255.0 Router(dhcp-config)#default-router 10.1.1.1 Router(dhcp-config)#exit Router(config)#ip dhcp excluded-address 10.1.1.1 10.1.1.99
Thiết lập config register (Chỉ định việc router làm khi khởi động) Router(config)#config-register 0x2102
Tạo sub interface, kích hoạt 802.1q trunking, đặt địa chỉ IP Router(config)#int fa0/0.1 Router(config-subif)#encapsulation dot1Q 1 Router(config-subif)#ip address 10.1.1.1 255.255.255.0
Bật OSPF trên bất kỳ local interface nào bắt đầu bằng 10.1.x.x Router(config-)#router ospf 1 Router(config-router)#network 10.1.0.0 0.0.255.255 area 0
EIGRP có thể cấu hình giống RIP hoặc dùng tùy chọn mask Router(config)#router eigrp 1 Router(config-router)#network 172.16.0.0 Router(config-router)#network 172.16.2.0 0.0.0.255
Thiết lập chuẩn ACL (số từ 1 đến 99) Router(config)#access-list 1 permit 172.16.1.1
Thiết lập Extended ACL (địa chỉ đầu tiên là IP nguồn) Router(config)#access-list 101 deny tcp host 172.16.1.1 host 172.16.2.1 eq telnet Router(config)#access-list 101 permit ip any any
Sử dụng lệnh group để gắn ACL vào interface Router(config)#interface fa0/0 Router(config-if)#ip access-group 1 out
Ví dụ sử dụng tên ACL thay vì số Router(config)#ip access-list extended my_list Router(config-ext-nacl)#deny tcp host 172.16.1.1 host 172.16.2.1 eq ftp Router(config-ext-nacl)#permit ip any any
Gán ACL cho interface bằng tên Router(config)#int fa0/0 Router(config-if)#ip access-group my_list in
Cấu hình NAT tĩnh để cho phép truy cập server qua Internet Router(config)#ip nat inside source static 10.1.1.2 interface s0/0/1
Xác định interface mà NAT xảy ra Router(config)#int fa0/0.1 Router(config-if)#ip nat inside
Enables RIPng (Bật RIPng) Router(config)#ipv6 unicast-routing Router(config)#ipv6 router rip ccna Router(config)#int s0/0/0 Router(config-if)#ipv6 rip ccna enable

Các lệnh đặc quyền (Privilege Commands) trên Switch

Mô tả Lệnh
Bật hộp thoại setup tự động khi thiết bị khởi động không có cấu hình Switch#setup
Displays the config held in DRAM (bị mất nếu không dùng copy run start) Switch#show running-config
Displays the NVRAM config (Hiển thị cấu hình NVRAM) Switch#show startup-config
Saves the config (Lưu cấu hình, nếu không mọi thay đổi sẽ bị mất) Switch#copy running-config startup-config
Saves the running config to a TFTP server Switch#copy running-config tftp
Copies IOS files to a TFTP server Switch#copy flash tftp
Copies files from a TFTP server to device flash Switch#copy tftp flash
Erase the config held in NVRAM (Kết hợp reload sẽ mất toàn bộ cấu hình) Switch#erase startup-config
Reboots the device (Khởi động lại switch) Switch#reload
Abort sequence (Hủy một lệnh, thủ tục) <Shift> <Ctrl> 6
Suspend Telnet Session (Tạm dừng phiên telnet) <Shift> <Ctrl> 6, thả hết và nhấn x
Show the current sessions (Phiên có * là phiên hiện hoạt) Switch#show sessions
Forcible closes a telnet session (Buộc đóng một phiên telnet) Switch#disconnect
Set the device local clock (Không thực hiện trong chế độ cấu hình) Switch#clock set 10:00:00 april 2 2008
Display the IOS version (Xem uptime, cấu hình register, v.v.) Switch#show version
Xem nội dung file của flash Switch#show flash
Xem giờ Switch#show clock
Xem user hiện đang đăng nhập Switch#show users
By default displays the last 10 commands Switch#show history
Displays the ARP cache (Xem cache ARP) Switch#show arp
Displays the spanning tree status on vlan 1 Switch#show spanning-tree vlan 1
Lists all the configured vlans (Liệt kê tất cả vlan đã cấu hình) Switch#show vlan
Displays VTP info (chế độ, miền, bộ đếm) Switch#sh vtp status
Ping selected address Switch#ping 10.1.1.1
Extended ping (Phải thực hiện trong chế độ privilege) Switch#ping
Display the interface status (Hiển thị trạng thái interface) Switch#show int fa0/1
Displays the vlan status and IP address VLAN 1 (management vlan) Switch#show interfaces vlan 1
Displays a list of CDP neighbours (Xem danh sách CDP) Switch#show cdp neighbors
Extended information on CDP (Xem nhiều thông tin hơn lệnh trên) Switch#show cdp neighbors details
Display CDP packets as they arrive Switch#debug cdp packets
Display ping packets as they arrive Switch#debug icmp packets
Display switch MAC Addresses table (Lấy từ địa chỉ MAC nguồn trong Ethernet frame) Switch#show mac address-table

Các lệnh đặc quyền (Privilege Commands) trên Router

Mô tả Lệnh
Vào chế độ đặc quyền enable
Trở về user mode từ privileged disable
Thoát router logout / exit / quit
Xem phiên bản router Router#show version
Xem cấu hình hiện tại (DRAM) Router#show running-config
Xem cấu hình startup (NVRAM) Router#show startup-config
Xem dung lượng file IOS, flash Router#show flash
Xem tất cả log router ghi lại Router#show log
Xem trạng thái interface e0 Router#show interface e0
Displays the interface operational status and IP addresses for all router interfaces Router#show ip interface brief
Xem kiểu cáp trên s0 Router#show controllers 0
Xem các thiết bị cdp đã kết nối Router#show cdp neighbor
Xem thông tin chi tiết trên tất cả các thiết bị Router#show cdp entry *
Displays all the configured routing protocols Router#show ip protocols
Displays the IP routing table (Hiển thị bảng định tuyến IP) Router#show ip route
Hiển thị access list Router#show access-lists
Xem router nào thấy được switch ISDN Router#show isdn status
Displays the NAT translations (Xem các NAT translation) Router#show ip nat translations
Xem cấu hình cáp vật lý: DTE/DCE, x.21, V.35, RS232 Router#show controllers s 0
Displays the end-to-end status Router#show frame-relay pvc
Displays the type of LMI and the number LMI frames Router#show frame-relay lmi
Displays the frame relay inverse ARP table Router#show frame-relay map
Xem danh sách ospf neighbor và trạng thái Router#show ip ospf neighbor
Xem trạng thái interface ospf Router#show ip ospf interface
Xem danh sách eigrp neighbor và trạng thái Router#show ip eigrp neighbor
Xem trạng thái interface EIGRP Router#show ip eigrp interface
Xem tất cả trunk port trên thiết bị Router#show interface trunk
ping IPv6 Router#ping 2000:1000:500:3::1

Lệnh copy trên Router Cisco

copy running-config startup-config   → Lưu cấu hình hiện tại từ DRAM vào NVRAM
copy startup-config running-config   → Hợp nhất cấu hình NVRAM vào DRAM
copy running-config tftp             → Sao chép cấu hình DRAM vào TFTP server
copy tftp running-config             → Hợp nhất cấu hình TFTP với DRAM
copy flash tftp                      → Sao lưu IOS lên TFTP server
copy tftp flash                      → Nâng cấp router IOS từ TFTP server

Lệnh debug trên Router Cisco

debug ip rip                   → Bật debug cho RIP
debug ip igrp events           → Xem thông tin debug IGRP tóm tắt
debug ip igrp transactions     → Xem thông tin debug IGRP chi tiết
debug ipx routing activity     → Debug IPX RIP
debug IPX SAP                  → Debug IPX SAP
debug ppp authentication       → Bật debug cho CHAP hoặc PAP
no debug all / undebug all     → Tắt tất cả debug

Kết luận

Nắm vững các lệnh Cisco IOS cơ bản giúp bạn tự tin hơn trong việc cấu hình, giám sát và xử lý sự cố trên các thiết bị mạng Cisco.


Yêu thích bài viết này

Bài viết liên quan

Configuring Routing (Cấu hình Định tuyến trên Cisco Packet Tracer)
Network 4 phút đọc

Configuring Routing (Cấu hình Định tuyến trên Cisco Packet Tracer)

Hướng dẫn thực hành Lab 10.6 — Cấu hình Static Routing trên Cisco Packet Tracer: thêm route bằng lệnh ip route, xác minh bảng định tuyến, kiểm tra kết nối bằng ping và xóa route. Bài lab thực hành thiết yếu cho kỳ thi CCNA/CCENT. Hiển thị ở trang chủ và làm meta description mặc định.

LAN Switching
Network 7 phút đọc

LAN Switching

Giới thiệu LAN Switching và mô hình thiết kế mạng LAN phân cấp theo Cisco — bao gồm ba lớp Access, Distribution và Core, lợi ích của mô hình phân cấp, tiêu chí lựa chọn switch và tính năng đặc trưng tại từng lớp. Hiển thị ở trang chủ và làm meta description mặc định.

2
Static Routing
Network 8 phút đọc

Static Routing

Tìm hiểu Static Routing trên Cisco IOS — hướng dẫn cấu hình định tuyến tĩnh, ba nguyên tắc bảng định tuyến, recursive lookup, summary route và default route dành cho học viên CCNA/CCENT. Hiển thị ở trang chủ và làm meta description mặc định.