Linux Netstat Command with examples

Let's get to the basics of the Linux networking command "netstat" and see various uses of it using examples. The netstat command is a swiss army knife for Linux system administrators for tapping out vital system information for troubleshooting purposes.

The Linux command Netstat (Network Statistics) is used to display the different information of the network. That includes network connections, routing tables, masquerade connections, interface statistics, multicast membership, and so on. This command is handy and important for Linux network administrators to handle the network-related problems, troubleshoot and monitor the network issues, and determine the performance of network traffic.

Note: In new updates of Linux, the ss command replaced the netstat command. This command is more powerful and can show more network connection information than the netstat command. We shall deal with the ss command later, but for now, let’s understand the usage of the still useful netstat command.

Netstat Command with examples

1. Display all the listening ports of TCP and UDP connections

To display the listening and non-listening sockets of network use -a -all option with netstat. Also, you can display the interfaces that are not up using -interface option.

# netstat -a | more

Example:

Display all tcp udp listening ports
Display all TCP UDP listening ports

2. List all TCP ports connections:

To display only the TCP port connections, use the below command:

# netstat -at

Example:

Display tcp ports
Display TCP ports

3. List all UDP port connections

To display only the UDP port connections, use the following command:

# netstat -au

Example:

Display all udp ports
Display all UDP ports

4. Display all listening ports

To show only the active listening port connections use the ‘l’ operator.

# netstat -l

Example:

Display only listening connections
Display only listening connections

5. Display TCP listening ports

Similarly, the “lt” operator shows only the active listening TCP port connections.

# netstat -lt

Example:

Display tcp listening ports
Display TCP listening ports

6. Display UDP listening ports

Another handy option to retrieve only the active listening UDP port connections. It can be done using the below command:

# netstat -lu

Example:

Display UDP listening ports
Display UDP listening ports

7. List all listening ports of UNIX

The active listening UNIX port connections can be obtained by using the “lx” operator.

# netstat -lx

Example:

Display all UNIX listening ports
Display all UNIX listening ports

8. Display statistics By Protocols

To display the statistics of all the protocols TCP, UDP, ICMP, and IP, use the below command:

# netstat -s

Example:

Display statistics for all protocols
Display statistics for all protocols

9. Display statistics By TCP Protocols

To show the statistics of the TCP protocol, use the following command:

# netstat -st

Example:

Display statistics for TCP protocol
Display statistics for TCP protocol

10. Display statistics By UDP Protocols

To show the statistics of the UDP protocol, use the “su” command:

# netstat -su

Example:

Display statistics for TCP protocol
Display statistics for TCP protocol

11. Displaying Service name with Process ID

For displaying the program name with PID, use netstat command with -tp option, which shows the ‘PID/Program Name.’

# netstat -tp

Example:

Displaying service name with process id
Displaying service name with process id

12. Continuously print the netstat information

The following command continuously prints the netstat information every few seconds.

# netstat -c

13. Display Kernel IP routing

Get the Kernel IP routing table information using the following command:

# netstat -r

Example:

Display Kernel IP Routing Table
Display Kernel IP Routing Table

14. Display Network Interface Transactions

Retrieve the network interface transactions information using -i:

# netstat -i

Example:

Display network interface transactions
Display network interface transactions

15. Display Kernel Interface Table

To show the Kernel interface table similar to ifconfig, use ie:

# netstat -ie

Example:

Display kernel interface table
Display kernel interface table

16. Display IPv4 and IPv6 Information

To get the group membership information for both IPv4 and IPv6, use the below command.

# netstat -g

Example:

Display ipv4 and ipv6 info
Display ipv4 and ipv6 info

17. Display Non-Supportive Address

To populate the non-supportive address, families with important information use the verbose command.

# netstat --verbose

Example:

Display non supportive address
Display non-supportive address

18. Find Listening Programs

To find and display listening programs on a port, use the grep along with ap.

# netstat -ap | grep http

Example:

Display Listening Programs
Display Listening Programs

19. Display RAW Network Statistics

To gather the raw network statistics, use the ap along with the grep function.

# netstat -ap | grep http

Example:

Display raw statistics
Display raw statistics

Conclusion

That’s the top examples of the netstat command used for networking. If you are looking for more information and options about, fire up the man netstat command in the terminal to get all the information.

Habib Ahmed
He is a professional writer with more than seven years of experience in the field. He also enjoys technical writing/ manuals, white papers, and scientific presentations.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

23,241FansLike
394FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

MUST READ

The Ubuntu Cinnamon Remix brings together Linux Mint's Cinnamon desktop with the Ubuntu Core. While some users are welcoming the new flavor of Ubuntu with open arms, others are scratching their heads, wondering where it fits in.
The wait is finally over (almost) for all you Ubuntu fans out there. The latest version of Ubuntu, 20.10 codenamed "Groovy Gorilla," is currently available in the beta version. I have tested out the distro myself, and it is stable enough to take out for a spin.

The 10 Best Programming Languages for Hacking

One of the significant entities we have in Cyber Security is Ethical Hacking (ETH). It is the process of detecting and finding flaws or vulnerabilities in a system that a hacker would exploit.

Top 5 Linux Distros for Windows Users

When Microsoft initially released Windows 7 in October 2009, the software giant committed to providing ten years of support for its popular operating system.  The much-maligned Microsoft was true to their word, support for Windows 7 ended just yesterday a little over ten years after its release.

What’s New in Ubuntu 20.04 LTS “Focal Fossa”

Ubuntu 20.04 LTS is out now! This is the successor to Ubuntu 18.04, which was released in April 2018 and still has three years of official support left. Code-named Focal Fossa, the new edition has all the bells and whistles included in it, making it one of the best Ubuntu releases yet. Let's find out more.

6 ways to find out your Linux file system type

Any Operating system in the market whether its Windows, Linux, Unix, macOS, and any other, must be able to access and manage files and data on storage devices.