Công cụ & Xử lý sự cốTools & Troubleshooting
Thuộc bộ kiến thức Network Engineer Roadmap.
Tổng quan
Troubleshooting (xử lý sự cố) là kỹ năng giá trị nhất của một network engineer. Mạng thường hỏng theo những cách mơ hồ và khó chịu — người dùng nói “internet chậm” hoặc “tôi không vào được app,” và việc của bạn là biến một triệu chứng mơ hồ thành một root cause chính xác. Khác biệt giữa engineer junior và senior hiếm khi nằm ở việc biết thêm một câu lệnh; nó nằm ở phương pháp. Một engineer senior đặt ra một hypothesis (giả thuyết), test nó với chi phí rẻ nhất, và loại bỏ cả một nhóm nguyên nhân sau mỗi bước. Một engineer junior chạy ping mười lần rồi cầu may.
Note này cố tình hands-on. Nó ghép một phương pháp có cấu trúc (cách tư duy) với bộ công cụ chuẩn (cái để chạy) và một loạt bảng triệu chứng → nguyên nhân → công cụ (khi nào dùng gì). Các công cụ chia thành vài nhóm:
| Nhóm | Công cụ | Trả lời câu hỏi |
|---|---|---|
| Connectivity | ping, traceroute/tracert, mtr | Packet có tới đích không, và chết ở đâu? |
| Name resolution | dig, nslookup, host | DNS có trả về đúng kết quả không? |
| Trạng thái local | ip, ifconfig, ipconfig, ss, netstat, arp | Host này nghĩ mạng của nó trông như thế nào? |
| Discovery & scan | nmap, arp-scan | Có những host và service nào trên segment này? |
| Throughput | iperf3, speedtest | Thực tế ta có bao nhiêu bandwidth? |
| Packet analysis | tcpdump, Wireshark | Thực sự có gì trên dây, từng byte một? |
| Lab & mô phỏng | Packet Tracer, GNS3, EVE-NG | Tái hiện và luyện tập mà không đụng vào production. |
Mọi thứ ở đây dựa trên mô hình phân lớp trong ./03-network-models-and-layers.md và các protocol trong ./06-core-protocols.md. Troubleshooting và monitoring là hai mặt của một đồng xu — monitoring (./14-monitoring-and-observability.md) cho bạn biết có thứ gì đó sai; troubleshooting cho bạn biết tại sao.
Kiến thức nền tảng
Một phương pháp có cấu trúc
Mục tiêu của phương pháp là làm cho tiến độ được đảm bảo thay vì may rủi. Mọi cách tiếp cận tốt đều đi qua stack OSI/TCP-IP theo một thứ tự nào đó, bởi vì lỗi ở lớp thấp làm mọi lớp phía trên nó cũng hỏng theo. Không có ích gì khi debug HTTP nếu dây mạng bị rút.
Vòng lặp phổ quát là: isolate → hypothesize → test → fix → verify (cô lập → giả thuyết → kiểm chứng → sửa → xác minh).
- Isolate. Thu hẹp phạm vi. Một host hay tất cả host? Một site hay cả LAN? Một application hay toàn bộ traffic? Một chiều hay cả hai chiều? Tái hiện được thì càng tốt. “Từ laptop của tôi thì được nhưng từ server thì không” hữu ích gấp trăm lần “nó hỏng.”
- Hypothesize. Nêu một phỏng đoán có thể bác bỏ được: “DNS đang resolve ra IP cũ,” “default gateway không reachable,” “có MTU mismatch trên tunnel.” Một hypothesis mà bạn không test được bằng một câu lệnh thì quá mơ hồ.
- Test. Chạy câu lệnh rẻ nhất để xác nhận hoặc bác bỏ hypothesis. Một lệnh
ping 8.8.8.8phân biệt ngay lập tức giữa “mất connectivity” và “DNS hỏng.” - Fix. Thay đổi mỗi lần một thứ. Đổi ba thứ rồi thấy nó chạy thì chẳng học được gì và có thể đã che mất lỗi thật.
- Verify. Xác nhận từ góc nhìn của người dùng, không chỉ của bạn. Rồi kiểm tra bạn không làm hỏng thứ khác. Ghi lại root cause.
Ba cách đi qua các lớp
| Cách tiếp cận | Cách làm | Tốt nhất khi |
|---|---|---|
| Bottom-up | Bắt đầu ở Layer 1 (dây, link) rồi đi lên: link → IP → transport → application. | Bạn nghi lỗi vật lý/hạ tầng, hoặc không biết lỗi ở đâu. Kỹ nhưng chậm. |
| Top-down | Bắt đầu ở application rồi đi xuống: app chạy không? HTTP? TLS? TCP? IP? | Người dùng báo lỗi application và các lớp thấp có lẽ ổn (ví dụ chỉ một website chết). |
| Divide-and-conquer | Bắt đầu ở giữa (thường là Layer 3 — ping được đích không?) rồi nhảy lên hoặc xuống tùy kết quả. | Bạn có kinh nghiệm và một linh cảm. Cách nhanh nhất trong tay người thạo. |
Một lượt đi bottom-up cụ thể:
# L1/L2 — link có UP không và có địa chỉ chưa?
ip link show # state UP? Có carrier không?
ip addr show # có địa chỉ IPv4/IPv6 chưa?
# L3 — tới được gateway chưa, rồi internet theo IP?
ip route show # có default route không?
ping -c 3 192.168.1.1 # default gateway (reachability trong LAN)
ping -c 3 8.8.8.8 # một IP public (routing + internet, không DNS)
# Cỡ L7 — name resolution có chạy không?
dig +short example.com # DNS có trả về kết quả không?
ping -c 3 example.com # end-to-end theo tên
# L7 — service thực sự có phản hồi không?
curl -I https://example.com # dòng status HTTP và headers
Nếu mọi bước đều pass cho đến dig, bạn đã chứng minh Layer 1–3 khỏe mạnh và lỗi là ở DNS. Đó là sức mạnh của việc đi qua stack: mỗi test pass loại bỏ vĩnh viễn một lớp.
”Is it DNS? It’s always DNS.”
Câu đùa này tồn tại vì DNS nằm giữa một mạng đang chạy và một application đang chạy, nên lỗi DNS đội lốt thành đủ thứ lỗi khác. Test tức thì để tách DNS khỏi connectivity:
ping -c 3 8.8.8.8 # được? -> IP connectivity ỔN
ping -c 3 google.com # thất bại? -> vấn đề là name resolution (DNS)
Nếu ping IP được nhưng ping tên thất bại, đừng nhìn routing với dây nữa — nhảy thẳng sang dig.
Đọc exit code và làm việc có hệ thống
Phần lớn công cụ trả về 0 khi thành công và khác 0 khi thất bại, nên bạn có thể script các bước kiểm tra. Nhưng quan trọng hơn: mỗi lần thay đổi một biến, ghi chép lại những gì đã thử và đã thấy, và luôn test cả hai chiều của một kết nối — asymmetric routing và firewall rule một chiều là những cái bẫy kinh điển.
Khái niệm chính
Công cụ connectivity
ping — host có reachable không (ICMP)?
ping gửi các gói ICMP Echo Request và đo thời gian các Echo Reply. Nó trả lời hai câu hỏi cùng lúc: reachability (reply có về không?) và latency (mất bao lâu?).
ping -c 4 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=12.3 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=118 time=11.9 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=118 time=12.1 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=118 time=12.0 ms
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 11.9/12.0/12.3/0.15 ms
Cách đọc:
time=là round-trip time (RTT). Số nhỏ và ổn định = khỏe. Số dao động lung tung = jitter, thường do link nghẽn hoặc wireless.packet lossnên là 0% trên LAN có dây. Vượt quá 1–2% end-to-end là đáng điều tra.ttl=gợi ý host cách bao nhiêu hop (giá trị khởi đầu trừ số hop). Host Linux khởi đầu ở 64, Windows ở 128; replyttl=118gợi ý cách ~10 hop từ một stack kiểu Windows.Request timeout/Destination Host Unreachable— không có reply nghĩa là host down, firewall chặn ICMP, hoặc không có route. ICMP bị chặn là chuyện thường, nên một lần ping thất bại không chứng minh host đã down.
Các flag hữu ích:
ping -c 4 -i 0.2 8.8.8.8 # gửi mỗi 0.2s (lấy mẫu nhanh hơn)
ping -c 4 -s 1472 -M do 8.8.8.8 # payload 1472 byte, don't fragment (test MTU, xem bên dưới)
ping -c 4 -I eth0 8.8.8.8 # ép source interface
ping6 -c 4 2001:4860:4860::8888 # ICMPv6 tới địa chỉ v6
Trên Windows: ping -n 4 8.8.8.8 (-n = số lần, -t = ping đến khi Ctrl-C, -l = kích thước, -f = don’t fragment).
traceroute / tracert — packet đi đâu và chết ở đâu?
traceroute phơi bày đường đi từng hop bằng cách gửi packet với giá trị TTL tăng dần; mỗi router giảm TTL về 0 sẽ gửi lại thông báo “Time Exceeded,” tự lộ diện.
traceroute -n google.com
traceroute to google.com (142.250.x.x), 30 hops max, 60 byte packets
1 192.168.1.1 0.5 ms 0.4 ms 0.4 ms
2 10.20.0.1 8.1 ms 8.0 ms 8.2 ms
3 100.64.0.1 11.0 ms 10.9 ms 11.1 ms
4 * * *
5 142.250.x.x 12.4 ms 12.3 ms 12.5 ms
Cách đọc:
- Mỗi dòng là một hop (router) với ba probe RTT.
* * *nghĩa là không có reply ở hop đó. Thường vô hại — nhiều router rate-limit hoặc không reply probe nhưng vẫn forward traffic. Chỉ lo khi* * *kéo dài đến tận đích.- Một cú nhảy latency đột ngột, kéo dài ở một hop và mọi hop sau đó chỉ ra nghẽn ở link đó. Nhảy chỉ ở một hop (rồi hồi lại) thường chỉ là router đó ưu tiên thấp cho ICMP — không phải lỗi thật.
-nbỏ reverse-DNS nên chạy nhanh hơn và hiện IP thô.
Linux mặc định dùng probe UDP; thêm -I cho ICMP hoặc -T cho TCP (traceroute -T -p 443 example.com), rất giá trị khi firewall chặn UDP/ICMP nhưng cho phép TCP port của app. tracert của Windows mặc định dùng ICMP.
mtr — traceroute + ping, liên tục
mtr kết hợp traceroute và ping: nó probe lặp lại mọi hop và hiển thị bảng loss/latency từng hop cập nhật liên tục. Đây là công cụ tốt nhất để chẩn đoán loss không liên tục (intermittent) và hop nào gây latency.
mtr -rwzbc 100 google.com # chế độ report: 100 chu kỳ, wide, hiện ASN
HOST: myhost Loss% Snt Last Avg Best Wrst StDev
1. AS??? 192.168.1.1 0.0% 100 0.4 0.5 0.3 1.2 0.1
2. AS1234 10.20.0.1 0.0% 100 8.1 8.3 7.9 10.2 0.4
3. AS5678 100.64.0.1 2.0% 100 11.0 11.4 10.8 25.1 1.9
4. AS15169 142.250.x.x 0.0% 100 12.4 12.6 12.1 14.0 0.3
Điểm mấu chốt: loss xuất hiện ở một hop và tiếp tục đến hop cuối là loss thật; loss xuất hiện ở một hop giữa nhưng 0% ở đích chỉ là router đó ưu tiên thấp cho ICMP và có thể bỏ qua. Trong ví dụ trên, hop 3 hiện 2% nhưng hop 4 hiện 0% — vậy “loss” chỉ mang tính hình thức, đường đi thực ra sạch.
Công cụ DNS
Xem ./06-core-protocols.md để hiểu DNS hoạt động ra sao; ở đây ta tập trung vào các lệnh chẩn đoán.
dig — công cụ DNS của dân chuyên
dig example.com A
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 3600 IN A 93.184.216.34
;; Query time: 14 msec
;; SERVER: 1.1.1.1#53(1.1.1.1)
Đọc ANSWER SECTION để lấy record và TTL của nó (ở đây 3600s). SERVER cho biết resolver nào đã trả lời — cực kỳ quan trọng khi bạn nghi đang dùng sai resolver.
dig +short example.com # chỉ kết quả, thân thiện với script
dig +trace example.com # đi từ root -> TLD -> authoritative (tìm nơi resolution gãy)
dig @1.1.1.1 example.com # query một resolver CỤ THỂ (bỏ qua resolver local)
dig @8.8.8.8 example.com +short # đối chiếu: resolver khác có đồng ý không?
dig example.com MX # bản ghi mail
dig example.com NS # nameserver
dig example.com TXT # bản ghi SPF/DKIM/xác minh
dig -x 8.8.8.8 # reverse lookup (PTR)
dig example.com +norecurse # hỏi xem server có cache sẵn không (kiểm tra authoritative)
Chẩn đoán DNS hữu ích nhất: query hai resolver và so sánh. Nếu dig @1.1.1.1 và dig @8.8.8.8 khác nhau, bạn có cache cũ hoặc vấn đề propagation. dig +trace sau đó chỉ ra chính xác nameserver nào trong chuỗi delegation trả về sai.
nslookup — có ở mọi nơi, kể cả Windows
nslookup example.com # lookup A cơ bản
nslookup example.com 8.8.8.8 # dùng server cụ thể
nslookup -type=MX example.com # chỉ định loại record
nslookup có sẵn trên Windows và macOS/Linux. Nó ít script-friendly hơn dig và định dạng output vụng hơn, nhưng luôn có mặt.
host — nhanh và gọn
host example.com # A, AAAA, và MX mỗi loại một dòng
host -t NS example.com # nameserver
host 93.184.216.34 # reverse lookup
Công cụ interface & socket — host này nghĩ gì?
ip (Linux, hiện đại) / ifconfig (cũ) / ipconfig (Windows)
ip addr show # tất cả interface, địa chỉ, trạng thái (thay cho ifconfig -a)
ip -br addr # tóm tắt gọn mỗi interface một dòng
ip link show # trạng thái L2, MAC, MTU, UP/DOWN
ip route show # bảng routing; tìm dòng 'default via'
ip neigh show # bảng ARP/neighbor (thay cho arp -a)
ip -s link show eth0 # thống kê interface: RX/TX errors, drops
Output gọn của ip -br addr lý tưởng để liếc nhanh:
lo UNKNOWN 127.0.0.1/8 ::1/128
eth0 UP 192.168.1.42/24 fe80::.../64
Kiểm tra: interface kẹt DOWN, thiếu IP (DHCP thất bại), địa chỉ 169.254.x.x (APIPA — DHCP thất bại, không server nào trả lời), hoặc thiếu route default.
Trên Windows:
ipconfig /all # cấu hình đầy đủ: IP, mask, gateway, DNS, MAC, DHCP lease
ipconfig /release # bỏ DHCP lease
ipconfig /renew # xin lease mới
ipconfig /flushdns # xóa cache resolver (sửa DNS cũ trên client)
ipconfig /displaydns # hiện các entry DNS đã cache
ipconfig /flushdns là cách sửa tương đương trên Windows khi client cứ resolve một tên ra IP cũ.
ss / netstat — socket và port đang lắng nghe
ss là bản thay thế hiện đại, nhanh hơn cho netstat.
ss -tulpn # socket TCP+UDP đang LISTEN kèm process sở hữu và port
ss -tan # tất cả socket TCP kèm state (không resolve tên)
ss -tn state established # chỉ kết nối established
ss -tn dst 10.0.0.5 # kết nối tới một host cụ thể
ss -s # tóm tắt số lượng theo state
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=812,fd=3))
tcp ESTAB 0 0 192.168.1.42:22 192.168.1.10:53344 users:(("sshd",pid=1099,fd=4))
Dùng nó để trả lời “service của tôi có thực sự đang lắng nghe không?” (tìm LISTEN trên port kỳ vọng) và “ai đang kết nối?” Để ý các TCP state: nhiều socket kẹt ở SYN-SENT nghĩa là đầu xa không trả lời (firewall/down); nhiều TIME-WAIT thường là bình thường; nhiều CLOSE-WAIT nghĩa là app local không đóng socket (lỗi app).
Tương đương Windows: netstat -ano (-o hiện PID; đối chiếu với Task Manager).
arp — ánh xạ MAC ↔ IP trên segment local
ip neigh show # Linux hiện đại
arp -a # truyền thống, cũng có trên Windows/macOS
192.168.1.1 dev eth0 lladdr aa:bb:cc:dd:ee:ff REACHABLE
192.168.1.10 dev eth0 lladdr 11:22:33:44:55:66 STALE
Hai thiết bị hiện cùng một MAC cho các IP khác nhau, hoặc IP gateway mà MAC cứ đổi, chỉ ra IP conflict hoặc ARP spoofing. INCOMPLETE cạnh một neighbor nghĩa là ARP không nhận được reply — host tắt hoặc ở VLAN khác.
Scanning & discovery
Chỉ dùng khi được ủy quyền. Port scan các mạng bạn không sở hữu hoặc không có văn bản cho phép test là bất hợp pháp ở nhiều nơi và vi phạm hầu hết chính sách sử dụng. Chỉ scan lab của bạn hoặc hệ thống bạn được phép đánh giá rõ ràng.
nmap — discovery host và service
# Chỉ discovery host (ping sweep) — ai còn sống trên subnet này?
nmap -sn 192.168.1.0/24
Nmap scan report for 192.168.1.1
Host is up (0.0012s latency).
Nmap scan report for 192.168.1.42
Host is up (0.00030s latency).
Nmap done: 256 IP addresses (2 hosts up) scanned in 2.11 seconds
# Các TCP port phổ biến trên một host
nmap 192.168.1.10
# Phát hiện service + version trên các port cụ thể
nmap -sV -p 22,80,443 192.168.1.10
# Nhanh top-100 port, không DNS, timing aggressive
nmap -F -n -T4 192.168.1.10
# Phát hiện OS (cần root/admin)
sudo nmap -O 192.168.1.10
# Scan UDP (chậm — nhiều service không reply)
sudo nmap -sU -p 53,123,161 192.168.1.10
Cách đọc: mỗi port mở hiện PORT STATE SERVICE VERSION. open = có gì đó đang lắng nghe; filtered = firewall đang drop probe (không trả lời); closed = host sống nhưng không có gì lắng nghe ở đó. -sV lấy banner để xác định phần mềm và version chính xác — vô giá cho câu “cái hộp bí ẩn kia đang chạy gì?”
Throughput: iperf3 và speedtest
speedtest đo download/upload internet của bạn tới một server công cộng:
speedtest # speedtest-cli hoặc client Ookla chính thức
iperf3 đo throughput giữa hai host bạn kiểm soát — công cụ thật để test LAN, link WAN, hoặc VPN tunnel. Chạy server một đầu và client đầu kia:
# Trên server (đích):
iperf3 -s
# Trên client (nguồn):
iperf3 -c 10.0.0.5 # throughput TCP trong 10 giây
iperf3 -c 10.0.0.5 -t 30 -P 4 # 30s, 4 luồng song song (làm bão hòa link)
iperf3 -c 10.0.0.5 -R # đảo chiều: đo download thay vì upload
iperf3 -c 10.0.0.5 -u -b 100M # UDP ở 100 Mbit/s — báo cáo jitter và loss
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-10.00 sec 1.10 GBytes 943 Mbits/sec 0 sender
[ 5] 0.00-10.00 sec 1.09 GBytes 940 Mbits/sec receiver
943 Mbits/sec trên link “gigabit” là khỏe (overhead chiếm phần còn lại). Số Retr (retransmit) cao báo hiệu loss hoặc nghẽn cổ chai. Chế độ UDP là cách đo jitter và packet loss cho việc lập kế hoạch VoIP/video.
Packet analysis
Khi công cụ ở lớp cao mâu thuẫn với thực tế, hãy capture chính các packet. Cả tcpdump và Wireshark đều dùng chung engine libpcap và cùng cú pháp capture filter (BPF); Wireshark thêm ngôn ngữ display filter phong phú hơn nhiều và một GUI.
Capture filter vs display filter
| Capture filter (BPF) | Display filter (Wireshark) | |
|---|---|---|
| Áp dụng khi nào | Trước khi capture — quyết định cái gì được ghi | Sau khi capture — quyết định cái gì được hiện |
| Cú pháp | host 10.0.0.5 and port 443 | ip.addr == 10.0.0.5 && tcp.port == 443 |
| Dùng bởi | tcpdump, ô “Capture” của Wireshark | thanh “Display filter” của Wireshark |
| Mục đích | Giảm khối lượng trên link bận | Đào sâu vào một capture có sẵn |
Nguyên tắc: dùng capture filter để giữ file nhỏ trên interface bận; dùng display filter để khám phá cái đã capture. Đừng lọc quá tay lúc capture — không thể khôi phục cái bạn đã không ghi.
tcpdump — capture từ CLI
sudo tcpdump -i eth0 -n host 8.8.8.8 # traffic tới/từ một host, không DNS
sudo tcpdump -i eth0 -n port 53 # tất cả DNS
sudo tcpdump -i eth0 -n 'tcp port 443 and host 10.0.0.5'
sudo tcpdump -i any -n icmp # ping trên mọi interface
sudo tcpdump -i eth0 -nn -c 100 -w capture.pcap # ghi 100 packet ra file cho Wireshark
sudo tcpdump -i eth0 -A -s0 port 80 # in payload dạng ASCII (HTTP plaintext)
sudo tcpdump -r capture.pcap 'tcp port 443' # đọc và lọc một file có sẵn
Một TCP handshake trong output của tcpdump trông như thế này:
10:00:01.100 IP 10.0.0.10.53344 > 10.0.0.5.443: Flags [S], seq 100, win 64240 # SYN
10:00:01.112 IP 10.0.0.5.443 > 10.0.0.10.53344: Flags [S.], seq 900, ack 101 # SYN-ACK
10:00:01.112 IP 10.0.0.10.53344 > 10.0.0.5.443: Flags [.], ack 901 # ACK
[S] = SYN, [S.] = SYN-ACK, [.] = ACK, [P.] = PSH+ACK (data), [F.] = FIN, [R] = RST. Thấy một SYN mà không có SYN-ACK đáp lại nghĩa là server không trả lời — firewall hoặc service down. Một SYN bị đáp bằng [R] (RST) nghĩa là port đóng / bị từ chối chủ động.
Wireshark — GUI phân tích
Wireshark decode hàng trăm protocol và cho bạn theo dõi một cuộc hội thoại trực quan. Các display filter thiết yếu:
ip.addr == 10.0.0.5 # mọi packet tới/từ IP này
tcp.port == 443 # TCP port này
dns # chỉ DNS
http.request # chỉ HTTP request
tcp.flags.syn == 1 && tcp.flags.ack == 0 # các SYN (nỗ lực kết nối)
tcp.analysis.retransmission # retransmit do Wireshark đánh dấu (loss!)
tcp.analysis.zero_window # bên nhận bảo bên gửi dừng (nghẽn flow-control)
tcp.stream eq 0 # cô lập trọn một cuộc hội thoại TCP
frame contains "password" # tìm một chuỗi byte trong payload
Right-click một packet → Follow → TCP Stream để xem trọn một cuộc hội thoại được ráp lại. Statistics → Conversations xếp hạng ai nói nhiều nhất (tìm kẻ ngốn bandwidth). Statistics → I/O Graph vẽ throughput theo thời gian. Khi thấy tcp.analysis.retransmission chồng chất, bạn có packet loss thật — đối chiếu với hop trong mtr bị loss.
Network simulator & lab
Luyện tập và tái hiện lỗi mà không mạo hiểm production. Mỗi công cụ đánh đổi độ trung thực lấy độ nặng:
| Công cụ | Là gì | Chạy | Tốt nhất cho |
|---|---|---|---|
| Cisco Packet Tracer | Simulator miễn phí của Cisco (xấp xỉ hành vi thiết bị, không phải firmware thật) | Nhẹ, chạy được trên laptop | Học nền tảng, ôn CCNA, phác nhanh topology |
| GNS3 | Emulator chạy image thiết bị thật (IOS, và qua Docker/QEMU: router, firewall, Linux) | Nặng hơn; có thể dùng VM từ xa | Lab đa hãng thực tế, kiểm chứng config trước khi triển khai |
| EVE-NG | Nền tảng emulation đa hãng chạy trên web, image thật, dễ lab đa người dùng | Chạy trên server/VM | Lab nhóm, topology lớn, ôn chứng chỉ (CCNP/CCIE, security) |
Nguyên tắc: Packet Tracer để học khái niệm với chi phí rẻ, GNS3 khi cần hành vi firmware thật trên máy của mình, EVE-NG cho lab dùng chung, quy mô lớn, hoặc đa hãng.
Sự cố thường gặp: triệu chứng → nguyên nhân → công cụ
| Triệu chứng | Nguyên nhân khả dĩ | Công cụ / lệnh để xác nhận |
|---|---|---|
| Mất connectivity hoàn toàn | Link down, không có DHCP lease, không có default route, sai VLAN | ip link, ip addr (169.254 = APIPA/không DHCP), ip route (thiếu default), ping gateway |
| Ping IP được nhưng ping tên không | DNS sai/down, sai resolver, cache cũ | ping 8.8.8.8 (được) vs ping name (thất bại); dig @1.1.1.1 name; ipconfig /flushdns |
| Rớt không liên tục (intermittent) | Dây lỏng, nhiễu Wi-Fi, duplex mismatch, hop quá tải | mtr -rwc 500 dest (tìm hop bị loss), ip -s link (RX/TX errors), kiểm tra error trên port switch |
| Latency cao | Nghẽn, bufferbloat, sai đường/routing, server ở xa | mtr/traceroute (định vị hop chậm), ping khi có tải, iperf3 |
| Throughput thấp | Duplex mismatch, link bão hòa, window nhỏ, vấn đề MTU | iperf3 -c host -P4, ethtool eth0 (speed/duplex), ip -s link (errors) |
| Lỗi DNS | Resolver hỏng, record hết hạn, lệch split-horizon | dig +trace name, so sánh dig @1.1.1.1 vs @8.8.8.8, dig name +norecurse ở authoritative |
| Duplex mismatch | Một bên auto, bên kia bị ép (half vs full) | ethtool eth0 cả hai đầu; triệu chứng là late collision + throughput thấp dù link vẫn up |
| MTU mismatch / phân mảnh | Overhead tunnel/VPN, jumbo frame chỉ bật một bên | ping -M do -s 1472 dest (thất bại nếu MTU < 1500); giảm kích thước đến khi pass để tìm path MTU |
| IP conflict | Hai host trùng static IP, hoặc static đè lên dải DHCP | arp -a (một IP nhảy MAC), event “address conflict” của OS, arping <ip> |
| VLAN / trunk cấu hình sai | Access port sai VLAN, trunk thiếu VLAN được phép, native VLAN lệch | Trên switch show vlan, show interfaces trunk; triệu chứng: host cùng switch không nói chuyện được, hoặc chỉ chạy trên một VLAN |
| Traffic bất đối xứng / một chiều | Firewall rule một chiều, asymmetric routing | tcpdump cả hai đầu (thấy SYN đi ra nhưng không có SYN-ACK về), kiểm tra log firewall |
Chẩn đoán MTU mismatch (ví dụ thực hành)
Vấn đề MTU rất ranh mãnh: packet nhỏ (ping, DNS, phần đầu của một phiên TCP) chạy được, nhưng transfer lớn thì treo. Tìm path MTU bằng ping don’t-fragment và giảm dần đến khi pass:
ping -M do -s 1472 -c 2 example.com # 1472 payload + 28 header = 1500 (Ethernet chuẩn)
# Nếu nhận: "Frag needed and DF set (mtu = 1420)" -> path MTU là 1420, không phải 1500
ping -M do -s 1392 -c 2 example.com # 1392 + 28 = 1420, giờ sẽ thành công
Giá trị -s lớn nhất thành công, cộng 28, là path MTU của bạn. Cách sửa phổ biến trên link VPN/PPPoE là giảm MTU của interface hoặc clamp TCP MSS.
Bảng tra nhanh câu lệnh (Linux ↔ Windows)
| Tác vụ | Linux | Windows |
|---|---|---|
| Reachability | ping -c 4 host | ping -n 4 host |
| Ping liên tục | ping host | ping -t host |
| Trace đường đi | traceroute host / mtr host | tracert host / pathping host |
| Cấu hình interface | ip addr / ifconfig | ipconfig /all |
| Bảng routing | ip route | route print / netstat -r |
| Bảng ARP / neighbor | ip neigh / arp -a | arp -a |
| Port đang lắng nghe | ss -tulpn | netstat -ano |
| Lookup DNS | dig / host / nslookup | nslookup |
| Xóa cache DNS | sudo systemd-resolve --flush-caches | ipconfig /flushdns |
| Renew DHCP lease | sudo dhclient -r && sudo dhclient | ipconfig /release + /renew |
| Packet capture | sudo tcpdump -i eth0 | Wireshark / pktmon |
| Scan port/host | nmap | nmap (hoặc Test-NetConnection) |
| Test một TCP port | nc -zv host 443 | Test-NetConnection host -Port 443 |
| Throughput test | iperf3 | iperf3.exe |
| Thống kê interface | ip -s link / ethtool eth0 | netstat -e / Get-NetAdapterStatistics |
Best Practices
- Có phương pháp, đừng có thói quen. Chọn bottom-up, top-down, hay divide-and-conquer một cách có chủ đích dựa trên triệu chứng — đừng phản xạ ping. Đi qua stack đảm bảo tiến độ; đoán mò thì không.
- Mỗi lần đổi một thứ, và ghi lại. Giữ một note liên tục về mọi câu lệnh, output của nó, và mọi thay đổi. Nếu một fix chạy, bạn biết tại sao; nếu không, bạn revert sạch được.
- Tái hiện và cô lập trước khi đặt giả thuyết. “Một host hay tất cả? Một chiều hay cả hai? Một app hay mọi thứ?” trả lời trước sẽ loại bỏ hầu hết không gian tìm kiếm ngay lập tức.
- Chứng minh connectivity theo IP trước khi đổ lỗi cho thứ khác.
ping 8.8.8.8vsping namelà lát cắt đầu tiên nhanh nhất: nó tách mạng khỏi DNS trong hai giây. - Test cả hai chiều. Firewall và routing thường bất đối xứng. Một capture ở mỗi đầu (SYN ra, SYN-ACK về?) thắng việc đoán mò.
- Ưu tiên
digvà query nhiều resolver. Khi nghi DNS, so sánh hai resolver và dùng+traceđể tìm chính xác chuỗi gãy ở đâu. - Capture bằng filter, phân tích bằng filter. Dùng capture filter BPF hẹp trên link bận để file nhỏ; dùng display filter Wireshark để khám phá — nhưng đừng bao giờ lọc chặt đến mức lúc capture làm mất bằng chứng.
- Phân biệt loss ICMP hình thức với loss thật. Trong
mtr/traceroute,* * *giữa đường hoặc loss tự hết ở hop cuối thường là router ưu tiên thấp ICMP, không phải lỗi. Loss thật kéo dài đến đích. - Chỉ scan cái bạn được phép.
nmapvào mạng bạn không sở hữu hoặc không có văn bản cho phép có thể phạm luật. Giữ trong lab và các mục tiêu đã duyệt. - Lab trước các thay đổi. Tái hiện topology phức tạp trong GNS3/EVE-NG/Packet Tracer trước khi đụng production; kiểm chứng thay đổi config trong lab, rồi mới triển khai.
- Verify từ ghế người dùng, rồi verify bạn không làm hỏng gì. Xác nhận triệu chứng ban đầu đã hết và các service lân cận vẫn chạy trước khi đóng ticket.
- Đưa phát hiện ngược lại vào monitoring. Mỗi sự cố nên để lại một alert hoặc dashboard mới để lần sau bị bắt bởi
./14-monitoring-and-observability.md, không phải bởi người dùng.
Tài liệu tham khảo
Part of the Network Engineer Roadmap knowledge base.
Overview
Troubleshooting is the single most valuable skill a network engineer has. Networks fail in messy, ambiguous ways — a user says “the internet is slow” or “I can’t reach the app,” and it is your job to turn that vague symptom into a precise root cause. The difference between a junior and a senior engineer is rarely knowledge of one more command; it is method. A senior engineer forms a hypothesis, tests it cheaply, and eliminates whole classes of problems with each step. A junior engineer runs ping a dozen times and hopes.
This note is deliberately hands-on. It pairs a structured methodology (how to think) with the standard toolset (what to run) and a set of symptom → cause → tool tables (what to reach for when). The tools split into a few families:
| Family | Tools | Answers the question |
|---|---|---|
| Connectivity | ping, traceroute/tracert, mtr | Can packets reach the destination, and where do they die? |
| Name resolution | dig, nslookup, host | Is DNS returning the right answer? |
| Local state | ip, ifconfig, ipconfig, ss, netstat, arp | What does this host think its network looks like? |
| Discovery & scan | nmap, arp-scan | What hosts and services exist on this segment? |
| Throughput | iperf3, speedtest | How much bandwidth do we actually get? |
| Packet analysis | tcpdump, Wireshark | What is actually on the wire, byte for byte? |
| Labs & simulation | Packet Tracer, GNS3, EVE-NG | Reproduce and practice without touching production. |
Everything here builds on the layering model in ./03-network-models-and-layers.md and the protocols in ./06-core-protocols.md. Troubleshooting and monitoring are two sides of one coin — monitoring (./14-monitoring-and-observability.md) tells you that something is wrong; troubleshooting tells you why.
Fundamentals
A structured methodology
The goal of a method is to make progress guaranteed rather than lucky. Every good approach walks the OSI/TCP-IP stack in some order, because a failure at a lower layer makes everything above it fail too. There is no point debugging HTTP if the cable is unplugged.
The universal loop is: isolate → hypothesize → test → fix → verify.
- Isolate. Narrow the scope. Is it one host or all hosts? One site or the LAN? One application or all traffic? One direction or both? Reproduce it if you can. “Works from my laptop but not the server” is a hundred times more useful than “it’s broken.”
- Hypothesize. State a falsifiable guess: “DNS is resolving to a stale IP,” “the default gateway is unreachable,” “there’s an MTU mismatch on the tunnel.” A hypothesis you can’t test with one command is too vague.
- Test. Run the cheapest command that confirms or kills the hypothesis. A single
ping 8.8.8.8distinguishes “no connectivity” from “DNS broken” instantly. - Fix. Make one change at a time. Changing three things and seeing it work teaches you nothing and may have masked the real fault.
- Verify. Confirm from the user’s perspective, not just yours. Then confirm you didn’t break something else. Document the root cause.
Three ways to walk the layers
| Approach | How it works | Best when |
|---|---|---|
| Bottom-up | Start at Layer 1 (cable, link) and climb: link → IP → transport → application. | You suspect a physical or infrastructure fault, or you have no idea where it is. Thorough but slow. |
| Top-down | Start at the application and descend: does the app work? HTTP? TLS? TCP? IP? | The user reports an application problem and lower layers are probably fine (e.g. one website is down). |
| Divide-and-conquer | Start in the middle (usually Layer 3 — can you ping the destination?) and jump up or down based on the result. | You have experience and a hunch. The fastest method in skilled hands. |
A concrete bottom-up walk:
# L1/L2 — is the link up and do we have an address?
ip link show # state UP? Any carrier?
ip addr show # do we have an IPv4/IPv6 address?
# L3 — can we reach the gateway, then the internet by IP?
ip route show # is there a default route?
ping -c 3 192.168.1.1 # the default gateway (LAN reachability)
ping -c 3 8.8.8.8 # a public IP (routing + internet, no DNS)
# L7-ish — is name resolution working?
dig +short example.com # does DNS return an answer?
ping -c 3 example.com # end-to-end by name
# L7 — does the actual service respond?
curl -I https://example.com # HTTP status line and headers
If every step passes until dig, you have proven Layers 1–3 are healthy and the fault is DNS. That is the power of walking the stack: each passing test permanently rules out a layer.
”Is it DNS? It’s always DNS.”
The running joke exists because DNS sits between a working network and a working application, so DNS faults masquerade as everything else. The instant test that separates DNS from connectivity:
ping -c 3 8.8.8.8 # works? -> IP connectivity is FINE
ping -c 3 google.com # fails? -> the problem is name resolution (DNS)
If pinging an IP works but pinging a name fails, stop looking at routing and cables — go straight to dig.
Reading exit codes and being systematic
Most tools return 0 on success and non-zero on failure, so you can script checks. But more importantly: change one variable at a time, keep a scratch log of what you tried and what you saw, and always test both directions of a connection — asymmetric routing and one-way firewall rules are classic traps.
Key Concepts
Connectivity tools
ping — is the host reachable (ICMP)?
ping sends ICMP Echo Request packets and times the Echo Replies. It answers two questions at once: reachability (do replies come back?) and latency (how long do they take?).
ping -c 4 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=12.3 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=118 time=11.9 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=118 time=12.1 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=118 time=12.0 ms
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 11.9/12.0/12.3/0.15 ms
How to read it:
time=is the round-trip time (RTT). Stable low numbers = healthy. Wildly varying numbers = jitter, often a congested or wireless link.packet lossshould be 0% on a wired LAN. Anything above 1–2% end-to-end is worth investigating.ttl=hints at how many hops away the host is (start value minus hops). A Linux host starts at 64, Windows at 128; a replyttl=118suggests ~10 hops from a Windows-ish stack.Request timeout/Destination Host Unreachable— no reply means either the host is down, a firewall drops ICMP, or there is no route. ICMP being blocked is common, so a failed ping alone does not prove the host is down.
Useful flags:
ping -c 4 -i 0.2 8.8.8.8 # send every 0.2s (faster sampling)
ping -c 4 -s 1472 -M do 8.8.8.8 # 1472-byte payload, don't fragment (MTU test, see below)
ping -c 4 -I eth0 8.8.8.8 # force a source interface
ping6 -c 4 2001:4860:4860::8888 # ICMPv6 to a v6 address
On Windows: ping -n 4 8.8.8.8 (-n = count, -t = ping until Ctrl-C, -l = size, -f = don’t fragment).
traceroute / tracert — where does the packet go, and where does it die?
traceroute reveals the path hop by hop by sending packets with increasing TTL values; each router that decrements TTL to 0 sends back a “Time Exceeded” message, revealing itself.
traceroute -n google.com
traceroute to google.com (142.250.x.x), 30 hops max, 60 byte packets
1 192.168.1.1 0.5 ms 0.4 ms 0.4 ms
2 10.20.0.1 8.1 ms 8.0 ms 8.2 ms
3 100.64.0.1 11.0 ms 10.9 ms 11.1 ms
4 * * *
5 142.250.x.x 12.4 ms 12.3 ms 12.5 ms
How to read it:
- Each line is one hop (router) with three RTT probes.
* * *means no reply at that hop. Often harmless — many routers rate-limit or don’t reply to the probe but still forward traffic. Only worry if* * *continues to the destination.- A sudden, sustained jump in latency at one hop and every hop after it points to congestion at that link. A jump at one hop only (that recovers) is usually just that router deprioritizing ICMP — not a real problem.
-nskips reverse-DNS so it runs faster and shows raw IPs.
Linux uses UDP probes by default; add -I for ICMP or -T for TCP (traceroute -T -p 443 example.com), which is invaluable when firewalls block UDP/ICMP but allow the app’s TCP port. Windows tracert uses ICMP by default.
mtr — traceroute + ping, continuously
mtr combines traceroute and ping: it repeatedly probes every hop and shows a live-updating table of loss and latency per hop. It is the best tool for diagnosing intermittent loss and which hop introduces latency.
mtr -rwzbc 100 google.com # report mode: 100 cycles, wide, show ASN
HOST: myhost Loss% Snt Last Avg Best Wrst StDev
1. AS??? 192.168.1.1 0.0% 100 0.4 0.5 0.3 1.2 0.1
2. AS1234 10.20.0.1 0.0% 100 8.1 8.3 7.9 10.2 0.4
3. AS5678 100.64.0.1 2.0% 100 11.0 11.4 10.8 25.1 1.9
4. AS15169 142.250.x.x 0.0% 100 12.4 12.6 12.1 14.0 0.3
Key insight: loss that appears at one hop and continues to the final hop is real loss; loss that appears at a middle hop but is 0% at the destination is just that router deprioritizing ICMP and can be ignored. In the example above, hop 3 shows 2% but hop 4 shows 0% — so the “loss” is cosmetic, the path is actually clean.
DNS tools
See ./06-core-protocols.md for how DNS works; here we focus on the diagnostic commands.
dig — the professional’s DNS tool
dig example.com A
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 3600 IN A 93.184.216.34
;; Query time: 14 msec
;; SERVER: 1.1.1.1#53(1.1.1.1)
Read the ANSWER SECTION for the record and its TTL (here 3600s). SERVER tells you which resolver answered — critical when you suspect the wrong resolver is in use.
dig +short example.com # just the answer, script-friendly
dig +trace example.com # walk from root -> TLD -> authoritative (find where resolution breaks)
dig @1.1.1.1 example.com # query a SPECIFIC resolver (bypass local one)
dig @8.8.8.8 example.com +short # cross-check: does another resolver agree?
dig example.com MX # mail records
dig example.com NS # nameservers
dig example.com TXT # SPF/DKIM/verification records
dig -x 8.8.8.8 # reverse lookup (PTR)
dig example.com +norecurse # ask if the server has it cached (authoritative check)
The single most useful DNS diagnostic: query two resolvers and compare. If dig @1.1.1.1 and dig @8.8.8.8 disagree, you have a stale cache or a propagation issue. dig +trace then shows exactly which nameserver in the delegation chain returns the wrong answer.
nslookup — everywhere, including Windows
nslookup example.com # basic A lookup
nslookup example.com 8.8.8.8 # use a specific server
nslookup -type=MX example.com # specify record type
nslookup ships on Windows and macOS/Linux by default. It is less scriptable than dig and its output format is clunkier, but it is always available.
host — quick and terse
host example.com # A, AAAA, and MX in one line each
host -t NS example.com # nameservers
host 93.184.216.34 # reverse lookup
Interface & socket tools — what does this host think?
ip (Linux, modern) / ifconfig (legacy) / ipconfig (Windows)
ip addr show # all interfaces, addresses, state (replaces ifconfig -a)
ip -br addr # brief one-line-per-interface summary
ip link show # L2 state, MAC, MTU, UP/DOWN
ip route show # the routing table; look for a 'default via' line
ip neigh show # the ARP/neighbor table (replaces arp -a)
ip -s link show eth0 # interface statistics: RX/TX errors, drops
The ip -br addr brief output is ideal for a quick glance:
lo UNKNOWN 127.0.0.1/8 ::1/128
eth0 UP 192.168.1.42/24 fe80::.../64
Check for: an interface stuck DOWN, a missing IP (DHCP failed), a 169.254.x.x address (APIPA — DHCP failed, no server answered), or the absence of a default route.
On Windows:
ipconfig /all # full config: IP, mask, gateway, DNS, MAC, DHCP lease
ipconfig /release # drop the DHCP lease
ipconfig /renew # request a new lease
ipconfig /flushdns # clear the resolver cache (fixes stale DNS on the client)
ipconfig /displaydns # show cached DNS entries
ipconfig /flushdns is the Windows equivalent fix when a client keeps resolving a name to an old IP.
ss / netstat — sockets and listening ports
ss is the modern, faster replacement for netstat.
ss -tulpn # TCP+UDP listening sockets with the owning process and port
ss -tan # all TCP sockets with state (no name resolution)
ss -tn state established # only established connections
ss -tn dst 10.0.0.5 # connections to a specific host
ss -s # summary counts by state
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=812,fd=3))
tcp ESTAB 0 0 192.168.1.42:22 192.168.1.10:53344 users:(("sshd",pid=1099,fd=4))
Use this to answer “is my service actually listening?” (look for LISTEN on the expected port) and “who is connected?” Watch TCP states: many sockets stuck in SYN-SENT means the far end isn’t answering (firewall/down); many in TIME-WAIT is usually normal churn; many in CLOSE-WAIT means the local app isn’t closing sockets (an app bug).
Windows equivalent: netstat -ano (the -o shows the PID; cross-reference with Task Manager).
arp — MAC ↔ IP mapping on the local segment
ip neigh show # modern Linux
arp -a # traditional, also on Windows/macOS
192.168.1.1 dev eth0 lladdr aa:bb:cc:dd:ee:ff REACHABLE
192.168.1.10 dev eth0 lladdr 11:22:33:44:55:66 STALE
Two devices showing the same MAC for different IPs, or a gateway IP whose MAC keeps changing, points to an IP conflict or ARP spoofing. INCOMPLETE next to a neighbor means ARP got no reply — the host is off or on a different VLAN.
Scanning & discovery
Authorized use only. Port scanning networks you do not own or lack written permission to test is illegal in many jurisdictions and against most acceptable-use policies. Scan only your own lab or systems you are explicitly authorized to assess.
nmap — host and service discovery
# Host discovery only (ping sweep) — who is alive on this subnet?
nmap -sn 192.168.1.0/24
Nmap scan report for 192.168.1.1
Host is up (0.0012s latency).
Nmap scan report for 192.168.1.42
Host is up (0.00030s latency).
Nmap done: 256 IP addresses (2 hosts up) scanned in 2.11 seconds
# Common TCP ports on one host
nmap 192.168.1.10
# Service + version detection on specific ports
nmap -sV -p 22,80,443 192.168.1.10
# Fast top-100 ports, no DNS, aggressive timing
nmap -F -n -T4 192.168.1.10
# OS detection (needs root/admin)
sudo nmap -O 192.168.1.10
# UDP scan (slow — many services don't reply)
sudo nmap -sU -p 53,123,161 192.168.1.10
Reading it: each open port shows PORT STATE SERVICE VERSION. open = something is listening; filtered = a firewall is dropping probes (no answer); closed = host is up but nothing listens there. -sV grabs banners to identify the exact software and version — invaluable for “what is running on that mystery box?”
Throughput: iperf3 and speedtest
speedtest measures your internet download/upload to a public server:
speedtest # speedtest-cli or the official Ookla client
iperf3 measures throughput between two hosts you control — the real tool for testing a LAN, WAN link, or VPN tunnel. Run a server on one end and a client on the other:
# On the server (destination):
iperf3 -s
# On the client (source):
iperf3 -c 10.0.0.5 # TCP throughput for 10 seconds
iperf3 -c 10.0.0.5 -t 30 -P 4 # 30s, 4 parallel streams (saturate the link)
iperf3 -c 10.0.0.5 -R # reverse: measure download instead of upload
iperf3 -c 10.0.0.5 -u -b 100M # UDP at 100 Mbit/s — reports jitter and loss
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-10.00 sec 1.10 GBytes 943 Mbits/sec 0 sender
[ 5] 0.00-10.00 sec 1.09 GBytes 940 Mbits/sec receiver
943 Mbits/sec on a “gigabit” link is healthy (overhead accounts for the rest). A high Retr (retransmit) count signals loss or a bottleneck. UDP mode is the way to measure jitter and packet loss for VoIP/video planning.
Packet analysis
When higher-level tools disagree with reality, capture the actual packets. Both tcpdump and Wireshark use the same libpcap engine and the same capture-filter syntax (BPF); Wireshark adds a far richer display-filter language and a GUI.
Capture filters vs display filters
| Capture filter (BPF) | Display filter (Wireshark) | |
|---|---|---|
| When applied | Before capture — decides what gets written | After capture — decides what is shown |
| Syntax | host 10.0.0.5 and port 443 | ip.addr == 10.0.0.5 && tcp.port == 443 |
| Used by | tcpdump, Wireshark “Capture” box | Wireshark “Display filter” bar |
| Purpose | Reduce volume on busy links | Drill into an existing capture |
Rule of thumb: use a capture filter to keep the file small on a busy interface; use a display filter to explore what you captured. Never over-filter at capture time — you can’t recover what you didn’t record.
tcpdump — capture from the CLI
sudo tcpdump -i eth0 -n host 8.8.8.8 # traffic to/from one host, no DNS
sudo tcpdump -i eth0 -n port 53 # all DNS
sudo tcpdump -i eth0 -n 'tcp port 443 and host 10.0.0.5'
sudo tcpdump -i any -n icmp # pings across all interfaces
sudo tcpdump -i eth0 -nn -c 100 -w capture.pcap # write 100 packets to a file for Wireshark
sudo tcpdump -i eth0 -A -s0 port 80 # print packet payloads as ASCII (plaintext HTTP)
sudo tcpdump -r capture.pcap 'tcp port 443' # read and filter an existing file
A TCP handshake in tcpdump output looks like this:
10:00:01.100 IP 10.0.0.10.53344 > 10.0.0.5.443: Flags [S], seq 100, win 64240 # SYN
10:00:01.112 IP 10.0.0.5.443 > 10.0.0.10.53344: Flags [S.], seq 900, ack 101 # SYN-ACK
10:00:01.112 IP 10.0.0.10.53344 > 10.0.0.5.443: Flags [.], ack 901 # ACK
[S] = SYN, [S.] = SYN-ACK, [.] = ACK, [P.] = PSH+ACK (data), [F.] = FIN, [R] = RST. Seeing a SYN with no SYN-ACK in reply means the server never answered — firewall or the service is down. A SYN answered by an [R] (RST) means the port is closed / actively refused.
Wireshark — the analysis GUI
Wireshark decodes hundreds of protocols and lets you follow a conversation visually. Essential display filters:
ip.addr == 10.0.0.5 # any packet to/from this IP
tcp.port == 443 # this TCP port
dns # only DNS
http.request # HTTP requests only
tcp.flags.syn == 1 && tcp.flags.ack == 0 # SYNs (connection attempts)
tcp.analysis.retransmission # Wireshark-flagged retransmits (loss!)
tcp.analysis.zero_window # receiver told sender to stop (flow-control stall)
tcp.stream eq 0 # isolate one whole TCP conversation
frame contains "password" # find a byte string in payloads
Right-click a packet → Follow → TCP Stream to see an entire conversation reassembled. Statistics → Conversations ranks who is talking the most (find the bandwidth hog). Statistics → I/O Graph plots throughput over time. When you see tcp.analysis.retransmission piling up, you have real packet loss — correlate it with the mtr hop that showed loss.
Network simulators & labs
Practice and reproduce faults without risking production. Each tool trades fidelity for weight:
| Tool | What it is | Runs | Best for |
|---|---|---|---|
| Cisco Packet Tracer | Cisco’s free simulator (approximates device behavior, not real firmware) | Light, laptop-friendly | Learning fundamentals, CCNA study, quick topology sketches |
| GNS3 | Emulator that runs real device images (IOS, and via Docker/QEMU: routers, firewalls, Linux) | Heavier; can use a remote VM | Realistic multi-vendor labs, validating configs before deployment |
| EVE-NG | Web-based multi-vendor emulation platform, real images, easy multi-user labs | Server/VM based | Team labs, large topologies, certification practice (CCNP/CCIE, security) |
Rule of thumb: Packet Tracer to learn concepts cheaply, GNS3 when you need real firmware behavior on your own machine, EVE-NG for shared, large-scale, or multi-vendor labs.
Common issues: symptom → likely cause → tool
| Symptom | Likely causes | Tools / commands to confirm |
|---|---|---|
| No connectivity at all | Link down, no DHCP lease, no default route, wrong VLAN | ip link, ip addr (169.254 = APIPA/no DHCP), ip route (missing default), ping gateway |
| Can ping IP but not names | DNS misconfigured/down, wrong resolver, stale cache | ping 8.8.8.8 (works) vs ping name (fails); dig @1.1.1.1 name; ipconfig /flushdns |
| Intermittent drops | Flaky cable, Wi-Fi interference, duplex mismatch, overloaded hop | mtr -rwc 500 dest (find the lossy hop), ip -s link (RX/TX errors), check switch port errors |
| High latency | Congestion, bufferbloat, wrong path/routing, distant server | mtr/traceroute (locate the slow hop), ping under load, iperf3 |
| Low throughput | Duplex mismatch, saturated link, small window, MTU issue | iperf3 -c host -P4, ethtool eth0 (speed/duplex), ip -s link (errors) |
| DNS failures | Bad resolver, expired records, split-horizon mismatch | dig +trace name, compare dig @1.1.1.1 vs @8.8.8.8, dig name +norecurse at authoritative |
| Duplex mismatch | One side auto, other side forced (half vs full) | ethtool eth0 both ends; symptom is late collisions + low throughput despite link up |
| MTU mismatch / fragmentation | Tunnel/VPN overhead, jumbo frames on one side only | ping -M do -s 1472 dest (fails if MTU < 1500); reduce size until it passes to find the path MTU |
| IP address conflict | Two hosts with the same static IP, or static overlapping DHCP | arp -a (same IP flapping MACs), OS “address conflict” event, arping <ip> |
| VLAN / trunk misconfig | Access port in wrong VLAN, trunk missing an allowed VLAN, native VLAN mismatch | Switch show vlan, show interfaces trunk; symptom: same-switch hosts can’t talk, or work only on one VLAN |
| Asymmetric / one-way traffic | Firewall rule one direction, asymmetric routing | tcpdump on both ends (see SYN leave but no SYN-ACK return), check firewall logs |
Diagnosing an MTU mismatch (worked example)
MTU problems are sneaky: small packets (ping, DNS, the start of a TCP session) work, but large transfers hang. Find the path MTU with a don’t-fragment ping and shrink until it passes:
ping -M do -s 1472 -c 2 example.com # 1472 payload + 28 header = 1500 (standard Ethernet)
# If you get: "Frag needed and DF set (mtu = 1420)" -> the path MTU is 1420, not 1500
ping -M do -s 1392 -c 2 example.com # 1392 + 28 = 1420, should now succeed
The largest -s value that succeeds, plus 28, is your path MTU. A common fix on VPN/PPPoE links is lowering the interface MTU or clamping TCP MSS.
Quick command cheat-sheet (Linux ↔ Windows)
| Task | Linux | Windows |
|---|---|---|
| Reachability | ping -c 4 host | ping -n 4 host |
| Continuous ping | ping host | ping -t host |
| Trace path | traceroute host / mtr host | tracert host / pathping host |
| Interface config | ip addr / ifconfig | ipconfig /all |
| Routing table | ip route | route print / netstat -r |
| ARP / neighbor table | ip neigh / arp -a | arp -a |
| Listening ports | ss -tulpn | netstat -ano |
| DNS lookup | dig / host / nslookup | nslookup |
| Flush DNS cache | sudo systemd-resolve --flush-caches | ipconfig /flushdns |
| Renew DHCP lease | sudo dhclient -r && sudo dhclient | ipconfig /release + /renew |
| Packet capture | sudo tcpdump -i eth0 | Wireshark / pktmon |
| Port/host scan | nmap | nmap (or Test-NetConnection) |
| Test a TCP port | nc -zv host 443 | Test-NetConnection host -Port 443 |
| Throughput test | iperf3 | iperf3.exe |
| Interface stats | ip -s link / ethtool eth0 | netstat -e / Get-NetAdapterStatistics |
Best Practices
- Have a method, not a habit. Pick bottom-up, top-down, or divide-and-conquer on purpose based on the symptom — don’t just reflexively ping. Walking the stack guarantees progress; guessing does not.
- Change one thing at a time, and log it. Keep a running note of every command, its output, and every change. If a fix works, you know why; if it doesn’t, you can cleanly revert.
- Reproduce and isolate before you theorize. “One host or all hosts? One direction or both? One app or everything?” answered up front eliminates most of the search space instantly.
- Prove connectivity by IP before blaming anything else.
ping 8.8.8.8vsping nameis the fastest first cut: it separates the network from DNS in two seconds. - Test both directions. Firewalls and routing are often asymmetric. A capture on each end (SYN out, SYN-ACK back?) beats guessing.
- Prefer
digand query multiple resolvers. When DNS is suspect, compare two resolvers and use+traceto find exactly where the chain breaks. - Capture with a filter, analyze with a filter. Use a narrow BPF capture filter on busy links to keep files small; use Wireshark display filters to explore — but never filter so tightly at capture time that you lose the evidence.
- Distinguish cosmetic ICMP loss from real loss. In
mtr/traceroute, mid-path* * *or loss that clears by the final hop is usually router ICMP deprioritization, not a fault. Real loss persists to the destination. - Scan only what you’re authorized to.
nmapagainst networks you don’t own or lack written permission for can be illegal. Keep it to your lab and approved targets. - Lab your changes first. Reproduce complex topologies in GNS3/EVE-NG/Packet Tracer before touching production; verify a config change in the lab, then deploy.
- Verify from the user’s seat, then verify you broke nothing. Confirm the original symptom is gone and that adjacent services still work before you close the ticket.
- Feed findings back into monitoring. Every incident should leave behind a new alert or dashboard so the next occurrence is caught by
./14-monitoring-and-observability.md, not by a user.