Home Linux ServerLinux Fundementals 20 Netstat commands for Linux network management

20 Netstat commands for Linux network management

by Thạch Phạm
Published: Last Updated on
A+A-
Reset

In this article, AZDIGI will help you understand more about the 20 Netstat commands that Linux server administrators commonly use.

I. What is Netstat?

Netstat is short for “network statistics” and is a command-line tool used to monitor network connections both incoming and outgoing, as well as view routing tables, interface statistics, and other network-related information…

Netstat is built into all Unix operating systems and is also available on Windows operating systems. It is very useful for troubleshooting network issues and is often used for performance measurement. Netstat is one of the most basic network troubleshooting tools, showing you which ports are open and whether there are any programs using those ports.

This tool is very important and useful for Linux network administrators as well as system administrators to monitor and troubleshoot network-related issues and determine network traffic performance. This article will show you how to use netstat commands with examples that may be useful in your daily operations.

II. 20 useful Netstat commands commonly used

Below are 20 Netstat commands frequently used by administrators as well as a detailed description of each command.

1. List all LISTENING Ports of TCP and UDP connections

List all ports (both TCP and UDP) using the option netstat -a. You can also use netstat -a | more for a gradual view.

AZDIGI Tutorial
netstat -a
    
20-netstat-commands-network-management

2. List connections using Port TCP

This command is similar to command 1, but this command only lists TCP (Transmission Control Protocol) Ports using netstat -at.

AZDIGI Tutorial
netstat -at
hoặc
netstat -at | more
    
20-netstat-commands-network-management

3. List connections using UDP Port

This command is similar to command 1 but this command only lists UDP (User Datagram Protocol) Ports using netstat -au.

AZDIGI Tutorial
netstat -au
hoặc
netstat -au | more
    
20-netstat-commands-network-management

4. List all connections in the LISTENING state

List all active LISTENING connections with the netstat -l command.

AZDIGI Tutorial
netstat -l
hoặc
netstat -l | more
    
20-netstat-commands-network-management

5. List all TCP Listening Ports

List all active TCP Listening Ports using the netstat -lt option.

AZDIGI Tutorial
netstat -lt
hoặc
netstat -lt | more
    
20-netstat-commands-network-management

6. List all UDP Listening Ports

List all active UDP Listening Ports using the netstat -lu option.

AZDIGI Tutorial
netstat -lu
hoặc
netstat -lu | more
    
20-netstat-commands-network-management

7. List all UNIX Listening Ports

List all active UNIX Port Listening using the netstat -lx command.

AZDIGI Tutorial
netstat -lx
hoặc
netstat -lx | more
    
20-netstat-commands-network-management

8. Display statistics by Protocol

Display statistics by Protocol. By default, statistics are displayed for protocols such as TCP, UDP, ICMP and IP. The -s parameter can be used to specify a set of Protocols.

AZDIGI Tutorial
netstat -s
hoặc
netstat -s | more
    
20-netstat-commands-network-management

9. Display statistics by TCP protocol

Only TCP statistics are displayed using the netstat -st option.

AZDIGI Tutorial
netstat -st
hoặc
netstat -st | more
    
20-netstat-commands-network-management

10. Display statistics by UDP protocol

Display UDP protocol statistics only using thenetstat -su option.

AZDIGI Tutorial
netstat -su
hoặc
netstat -su | more
    
20-netstat-commands-network-management

11. Show service name with PID

To display the service name with PID number, use the netstat -tp command, it will display PID/Program name.

AZDIGI Tutorial
netstat -tp
hoặc
netstat -tp | more
    
20-netstat-commands-network-management

12. Promiscuous mode display

Display Promiscuous mode with the -ac option, netstat will show the existing information or refresh it every 5 seconds. The default refresh is every second.

AZDIGI Tutorial
netstat -ac 5 | grep tcp
    
20-netstat-commands-network-management

13. Show Kernel IP routing

Show the Kernel IP routing table with the netstat -r command.

AZDIGI Tutorial
netstat -r
    
20-netstat-commands-network-management

14. Display of online exchanges

Displays the number of packet exchanges on the network including sending and receiving MTU packets.

image 162

15. Show Kernel interface panel

Display the Kernel interface panel, similar to the ifconfig command with the netstat -ie command.

AZDIGI Tutorial
netstat -ie
hoặc
netstat -ie | more
    
20-netstat-commands-network-management

16. Display IPv4 and IPv6 information

Display IPv4 and IPv6 Group Memberships information with the netstat -g command.

AZDIGI Tutorial
netstat -g
    
20-netstat-commands-network-management

17. Show Netstat information continuously

To get the netstat information every few seconds, we will use the following netstat command, which will show the information continuously with the intensity of every few seconds.

AZDIGI Tutorial
netstat -c
    
20-netstat-commands-network-management

18. Find the service and the port that the service is using

This command is very commonly used to find the Port and the application that is using it. To check if the service is running and using the correct port.

AZDIGI Tutorial
netstat -tlpn
    
20-netstat-commands-network-management

19. Find services that are using the same port

Find out how many listeners are running on a port. Here I will search on the http/https port.

AZDIGI Tutorial
netstat -ap | grep http
    
Screen Shot 2020 12 30 at 1.36.46 PM 1

20. Display network statistics as raw data

Since this data is quite long, please add the more option after the command to view it slowly.

AZDIGI Tutorial
netstat --statistics --raw | more
    
image 166

III. Summary

Hopefully, with the above 20 commonly used netstat commands, you can find the information you need. Moreover, for deeper understanding, you can use the command man netstat to know all the information and options available.

image 167

Wishing you success! See more useful articles about Linux VPS at the following link:

If you need assistance, you can contact support in the ways below:

Đánh giá

Tham gia nhóm hỗ trợ Server - Hosting

Tham gia nhóm Hỗ trợ Server - Hosting & WordPress để cùng nhau hỏi đáp và hỗ trợ các vấn đề về WordPress, tối ưu máy chủ/server.

Tham gia ngay

Bài viết cùng chuyên mục

AZDIGI – Không chỉ là đơn vị hàng đầu trong lĩnh vực Web Hosting và Máy chủ, chúng tôi mong muốn mang lại những kiến thức bổ ích nhất và luôn cập nhật thường xuyên cho cộng đồng người đam mê thiết kế website, công nghệ,…

Vui lòng không sao chép nội dung nếu chưa xin phép. Designed and Developed by PenciDesign