11

A Simple Guide to Using the netstat Command in Linux

 2 years ago
source link: https://www.makeuseof.com/netstat-command-guide-linux/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

A Simple Guide to Using the netstat Command in Linux

By Jerome Davidson

Published 16 hours ago

Linux has got a plethora of tools to get network-related information. One such tool is netstat, a command-line network statistics monitor for Linux.

netstat is a command-line tool used to monitor network statistics. It enables you to view network data such as the ports in use, active connections, packets that have been transferred, etc.

It’s interesting to note that this very utility is available on Windows Server editions and is very similar in usage to that on Linux.

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

Structuring netstat Commands

There are two ways in which you can use the netstat command: either run the command alone or run it with options. If you choose to run netstat without any options indicated, it will display all active connections on your system.

netstat
netstat command in linux

When running netstat with options, you need to specify a hyphen (-) before each flag.

netstat [-option1] [-option2] …

netstat has a number of flags, and in the next section, you'll see some examples in use.

If you have many options to include in your command, it can be disturbing to add a hyphen every time. Fortunately, netstat provides a simpler way of doing so.

You can simply use one hyphen and then consecutively list your options without any spaces between them. For example, instead of typing netstat -p -n -t, you can simply run netstat -pnt.

You’ll find this summative format very convenient when you have to run multiple netstat commands with many options:

netstat -[option1][option2][option3]...

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

netstat Commands You Should Know Of

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

netstat -s

To list all TCP (Transmission Control Protocol) connections, run the command below:

netstat -at

Similarly, for UDP connections, issue the following command:

netstat -au

To list all servers/ports that are actively running (listening) on your system, run:

netstat -plnt

It’s important to note that this command may require sudo privileges. This is because the root user may be the owner of some of the services.

This particular command is very important as it even shows you the program IDs of the running servers. You can use this information to stop servers that you don’t want running on your system.

ss: A Successor to the netstat Command

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

About The Author

60f2accf7711f-pictureJD.jpg?fit=crop&w=100&h=100

Jerome Davidson (31 Articles Published)

Jerome is a Staff Writer at MakeUseOf. He covers articles on Programming and Linux. He's also a crypto enthusiast and is always keeps tabs on the crypto industry.

More From Jerome Davidson

Subscribe to our newsletter

Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals!

Click here to subscribe

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK