The netstat command is like a special tool in Linux that helps you understand and check things about how your computer connects to the internet. It can tell you about the connections your computer is making, the paths it uses to send information, and even some technical details like how many packets of data are being sent or received. In simple terms, it’s like a window that shows you what’s happening with your computer and the internet. This article will help you learn how to use netstat, exploring different ways to get specific information and giving you a better idea of what’s going on behind the scenes.
Overview of Netstat Command in Linux
`netstat` stands for network statistics. It allows users to display network-related information and diagnose various networking issues. The command has several options that can be combined to retrieve specific details.
Basic Syntax of `netstat`Command in Linux
Below is the general syntax of the netstat command:
netstat [options]
Let’s explore some of the most commonly used options along with examples:
Some Practical Examples of netstat Commands in Linux:
1) Show Both Listening and Non-listening Sockets Using netstat Command in Linux
-a -all : Show both listening and non-listening sockets. With the –interfaces option, show interfaces that are not up.
netstat -a | more


2) List All TCP Ports Using netstat Command in Linux
This command specifically lists all TCP ports, giving you information about the TCP connections your system is engaged in.
netstat -at

3) List All UDP Ports Using netstat Command in Linux
Similar to the previous example, this command focuses on UDP ports, revealing details about UDP connections.
netstat -au

4) List Only Listening Ports Using netstat Command in Linux
By using this option, you can see only the ports that are actively listening for incoming connections
netstat -l
To list only the listening ports.

5) List Only Listening TCP Ports Using netstat Command in Linux
Narrowing it down further, this command specifically lists the TCP ports that are in a listening state.
netstat -lt
To list only the listening tcp ports.

6) List Only Listening UDP Ports Using netstat Command in Linux
Similarly, this command focuses on displaying only the UDP ports that are actively listening.
netstat -lu
To list only the listening udp ports.

7) List Only Listening UNIX Ports Using netstat Command in Linux
For those working with UNIX systems, this option shows only the UNIX ports that are in a listening state.
netstat -lx
To list only the listening UNIX ports.

8) List Statistics for All Ports Using netstat Command in Linux
This command provides statistical information for all ports, offering insights into network activity.
netstat -s
To list the statistics for all ports.

9) List Statistics for TCP Ports Using netstat Command in Linux
For a more specific breakdown, this command displays statistics exclusively for TCP ports.
netstat -st
To list the statistics for TCP ports.

10) List Statistics for UDP Ports Using netstat Command in Linux
Similarly, this command focuses on the statistical information related to UDP ports.
netstat -su
List the statistics for UDP ports.

11) Display PID and Program Names Using netstat Command in Linux
This option enriches the output by displaying Process ID (PID) and program names associated with network connections.
netstat -pt
To display the PID and program names.

12) Print Netstat Information Continuously Using netstat Command in Linux
Executing this command continuously prints netstat information, updating at regular intervals to provide real-time insights.
netstat -c
To print the netstat information continuously.

13) Get Non-supportive Address Families Using netstat Command in Linux
To identify non-supportive address families on the system, use this command for a detailed overview.
netstat --verbose
To get the non-supportive address families in the system.

At the end, we have something like this.

14) Get Kernel Routing Information Using netstat Command in Linux
This command retrieves kernel routing information, displaying destination addresses, gateways, and interface details.
netstat -r
To get the kernel routing information.

15) Get Port on Which a Program is Running Using netstat Command in Linux
To find the port on which a specific program, in this case, SSH, is running, use this command.
netstat -ap | grep ssh
To get the port on which a program is running.

16) Identify Process Using a Particular Port Using netstat Command in Linux
This command helps identify the process associated with a given port, such as port 80 in this example.
netstat -an | grep ':80'
To get the process which is using the given port.

17) Get List of Network Interfaces Using netstat Command in Linux
Use this command to obtain a list of network interfaces, providing details about each interface’s activities.
netstat -i
To get the list of network interfaces.

Display Extended Information on Interfaces Using netstat Command in Linux
For extended information on interfaces, similar to the output of the ifconfig command, use this option to gain comprehensive insights.
netstat -ie
To display extended information on the interfaces

