A Easy Information to Utilizing the netstat Command in Linux

Linux has a variety of tools for obtaining network-related information. One such tool is netstat, a command line network statistics monitor for Linux.

netstat is a command line tool for monitoring network statistics. It enables you to view network data such as the ports used, active connections, packets transmitted, etc.

It is interesting to note that this very same utility is available in Windows Server editions and is very similar to using it on Linux.

Follow this article to see how to use the netstat command on your Linux system.

Structuring netstat commands

There are two ways to use the netstat command: either run the command alone or with options. If you choose to run netstat with no options displayed, it will display all active connections on your system.

netstat

When running netstat with options, you need to a. indicate hyphen () in front of each flag.

netstat (-option1) (-option2) …

netstat has a number of flags, and in the next section you will see some examples of how they are used.

If you can include a lot of options in your command, it can be annoying to add a hyphen every time. Fortunately, netstat offers an easier way to do this.

You can just use a hyphen and then list your options one by one with no spaces. For example, instead of typing netstat -p -n -t, you can just walk netstat -pnt.

You will find this summative format very handy when you need to run multiple netstat commands with many options:

netstat – (Option1) (Option2) (Option3) …

Related: Why You Should Use the Linux Networking Tool in Windows with WSL

netstat commands you should know

If you want to know the statistics for the UDP, TCP, ICMP, and IP protocols, use the following command:

netstat -s

Run the following command to list all Transmission Control Protocol (TCP) connections:

netstat -at

For UDP connections, issue the following command:

netstat -au

To list all servers / ports that are actively running (listening) on ​​your system, do the following:

netstat -plnt

It is important to note that this command may require sudo permissions. This is because the root user may own some of the services.

This particular command is very important as it will even show you the program IDs of the running servers. You can use this information to stop servers that you do not want to be running on your system.

ss: A successor to the netstat command

While netstat is a good tool for monitoring network connections, it is not as detailed as the ss utility. You can use the ss command to monitor network sockets on Linux. It is faster than netstat and offers more detailed information.

How to monitor network connections on Linux with ss

If you suspect a network problem on your Linux system, the ss command can be used to track and fix it.

Continue reading

About the author

Jerome Davidson
(31 published articles)

Jerome is a staff writer at MakeUseOf. It covers articles on programming and Linux. He is also a crypto enthusiast and is always keeping an eye on the crypto industry.

More
By Jerome Davidson

Subscribe to our newsletter

Subscribe to our newsletter for tech tips, reviews, free e-books, and exclusive offers!

Click here to subscribe

Leave a Reply

Your email address will not be published. Required fields are marked *