×

netstat Command in Linux/Unix with Examples

The "netstat" command in Linux is a command-line utility that displays network connections, routing tables, and various network statistics. It is used to display the status of network connections, both incoming and outgoing, as well as information about the routing tables on a system.

The basic syntax for the command is:

netstat [options]

When the netstat command is run without any options, it will display a list of active network connections. The output of the command will include the protocol (TCP or UDP), the local and remote addresses, and the state of the connection. For example:

netstat

The netstat command has a number of options that can be used to customize its behavior. Some of the most commonly used options include:

  • -a: This option will display all active connections, including listening connections.
  • -t: This option will display only TCP connections.
  • -u: This option will display only UDP connections.
  • -l: This option will display only listening connections.
  • -n: This option will display the IP addresses and port numbers in numerical form, rather than resolving them to hostnames or service names.
  • -r: This option will display the routing table for the system.
  • -p: This option will display the process ID (PID) and name of the program that is responsible for each connection.

The netstat command can also be used to display various network statistics, such as the number of packets sent and received, the number of errors, and the number of collisions. To view these statistics, you can use the -s option with the netstat command. For example:

netstat -s

The netstat command can also be used to display the state of a specific connection. To view the state of a connection, you can use the -c option with the netstat command, and specify the connection by protocol, local address, and local port number. For example:

netstat -c -t -l

Additionally, the netstat command can also be used to display the status of a specific protocol. To view the status of a protocol, you can use the -s option with the netstat command, and specify the protocol by name. For example:

netstat -s -t

Another useful feature of the netstat command is its ability to monitor network connections in real-time. By using the -i option, you can display the number of packets and bytes sent and received on a network interface, and by using the -w option, you can specify the time interval for which the statistics are displayed.

netstat -i -w 2

This command will display the statistics for all network interfaces, updating the statistics every 2 seconds.

The netstat command can also be used to display the status of the multicast groups that a system is a member of. To display the status of multicast groups, you can use the -g option with the netstat command.

netstat -g

In summary, the netstat command in Linux is a powerful command-line utility that can be used to display a wide range of network information, including active connections, routing tables, network statistics, and protocol status. It can also be used to monitor network connections in real-time, and display the status of multicast groups. With the various options available, the netstat command can be used in a variety of ways to troubleshoot and monitor network issues on a Linux system.


Related Topics

Linux Commands List

Linux Commands List The Linux systems are filled with commands for several use cases. We have divided these commands into some of the most common implementations for a better understanding of...

2 minutes read.

awk Command in Linux/Unix with Examples

The 'awk' command in Linux is a powerful text processing tool that allows you to perform various operations on text files, such as searching, replacing, and manipulating text. The command...

4 minutes read.

How to change the ApacheHTTP port in Linux

What is an Apache HTTP server in Linux? When we talk about the most commonly used web servers, one of the web servers that cannot be missed is Apache. With the...

4 minutes read.

man Command in Linux/Unix with Examples

The man command in Linux is used to display the manual pages for a given command or system call. These manual pages provide detailed information on the command's usage, options,...

3 minutes read.

chmod Command in Linux/Unix with Examples

The chmod command in Linux is a command-line utility that is used to change the permissions of files and directories. It stands for "change mode" and it is used to...

4 minutes read.

du Command in Linux/Unix with Examples

The "du" command in Linux (and other Unix-like operating systems) is used to estimate the space used by a file or directory. The du command stands for "disk usage," and...

4 minutes read.

cut Command in Linux/Unix with Examples

The "cut" command in Linux (and other Unix-like operating systems) is used to remove sections from each line of a file or stream of data. The cut command is often...

3 minutes read.

wc Command in Linux/Unix with Examples

The wc command in Linux is a command-line utility that is used to count the number of lines, words, and characters in a text file or standard input. The name...

4 minutes read.

addgroup Command in Linux with Examples

What is the addgroup command? It is a command in Linux to create a new group using specified command lined and the system’s default values. How to add groups Adding a user group:...

4 minutes read.

Linux Bash

Linux Bash In this tutorial, we are going to learn what the shell is? And how many various shells we have, we have also covered most of the bash shell features....

4 minutes read.

curl Command in Linux/Unix with Examples

The 'curl' command in Linux is a command-line tool that allows you to transfer data from or to a server using various protocols, including HTTP, HTTPS, FTP, and many more....

3 minutes read.

mkdir Command in Linux/Unix with Examples

The "mkdir" command in Linux (and other Unix-like operating systems) is used to create new directories. The "mkdir" command stands for "make directory" and it is used to create a...

3 minutes read.

Linux mkdir | Linux Create Directory

The Linux mkdir command is very much similar to Windows’s "new folder" feature. This command is used in Linux os to create new directories. The command mkdir stands for "make...

1 minute read.

ls Command in Linux/Unix with Examples

The ls command in Linux is a command-line utility that is used to list the files and directories in a directory. It is one of the most basic and commonly...

4 minutes read.

unzip Command in Linux/Unix with Examples

The 'unzip' command in Linux is used to extract files from a ZIP archive file. The command allows you to decompress and extract the files and directories stored in a...

3 minutes read.

apt-get Command in Linux with Examples

The apt-get command is a command-line tool that is used to handle packages in Linux. This command handles the processes like retrieving the packages and information from authentic sources for...

5 minutes read.

Linux Path Completion

Every operating system has some features which make them special. The Linux operating system primarily works on the command line interface, and we do have many features for this CLI....

1 minute read.

grep Command in Linux/Unix with Examples

The grep command in Linux is a command-line utility that searches for patterns in text files. It stands for "global regular expression print" and it is used to search for...

5 minutes read.

Linux apt-get command

Apt-get is a command-line that helps to handle the packages in Linux. Its major task is to assist in retrieving data and packages from trusted sources for purposes of installation,...

6 minutes read.

sudo Command in Linux/Unix with Examples

The sudo command in Linux is used to run a command or set of commands with the privileges of another user, typically the root user. This allows users to perform...

3 minutes read.