Sổ tay kỹ thuật

Linux network – lệnh iproute2, ss, nmcli, resolvectl

cheatsheet#linux#iproute2#networking· cập nhật 2026-11-06

Tra nhanh lệnh xem và sửa tạm IP, route, link, ARP/NDP, socket và DNS trên Linux hiện đại.

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

Dùng iproute2 (ip, ss) thay cho ifconfig/netstat/route (gói net-tools đã cũ). Thay đổi bằng ip mất sau reboot; muốn bền thì cấu hình qua netplan hoặc NetworkManager.

Mục đích Lệnh
Xem IP gọn, có màu ip -br -c addr
Trạng thái link gọn (UP/DOWN, MAC) ip -br link
Chi tiết một interface (MTU, state, qdisc) ip addr show dev eth0
Thêm / xoá IP (tạm thời) ip addr add 198.51.100.10/24 dev eth0 / ip addr del 198.51.100.10/24 dev eth0
Bật / tắt interface ip link set eth0 up / ip link set eth0 down
Đổi MTU ip link set eth0 mtu 9000
Bộ đếm packet, error, drop ip -s link show eth0
Tạo VLAN subinterface ip link add link eth0 name eth0.100 type vlan id 100
Output JSON để script ip -j addr | jq '.[] | {ifname, addr_info}'
Theo dõi thay đổi link/addr/route realtime ip monitor all

Route và policy routing

Mục đích Lệnh
Bảng route chính (IPv4 / IPv6) ip route / ip -6 route
Kernel sẽ đi đường nào tới đích ip route get 203.0.113.5
Thêm default / static route ip route add default via 198.51.100.1 / ip route add 203.0.113.0/24 via 198.51.100.1 dev eth0
Đổi route đang có ip route replace 203.0.113.0/24 via 198.51.100.254
Mọi bảng route ip route show table all
Policy rule (from/fwmark → table) ip rule show
VRF: liệt kê / route trong VRF ip vrf show / ip route show vrf mgmt

ARP / NDP

Mục đích Lệnh
Bảng neighbor (ARP + NDP) ip neigh show
Chỉ entry lỗi ip neigh show nud failed
Xoá cache neighbor của interface ip neigh flush dev eth0
Gửi ARP kiểm tra trùng IP arping -D -I eth0 198.51.100.10 (gói iputils-arping)

Socket với ss

Mục đích Lệnh
Port đang listen + process ss -tulpn
Tổng quan số socket theo trạng thái ss -s
Session BGP (port 179) ss -tn state established '( sport = :179 or dport = :179 )'
Kết nối tới một host ss -tn dst 203.0.113.5
Thông tin TCP: RTT, cwnd, retrans ss -ti dst 203.0.113.5
Kèm timer (keepalive, retrans) ss -tno
Socket trong network namespace ss -N <netns> -tulpn

NetworkManager (nmcli)

Mục đích Lệnh
Trạng thái thiết bị / connection nmcli device status / nmcli connection show
Đặt IP tĩnh nmcli con mod eth0 ipv4.method manual ipv4.addresses 198.51.100.10/24 ipv4.gateway 198.51.100.1 ipv4.dns 198.51.100.53
Áp dụng nmcli con up eth0
Xem chi tiết connection nmcli -f ipv4 con show eth0

DNS với systemd-resolved

Mục đích Lệnh
DNS server theo từng link resolvectl status
Phân giải thử qua resolved resolvectl query example.com
Xoá cache resolvectl flush-caches
Thống kê cache hit/miss resolvectl statistics
Đặt DNS tạm cho link resolvectl dns eth0 198.51.100.53
Hỏi thẳng server, bỏ qua resolved dig @198.51.100.53 example.com +short

NIC

Mục đích Lệnh
Tốc độ, duplex, link detected ethtool eth0
Counter phần cứng (crc, drop) ethtool -S eth0 | grep -Ei 'err|drop|crc'
Driver, firmware ethtool -i eth0

/etc/resolv.conf trỏ tới 127.0.0.53 là bình thường trên Ubuntu: đó là stub của systemd-resolved, DNS thật xem bằng resolvectl status.

Xem thêm: tcpdump cheatsheet khi cần nhìn packet thật.