System administrators utilize network statistics or netstat as a command-line tool to analyze network data. Routing tables, multicast memberships, interface statistics, network connections, masquerade connections, and other network-related information is displayed using the netstat command. It also assists you in finding out network problems.
In this post, you will learn about how to install and use netstat on CentOS. So, let’s start!
How to install netstat on CentOS
In Linux distributions such as CentOS, the package that comprises the net-stat is known as “net-tools”. The “net-tools” package has a tools collection for controlling the network subsystem of Linux.
To install “net-tools” on your system, open up the CentOS terminal by pressing “CTRL+ALT+T” and write out the below-given command in it:
The error-free output indicates that the net-tools package is successfully installed on the system. Now, confirm its existence using the “netstat -V” command, it will show you the version of “net-stat”:
The above-given netstat command will show you the following output:
How to use netstat on CentOS
For displaying various types of statistics on your CentOS, you can utilize the netstat command in your terminal. In the upcoming section, we will demonstrate you how to use the netstat command in various forms. Go ahead and understand this concept carefully!
How to view network interface statistics using netstat on CentOS
You can execute the net-stat command for viewing the list of network interfaces with their statistics in your terminal:
Here, the “-i” option is added for retrieving the output of network interface statistics, while “-a” print all of the existing network interfaces of the Linux kernel:
How to view network routing table using netstat on CentOS
In the netstat command, the “-n” option is added to list network addresses separated by dots, and “-r” displays the network routing table:
How to view TCP connections using netstat on CentOS
Adding the “-t” option in the netstat command will print out the TCP connection, and the “-a” option will display all active network connections. When you utilize the combination of the “-at” option in the netstat command, it will list all the active TCP connections on your system:
How to view UDP connections using netstat on CentOS
If you want to view the information related to UDP traffic, then add the “-au” options in the netstat command:
Here, the “-u” option is used for printing the UDP connections, and “-a” will help netstat to fetch the list of active connections:
How to list network services using netstat on CentOS
Execute the below-given command for listing the network services with their related information such as protocol name, its current state, PID, etc:
Here:
- “-p” option shows all process IDs (PID) for sockets.
- “-n” option is used to list out the IP addresses.
- “-l” option prints the server socket having the “LISTEN” state.
- “-t” option is utilized to print the TCP connections.
- “-u” option is used to print the UDP connections.
How to list all UNIX listening ports using netstat on CentOS
A combination of “-l” and “-x” options will print out all the active listening ports on your CentOS system:
Here, the “-l” option prints the server socket having the “LISTEN” state, whereas the “-x” option will show the list of Unix socket connections:
How to view all protocols statistics using netstat on CentOS
Using the netstat command, you can also check out the network statistics of your protocol by their names, such as the network statistics for IP, ICMP, TCP, UDP protocols. For this purpose, the “-s” option is added in the netstat command:
How to view TCP protocol statistics using netstat on CentOS
If you only want to view the TCP protocol statistics, then add the combine the “-s” with “-t” option:
How to view UDP protocol statistics using netstat on CentOS
It is also possible to only check out the statistics of UDP protocol. To do so, execute the netstat command with the “-su” options:
How to show kernel interface table using netstat on CentOS
In the netstat command, add the “-ie” options for displaying Ethernet statistics:
How to display IPv4 and IPv6 information using netstat on CentOS
In your CentOS terminal, you can execute the netstat command with the “-g” option to display multicast group membership information of IPv4 and IPv6:
Conclusion
The netstat or network statistics is a command-line tool used for retrieving network statistics. It displays helpful information such as whether your system ports are open or have active connections, etc. You can utilize the netstat utility is critical for identifying network issues. You have learned how to install and use netstat on CentOS in this post. Try it out to know your system network more deeply!