Netstat command in Linux – FAQs
What is the netstat command in Linux used for?
The netstat command in Linux is a powerful networking tool used to display a variety of information related to network connections, routing tables, interface statistics, and more. It helps users diagnose network issues and gain insights into the current state of network activities on a system.
How do I view all active connections using netstat?
To view all active connections using netstat, you can use the following command:
netstat -a
This command displays both listening and non-listening sockets, providing a comprehensive list of active network connections.
Can netstat show the processes associated with network connections?
Yes, netstat can show the processes associated with network connections. By using the `-p` option, you can include the Process ID (PID) and program names in the output. For example:
netstat -p
This command will display the processes along with their PIDs that are using network resources.
How do I monitor network activity in real-time with netstat?
To monitor network activity in real-time using netstat, you can use the `-c` option. This option continuously updates the netstat information at regular intervals.
For example:
netstat -c
Executing this command will provide ongoing updates on network statistics.
What is the difference between netstat and ss command in Linux?
The netstat and ss commands in Linux both provide information about network connections, but they differ in terms of features and efficiency. ss is considered a more modern and efficient replacement for netstat. It provides faster output, supports more filters, and is generally recommended for users who want a more streamlined and up-to-date tool for viewing network statistics. However, netstat remains widely used and available on many systems.
How to show listening network ports with netstat in Linux?
To display listening network ports using netstat in Linux, you can use the following command:
netstat -tuln
Here’s what each option means:
-t: Show TCP connections.
-u: Show UDP connections.
-l: Display only listening sockets.
-n: Show numerical addresses instead of resolving them to hostnames.
This command will provide a list of all listening TCP and UDP ports along with their respective numerical addresses
How to display all network connections with netstat in Linux?
To show all network connections using netstat in Linux, you can use the following command:
netstat -a
Here’s the breakdown of the options:
-a: Display all sockets, including listening and non-listening sockets.
This command will show a comprehensive list of all established connections, listening sockets, and other network-related information. Additionally, you can use the -n option to display numerical addresses instead of resolving them to hostnames:
netstat -an
These commands will help you monitor and analyze network connections on your Linux system.
Conclusion
In this article we discussed the netstat command in Linux which is like a special tool that helps you see how your computer connects to the internet. It’s like a window showing you information about connections, data paths, and technical details. This article covers practical examples of netstat commands, from displaying active connections to listing specific types of ports and getting detailed statistics. Whether you’re a beginner or more advanced, netstat offers versatile options. Common questions are answered, making it clear what netstat does and how it differs from other commands like ss in Linux. This knowledge helps users diagnose network issues and understand their system’s internet activities better.
Similar Reads
lsusb command in Linux with Examples
The 'lsusb' command in Linux is a useful utility for displaying information about USB buses and the devices connected to them. It provides a detailed view of the USB hardware connected to your system, including details such as speed, bus number, device class, and type. This command is particularly v
2 min read
mailq Command in Linux with Examples
mailq i.e. "mail-queue", this command in Linux prints the mail queue i.e. the list of messages that are there in the mail queue. You should have a mail-server setup on your Linux machine, to use this command, there are ways i.e MTA's(Mail Transfer agent) you can use like sendmail which uses the serv
3 min read
How to Read Manual Pages in Linux | man Command
The "man" command, short for manual, is a powerful tool in the Linux operating system that allows users to access detailed information about various commands, utilities, and system calls. The "man" command provides comprehensive documentation, helping users understand how to use and configure differ
9 min read
md5sum Command in Linux with Examples
The md5sum is designed to verify data integrity using MD5 (Message Digest Algorithm 5). MD5 is 128-bit cryptographic hash and if used properly it can be used to verify file authenticity and integrity. Example : Input : md5sum /home/mandeep/test/test.cppOutput : c6779ec2960296ed9a04f08d67f64422 /home
5 min read
How to Create Directory in Linux | mkdir Command
In Linux, the 'mkdir' command is like a magic wand for creating folders super easily. 'mkdir' stands for "make directory," and it helps you organize your computer stuff by creating folders with just one command. Whether you're making one folder or a bunch of them in a row, 'mkdir' is there to help y
7 min read
modinfo command in Linux with Examples
The modinfo command in Linux is used to display information about a Linux kernel module. It extracts detailed information from the modules available in the system and provides insights into their properties, dependencies, parameters, and more. If the module name is provided without a file name, the
3 min read
more command in Linux with Examples
The 'more' command in Linux is a useful tool for viewing text files in the command prompt, particularly when dealing with large files like log files. It displays the content one screen at a time, allowing users to scroll through the text easily. This command is especially handy for reviewing long ou
4 min read
How to Mount File System in Linux | mount Command
All files in a Linux filesystem are arranged in form of a big tree rooted at '/'.These files can be spread out on various devices based on your partition table, initially your parent directory is mounted(i.e attached) to this tree at '/', others can be mounted manually using GUI interface(if availab
6 min read
mpstat Command in Linux with Examples
mpstat is a powerful and versatile command-line tool within a Linux system that allows detailed reporting of various processor-related statistics. Indeed, part of the sysstat package, mpstat delivers comprehensive CPU utilization and performance data, thus becoming an essential utility for both syst
5 min read
How to Move File in Linux | mv Command
The `mv` command in Linux is like a superhero tool that can do a bunch of cool stuff with your files and folders. Think of it as a digital moving truck that helps you shift things around in your computer. Whether you want to tidy up your folders, give your files new names, or send them to different
7 min read
Practical Uses of nc(netcat) command in Linux
Netcat is one of the most powerful networking tools, security tools, and network monitoring tools. It is even considered a Swiss army knife of networking tools. It acts like a cat command over a network. It is generally used for the following reasons: Operation related to TCP, UDP, or UNIX-domain so
8 min read
Netstat command in Linux
The netstat command is like a special tool in Linux that helps you understand and check things about how your computer connects to the internet. It can tell you about the connections your computer is making, the paths it uses to send information, and even some technical details like how many packets
7 min read
Manage Network Connections From the Linux Command Line with nmcli
Network connectivity is a critical aspect of modern computing, and Linux provides a robust command-line tool for managing network connections: nmcli. Network Manager Command-Line Interface (nmcli) is a powerful and versatile utility that allows users to control and configure network settings directl
5 min read
Nslookup Command in Linux with Examples
Nslookup (stands for “Name Server Lookup”) is a useful command for getting information from the DNS server. It is a network administration tool for querying the Domain Name System (DNS) to obtain domain name or IP address mapping or any other specific DNS record. It is also used to troubleshoot DNS-
6 min read
od command in Linux with example
The od (octal dump) command in Linux is a versatile tool used to display file contents in various formats, with the default being octal. This command is particularly useful for debugging scripts, examining binary files, or visualizing non-human-readable data like executable code. It allows users to
6 min read
How to Change User Password in Linux | passwd Command
Securing user accounts is a fundamental aspect of maintaining a robust and secure Linux system. One essential task is changing user passwords regularly to prevent unauthorized access. The passwd command in Linux provides a straightforward and effective way to modify user passwords. This article will
8 min read
Paste command in Linux with examples
Paste command is one of the useful commands in Unix or Linux operating system. It is used to join files horizontally (parallel merging) by outputting lines consisting of lines from each file specified, separated by tab as delimiter, to the standard output. When no file is specified, or put dash ("-"
6 min read
pidof Command in Linux with Examples
pidof command is used to find out the process IDs of a specific running program. It is basically an identification number that is automatically assigned to each process when it is created. Syntax: pidof [options] program1 program2 ... programNWorking with Pidof Command 1. To find pid of any process
2 min read
How to Check Network Connectivity in Linux | ping Command
Ensuring a stable and reliable internet connection is crucial for seamless navigation and efficient communication in the world of Linux. The "ping" command is a powerful tool that allows users to check the status of their internet connection and diagnose network-related issues. In this article, we w
7 min read
Pinky command in Linux with Examples
Pinky command is a user information lookup command which gives details of all the users logged in. This tool is generally used by system administrators. It is similar to the finger tool but in many Linux, Systems pinky comes pre-installed while finger doesn't, so this command is useful in case you d
2 min read
pmap command in Linux with Examples
The pmap command in Linux is a powerful utility used to display the memory map of a process. A memory map provides insight into how memory is allocated and distributed within a running process. This can be incredibly useful for developers and system administrators when debugging memory issues, optim
4 min read
halt, poweroff and reboot Commands in Linux
In Linux systems, the halt, poweroff, and reboot commands are essential tools for controlling the system's hardware by stopping the CPU, shutting down the system, or restarting it. These commands are typically restricted to superusers, as they involve critical actions that impact the system hardware
4 min read
printf command in Linux with Examples
The 'printf' command in Linux is a versatile tool used to display formatted text, numbers, or other data types directly in the terminal. Like the 'printf' function in programming languages like C, the Linux printf command allows users to format output with great precision, making it ideal for script
4 min read
How to List Running Processes in Linux | ps Command
As we all know Linux is a multitasking and multi-user system. So, it allows multiple processes to operate simultaneously without interfering with each other. Process is one of the important fundamental concepts of the Linux OS. A process is an executing instance of a program that carries out differe
9 min read
How to Display Current Working Directory in Linux | pwd Command
The 'pwd,' which stands for "print working directory." In this article, we will delve into the 'pwd' command, exploring its functionality, usage, and various examples. It prints the path of the working directory, starting from the root. pwd is shell built-in command(pwd) or an actual binary(/bin/pwd
4 min read