TDNamvnCommunity
Home/Công cụ/Sổ Tay Lệnh Cisco

Sổ Tay Tra Cứu Lệnh Cấu Hình Cisco Toàn Diện

Tổng hợp bộ lệnh cấu hình thực tế cho Switch & Router Cisco: VLAN, Trunking, LACP, OSPF, NAT/PAT, Port-Security, HSRP kèm nút sao chép 1-click.

100% Client-Side

Khởi tạo Cơ bản & Cấu hình Bảo mật SSH v2

Đặt tên thiết bị, mã hóa mật khẩu enable, tạo RSA key và kích hoạt truy cập SSH v2 an toàn.

enable
configure terminal
hostname SW-CORE-01
ip domain-name tdnam.corp
crypto key generate rsa modulus 2048
ip ssh version 2
username admin privilege 15 secret SuperSecretP@ss123
line vty 0 4
 transport input ssh
 login local
 exec-timeout 5 0
exit
service password-encryption
#Basic#SSH#Crypto#Hardening

Tạo VLAN & Cấu hình Cổng 802.1Q Trunking

Tạo các VLAN dữ liệu, giọng nói và cấu hình đường truyền Trunk nối giữa 2 Switch.

configure terminal
vlan 10
 name DATA_DEPT
vlan 20
 name VOICE_VOIP
vlan 99
 name MANAGEMENT
exit

interface GigabitEthernet0/1
 description UPLINK-TO-DISTRIBUTION
 switchport mode trunk
 switchport trunk encapsulation dot1q
 switchport trunk allowed vlan 10,20,99
 switchport trunk native vlan 99
 no shutdown
exit
#VLAN#Trunk#802.1Q#Switching

Cấu hình Cổng Access kèm Voice VLAN cho IP Phone

Cổng cắm PC qua điện thoại bàn IP Phone (phân tách gói tin thoại và dữ liệu máy tính).

interface GigabitEthernet0/2
 description PC-USER-DESK
 switchport mode access
 switchport access vlan 10
 switchport voice vlan 20
 spanning-tree portfast
 spanning-tree bpduguard enable
 no shutdown
exit
#Access#Voice VLAN#PortFast#QoS

Gộp Băng Thông Port-Channel (LACP IEEE 802.3ad)

Gộp 2 đường cáp vật lý 1Gbps thành 1 kênh logic 2Gbps chống nghẽn và dự phòng.

interface range GigabitEthernet0/23 - 24
 description BUNDLED-TO-CORE
 channel-group 1 mode active
 no shutdown
exit

interface Port-channel 1
 switchport mode trunk
 switchport trunk allowed vlan all
exit
#EtherChannel#LACP#Port-Channel#LAG

Định tuyến Động OSPFv2 (Single & Multi-Area)

Quảng bá các dải mạng nội bộ vào Area 0, đặt router-id và cấu hình cổng passive.

router ospf 1
 router-id 1.1.1.1
 network 192.168.10.0 0.0.0.255 area 0
 network 192.168.20.0 0.0.0.255 area 0
 network 10.0.0.0 0.0.0.3 area 0
 passive-interface GigabitEthernet0/1
 auto-cost reference-bandwidth 1000
exit
#OSPF#Routing#Area 0#Cisco

Cấu hình NAT / PAT (Overload) Ra Mạng Internet

Chuyển dịch địa chỉ IP mạng nội bộ (Private IP) ra 1 IP Public trên cổng WAN.

access-list 1 permit 192.168.0.0 0.0.255.255

interface GigabitEthernet0/0
 description LAN-INSIDE
 ip nat inside
exit

interface GigabitEthernet0/1
 description WAN-INTERNET
 ip nat outside
exit

ip nat inside source list 1 interface GigabitEthernet0/1 overload
ip route 0.0.0.0 0.0.0.0 GigabitEthernet0/1 203.0.113.1
#NAT#PAT#Overload#Internet

DHCP Server Nội Bộ & DHCP Relay Agent

Cấp phát IP động cho máy trạm và chuyển tiếp gói tin DHCP qua router tới máy chủ Windows Server.

ip dhcp excluded-address 192.168.10.1 192.168.10.20
ip dhcp pool POOL_LAN_DEPT
 network 192.168.10.0 255.255.255.0
 default-router 192.168.10.1
 dns-server 1.1.1.1 8.8.8.8
 lease 7
exit

interface Vlan 10
 description GATEWAY-VLAN-10
 ip address 192.168.10.1 255.255.255.0
 ip helper-address 192.168.1.100
exit
#DHCP#Helper-Address#Relay#LAN

Khóa Cổng Switch theo Địa chỉ MAC (Port Security)

Chặn thiết bị lạ cắm vào mạng LAN, tự động shutdown cổng nếu phát hiện cắm switch phụ hoặc đổi MAC.

interface GigabitEthernet0/5
 switchport mode access
 switchport access vlan 10
 switchport port-security
 switchport port-security maximum 1
 switchport port-security mac-address sticky
 switchport port-security violation shutdown
 no shutdown
exit

# Khôi phục cổng bị err-disabled do vi phạm:
# errdisable recovery cause psecure-violation
# errdisable recovery interval 30
#Port Security#Sticky MAC#SecOps#Switching

Dự phòng Cổng Gateway HSRP (Cisco First Hop)

Tạo địa chỉ Virtual IP Gateway dự phòng nóng giữa 2 Router/Switch L3.

interface Vlan 10
 ip address 192.168.10.2 255.255.255.0
 standby 10 ip 192.168.10.1
 standby 10 priority 110
 standby 10 preempt
 standby 10 track GigabitEthernet0/1 20
exit
#HSRP#Redundancy#High Availability#Gateway
TDNamvn — Cộng đồng Kỹ sư CNTT, Mạng & An toàn Thông tin