Sổ tay kỹ thuật

SNMPv3 authPriv trên IOS XR và Junos

how-to#snmp#iosxr#junos#security· cập nhật 2026-11-06

Dùng khi thay community SNMPv2c bằng SNMPv3 có xác thực và mã hoá (authPriv) cho collector giám sát, và kiểm tra bằng snmpwalk.

Sửa trang này
Mục lục

Tóm tắt: Tạo view (OID được đọc), group ở mức priv gắn view, rồi user với auth SHA + priv AES thuộc group đó. Giới hạn nguồn bằng ACL (IOS XR) hoặc filter lo0 (Junos, xem Hardening thiết bị mạng). Kiểm tra từ collector bằng snmpwalk -v3 -l authPriv. Gỡ community v2c sau khi collector đã chạy ổn với v3. Phía Prometheus xem snmp_exporter.

Luồng hoạt động

flowchart LR A["Collector 198.51.100.20"] -->|"GET, user nms01, SHA + AES"| B{"ACL / filter lo0"} B -->|"không thuộc dải quản trị"| X[Drop] B --> C{"User tồn tại, key đúng?"} C -->|sai| Y["Report: authFailure / unknownUser"] C --> D["Group NMS-RO (priv)"] D --> E["View: OID được phép"] E --> F[Response mã hoá]

Mức bảo mật SNMPv3:

Mức Xác thực Mã hoá Dùng khi
noAuthNoPriv Không Không Không dùng
authNoPriv Có Không Tránh: nội dung vẫn đọc được trên đường truyền
authPriv Có Có Mặc định nên dùng

Cấu hình

Ví dụ: collector 198.51.100.20, user nms01, chỉ đọc. Thay <auth-pass> / <priv-pass> bằng mật khẩu lấy từ secret store (tối thiểu 8 ký tự).

IOS XR

ipv4 access-list SNMP-NMS
 10 permit ipv4 host 198.51.100.20 any
!
snmp-server view NMS-VIEW 1.3.6.1.2.1 included
snmp-server view NMS-VIEW 1.3.6.1.4.1 included
snmp-server group NMS-RO v3 priv read NMS-VIEW IPv4 SNMP-NMS
snmp-server user nms01 NMS-RO v3 auth sha clear <auth-pass> priv aes 128 clear <priv-pass>
!
commit confirmed 300
show snmp group
show snmp user
show snmp engineid

Junos

set snmp view NMS-VIEW oid 1.3.6.1.2.1 include
set snmp view NMS-VIEW oid 1.3.6.1.4.1 include
set snmp v3 usm local-engine user nms01 authentication-sha authentication-password "<auth-pass>"
set snmp v3 usm local-engine user nms01 privacy-aes128 privacy-password "<priv-pass>"
set snmp v3 vacm security-to-group security-model usm security-name nms01 group NMS-RO
set snmp v3 vacm access group NMS-RO default-context-prefix security-model usm security-level privacy read-view NMS-VIEW
commit confirmed 5
show snmp v3
show snmp statistics
show configuration snmp | display set

Junos lưu password dưới dạng key đã băm (authentication-key), không đọc lại được bản gốc. Để chặn theo nguồn, dùng term SNMP trong filter lo0 với source-prefix-list dải quản trị.

Nhiều bản phần mềm mới hỗ trợ SHA-2 (vd auth sha256 / authentication-sha256) và AES-256. Chỉ dùng khi cả thiết bị lẫn collector cùng hỗ trợ; dò bằng ? trên CLI thiết bị.

Engine ID

Key SNMPv3 được "localize" theo engine ID của thiết bị. Đổi engine ID (đổi cấu hình engine-id, đôi khi sau RMA/thay RE) làm user cũ không xác thực được nữa: phải tạo lại user. Ghi lại engine ID bằng show snmp engineid (XR) / show snmp v3 (Junos).

Lệnh

# Từ collector. Đặt password trong biến môi trường, không gõ thẳng trên dòng lệnh dùng chung
export SNMP_AUTH='***' SNMP_PRIV='***'
 
snmpget  -v3 -l authPriv -u nms01 -a SHA -A "$SNMP_AUTH" -x AES -X "$SNMP_PRIV" 192.0.2.1 1.3.6.1.2.1.1.5.0
snmpwalk -v3 -l authPriv -u nms01 -a SHA -A "$SNMP_AUTH" -x AES -X "$SNMP_PRIV" 192.0.2.1 1.3.6.1.2.1.2.2.1.2
snmpbulkwalk -v3 -l authPriv -u nms01 -a SHA -A "$SNMP_AUTH" -x AES -X "$SNMP_PRIV" -Cr25 192.0.2.1 IF-MIB::ifHCInOctets
 
# Kiểm tra v2c đã bị gỡ (phải timeout)
snmpget -v2c -c public -t 2 -r 0 192.0.2.1 1.3.6.1.2.1.1.5.0

-x AES trong Net-SNMP là AES-128, tương ứng priv aes 128 / privacy-aes128. Có thể lưu tham số vào ~/.snmp/snmp.conf (defSecurityName, defAuthType, defPrivType...) với quyền 0600.

Lỗi thường gặp

Triệu chứng Nguyên nhân Cách xử lý
Timeout: No Response ACL/filter lo0 chặn, sai IP nguồn (collector đi qua NAT), SNMP chưa bật trên VRF quản trị Kiểm tra ACL, show snmp statistics; cấu hình SNMP cho VRF mgmt nếu cần
Unknown user name Sai tên user hoặc user chưa commit show snmp user / show snmp v3
Authentication failure (incorrect password, community or key) Sai auth password hoặc sai thuật toán (SHA vs SHA-256) So -a với cấu hình thiết bị
Decryption error hoặc walk trả về rỗng/lỗi giải mã Sai priv password hoặc -x AES vs AES-256 Đặt lại priv password, khớp thuật toán
User đúng nhưng No Such Object OID nằm ngoài view Thêm OID vào view
Mọi thứ đúng nhưng auth fail sau khi thay phần cứng Engine ID đổi Tạo lại user v3
authNoPriv vẫn đọc được Group đặt mức auth thay vì priv Group phải là v3 priv / security-level privacy

Tham khảo