Thông tin liên hệ
- 036.686.3943
- admin@nguoicodonvn2008.info
Netstat là một tiện ích dòng lệnh có thể được sử dụng để liệt kê tất cả các kết nối mạng (socket), cho phép so sánh với các kết nối mạng, bảng định tuyến, bản ghi interface, kết nối giả mạo, v.v... Bài viết này sẽ chia sẻ với bạn đọc 10 ví dụ hàng đầu về lệnh Netstat trên Linux.

Để hiển thị về các listening và non-listening socket, hãy sử dụng lệnh sau:
$ netstat -all
Đầu ra mẫu sẽ trông giống như sau:
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:mysql *:* LISTEN
tcp 0 0 linux-Inspiron-3:domain *:* LISTEN
tcp 0 0 linux-Inspiron-35:46930 ec2-54-236-207-15:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:59820 maa03s22-in-f14.1:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:46662 sc-in-f188.1e100.n:5228 ESTABLISHED
tcp 0 0 linux-Inspiron-35:41914 bom05s08-in-f4.1e:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:59760 maa03s22-in-f14.1:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:33172 ec2-54-221-62-191:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:43466 ec2-34-192-133-18:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:43480 a104-81-21-73.depl:http TIME_WAIT
tcp 0 0 linux-Inspiron-35:36270 maa03s20-in-f14.1:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:53360 maa03s20-in-f3.1e1:http ESTABLISHED
........................................................................................
Để hiển thị PID và tên của chương trình mà mỗi socket thuộc về, hãy sử dụng lệnh sau:
$ netstat --program
Đầu ra mẫu sẽ trông giống như sau:
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 linux-Inspiron-35:46930 ec2-54-236-207-15:https ESTABLISHED 23074/chrome
tcp 0 0 linux-Inspiron-35:59820 maa03s22-in-f14.1:https ESTABLISHED 23235/chromium-brow
tcp 0 0 linux-Inspiron-35:46662 sc-in-f188.1e100.n:5228 ESTABLISHED 23074/chrome
tcp 0 0 linux-Inspiron-35:41914 bom05s08-in-f4.1e:https ESTABLISHED 23074/chrome
tcp 1 0 linux-Inspiron-35:60770 117.18.237.42:http CLOSE_WAIT 23074/chrome
tcp 0 0 linux-Inspiron-35:43466 ec2-34-192-133-18:https ESTABLISHED 23074/chrome
............................................................................................
Để lấy thông tin về các cổng TCP, hãy sử dụng lệnh sau:
$ netstat --tcp
Đầu ra mẫu sẽ trông giống như sau:
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q L ocal Address Foreign Address State
tcp 0 0 linux-Inspiron-35:36310 maa03s20-in-f14.1:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:46930 ec2-54-236-207-15:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:46662 sc-in-f188.1e100.n:5228 ESTABLISHED
tcp 0 0 linux-Inspiron-35:36320 maa03s20-in-f14.1:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:33216 ec2-54-221-62-191:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:46478 arn02s05-in-f3.1e:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:43466 ec2-34-192-133-18:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:60794 117.18.237.42:http ESTABLISHED
tcp 0 0 linux-Inspiron-35:48080 104.244.42.136:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:58048 ip-166-62-112-150.:http ESTABLISHED
tcp 0 0 linux-Inspiron-35:33272 bom05s08-in-f163.:https ESTABLISHED
Để nhận thông tin cổng UDP, hãy sử dụng lệnh sau:
$ netstat --udp
Đầu ra mẫu sẽ trông giống như sau:
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 linux-Inspiron-35:46539 maa03s20-in-f5.1e:https ESTABLISHED
udp 768 0 localhost:46996 linux-Inspiron-3:domain ESTABLISHED
Để lấy danh sách các cổng Linux, hãy sử dụng lệnh sau:
$ netstat -lx
Đầu ra mẫu sẽ trông giống như sau:
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 27810 @/tmp/.ICE-unix/2345
unix 2 [ ACC ] STREAM LISTENING 26776 @/tmp/ibus/dbus-RkYlcXlm
unix 2 [ ACC ] STREAM LISTENING 20175 /var/run/mysqld/mysqld.sock
unix 2 [ ACC ] STREAM LISTENING 25423 /run/user/1000/systemd/private
unix 2 [ ACC ] STREAM LISTENING 24848 /run/user/126/systemd/private
unix 2 [ ACC ] SEQPACKET LISTENING 1784 /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 25933 /run/user/1000/keyring/control
unix 2 [ ACC ] STREAM LISTENING 22555 /var/run/NetworkManager/private-dhcp
unix 2 [ ACC ] STREAM LISTENING 24475 /run/user/1000/keyring/pkcs11
unix 2 [ ACC ] STREAM LISTENING 24477 /run/user/1000/keyring/ssh
unix 2 [ ACC ] STREAM LISTENING 112357 /tmp/.com.google.Chrome.3r7jSQ/SingletonSocket
Để hiển thị bảng định tuyến, hãy sử dụng lệnh sau:
$ netstat -r
Đầu ra mẫu sẽ trông giống như sau:
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default TutorialsPoint1 0.0.0.0 UG 0 0 0 enp7s0
default 192.168.1.254 0.0.0.0 UG 0 0 0 wlp6s0
link-local * 255.255.0.0 U 0 0 0 enp7s0
192.168.1.0 * 255.255.255.0 U 0 0 0 enp7s0
192.168.1.0 * 255.255.255.0 U 0 0 0 wlp6s0
Để hiển thị thống kê mạng, hãy sử dụng lệnh sau:
$ netstat -s
Đầu ra mẫu sẽ trông giống như sau:
Ip:
226777 total packets received
99 with invalid addresses
0 forwarded
0 incoming packets discarded
213036 incoming packets delivered
126141 requests sent out
48 outgoing packets dropped
Icmp:
420 ICMP messages received
120 input ICMP message failed.
ICMP input histogram:
destination unreachable: 414
echo requests: 6
576 ICMP messages sent
0 ICMP messages failed
ICMP output histogram:
destination unreachable: 570
echo replies: 6
IcmpMsg:
InType3: 414
InType8: 6
OutType0: 6
OutType3: 570
....................................................................................
Để tìm các họ địa chỉ không được hỗ trợ, hãy sử dụng lệnh sau:
$ netstat -v
Đầu ra mẫu sẽ trông giống như sau:
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 linux-Inspiron-35:46930 ec2-54-236-207-15:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:39418 arn09s10-in-f14.1:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:36398 maa03s20-in-f14.1:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:59950 maa03s22-in-f14.1:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:60888 117.18.237.42:http ESTABLISHED
tcp 0 0 linux-Inspiron-35:55716 maa03s20-in-f3.1e:https TIME_WAIT
tcp 0 0 linux-Inspiron-35:42044 bom05s08-in-f4.1e:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:49654 ec2-54-221-3-35.c:https ESTABLISHED
tcp 0 0 linux-Inspiron-35:47238 sc-in-f188.1e100.n:5228 ESTABLISHED
tcp 0 0 linux-Inspiron-35:42046 bom05s08-in-f4.1e:https ESTABLISHED
...........................................................................................
Để hiển thị thông tin khác/thêm về mạng, hãy sử dụng lệnh sau:
$ netstat -e
Đầu ra mẫu sẽ trông giống như sau:
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode
tcp 0 0 linux-Inspiron-35:46930 ec2-54-236-207-15:https ESTABLISHED linux 123811
tcp 0 0 linux-Inspiron-35:55458 52.222.136.134:https ESTABLISHED linux 148067
tcp 0 0 linux-Inspiron-35:43780 sb-in-f188.1e100.n:5228 ESTABLISHED linux 147150
tcp 0 0 linux-Inspiron-35:60924 117.18.237.42:http ESTAB LISHED linux 148291
tcp 0 0 linux-Inspiron-35:36446 maa03s20-in-f14.1:https ESTABLISHED linux 148068
tcp 0 0 linux-Inspiron-35:51126 edge-star-mini-sh:https ESTABLISHED linux 149411
tcp 0 0 linux-Inspiron-35:33338 ec2-54-221-62-191:https CLOSE_WAIT linux 146371
udp 0 0 linux-Inspiron-35:46539 maa03s20-in-f5.1e:https ESTABLISHED linux 117623
udp 768 0 localhost:46996 linux-Inspiron-3:domain ESTABLISHED linux 123551
..................................................................................
Để nhận được sự trợ giúp từ netstat, hãy sử dụng lệnh sau:
$ netstat -h
Đầu ra mẫu sẽ trông giống như sau:
usage: netstat [-vWeenNcCF] [] -r netstat {-V|--version|-h|--help}
netstat [-vWnNcaeol] [ ...]
netstat { [-vWeenNac] -i | [-cWnNe] -M | -s }
-r, --route display routing table
-i, --interfaces display interface table
-g, --groups display multicast group memberships
-s, --statistics display networking statistics (like SNMP)
-M, --masquerade display masqueraded connections
-v, --verbose be verbose
-W, --wide don't truncate IP addresses
-n, --numeric don't resolve names
--numeric-hosts don't resolve host names
--numeric-ports don't resolve port names
--numeric-users don't resolve user names
-N, --symbolic resolve hardware names
-e, --extend display other/more information
-p, --programs display PID/Program name for sockets
-c, --continuous c ontinuous listing
-l, --listening display listening server sockets
-a, --all, --listening display all sockets (default: connected)
-o, --timers display timers
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
={-t|--tcp} {-u|--udp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom
=Use '-6|-4' or '-A ' or '--'; default: inet
List of possible address families (which support routing):
inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
x25 (CCITT X.25)
Nguồn tin: Quantrimang.com
Ý kiến bạn đọc
Những tin mới hơn
Những tin cũ hơn
Lợi ích khi dùng Claude Code thay thế phần mềm CAD
4 tính năng ChatGPT từng yêu cầu phải trả tiền, nay đã miễn phí
TOP công cụ AI tăng năng suất thực sự đáng giá
Hướng dẫn tạo và quản lý lịch trình trong Gemini Spark
TOP công cụ AI Web Scraping tốt nhất
9 mô hình tạo ảnh AI tốt nhất năm 2026
Work IQ trong Copilot Studio
Sekai: Tạo Remix Chơi
Hướng dẫn xóa dữ liệu trình duyệt và máy tính từ xa Gemini Spark
Chào ngày mới thứ 6, lời chúc thứ 6 vui vẻ
TOP công cụ AI tạo biểu đồ tốt nhất
Hướng dẫn xây dựng storyboard tạo video AI Google Vids
Prompt AI tạo ảnh chân dung đường phố phong cách Y2K với đèn flash iPhone
TOP công cụ AI kiểm tra SEO (SEO Audit) tốt nhất
Prompt AI tạo ảnh đường phố châu Âu sau cơn mưa cực kỳ chân thực
Claude Code thực sự có giá bao nhiêu?
Prompt thiết kế hoạt động dạy học cho các môn học
Hướng dẫn kết nối Slack vào Claude để tối ưu hóa quy trình làm việc
Google Photos AI Enhance: Tự động chỉnh sáng, màu sắc ảnh