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:

$ sudo yum install net-tools

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image1-12.png" data-lazy- height="473" src="data:image/svg xml,” width=”740″>

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image3-10.png" data-lazy- height="392" src="data:image/svg xml,” width=”755″>

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image2-11.png" data-lazy- height="301" src="data:image/svg xml,” width=”800″>

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image5-11.png" data-lazy- height="328" src="data:image/svg xml,” width=”758″>

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image4-11.png" data-lazy- height="367" src="data:image/svg xml,” width=”802″>

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image7-9.png" data-lazy- height="398" src="data:image/svg xml,” width=”801″>

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.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image6-10.png" data-lazy- height="471" src="data:image/svg xml,” width=”801″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image9-6.png" data-lazy- height="471" src="data:image/svg xml,” width=”799″>

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image8-9.png" data-lazy- height="474" src="data:image/svg xml,” width=”803″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image12-4.png" data-lazy- height="472" src="data:image/svg xml,” width=”804″>

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image10-5.png" data-lazy- height="474" src="data:image/svg xml,” width=”804″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image11-4.png" data-lazy- height="470" src="data:image/svg xml,” width=”801″>

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image13-3.png" data-lazy- height="470" src="data:image/svg xml,” width=”803″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image14-1.png" data-lazy- height="474" src="data:image/svg xml,” width=”803″>

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image15.png" data-lazy- height="473" src="data:image/svg xml,” width=”806″>

How to show kernel interface table using netstat on CentOS

In the netstat command, add the “-ie” options for displaying Ethernet statistics:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image16.png" data-lazy- height="562" src="data:image/svg xml,” width=”800″>

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/image17.png" data-lazy- height="437" src="data:image/svg xml,” width=”803″>

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!

About the author

<img alt="" data-lazy-src="https://secure.gravatar.com/avatar/c73b74cd8044d2e9b300610f5af77d0b?s=112&r=g" data-lazy- height="112" src="data:image/svg xml,” width=”112″>

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.