×

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

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.

cd Command in Linux/Unix with Examples

The 'cd' command in Linux is used to change the current working directory. The command stands for "change directory" and it is used to navigate the file system on a...

3 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.

mv Command in Linux/Unix with Examples

The 'mv' command in Linux is used to move or rename files and directories. The command stands for "move" and it allows you to move files and directories from one...

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 Commands with Examples

Linux Commands with Examples All the Linux commands are executed on the terminal provided by the Linux system. This terminal is a command-line interface to implement and display command outputs. Linux...

10 minutes read.

scp Command in Linux/Unix with Examples

The scp (secure copy) command in Linux is a command-line utility that is used to securely transfer files between two hosts over a network. It is similar to the cp...

4 minutes read.

echo Command in Linux/Unix with Examples

The "echo" command in Linux is used to display a line of text on the terminal. It can also be used to print the value of a variable or to...

3 minutes read.

cat Command in Linux/Unix with Examples

The cat command in Linux is a command-line utility that is used to display the contents of a text file. It stands for "concatenate" and it is used to view...

4 minutes read.

addr2line Command in Linux with Examples

Use of addr2line Command The addr2line command is used to convert addresses to line numbers and file names. This command uses debugging info to check which line number and file name...

4 minutes read.

Linux Distributions

Linux Distributions Linux OS is not like other operating systems. Linux can be modified according to the user’s requirements, and it is very flexible to any change. Linux distributions are often...

4 minutes read.

tar Command in Linux/Unix with Examples

The 'tar' command in Linux is used to create, maintain, and extract files from archive files called tarballs. The command stands for "tape archive" and it allows you to combine...

4 minutes read.

rm Command in Linux/Unix with Examples

The "rm" command in Linux (and other Unix-like operating systems) is used to remove files and directories. The "rm" command stands for "remove" and it is used to delete files...

4 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.

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.

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.

ping Command in Linux/Unix with Examples

The "ping" command in Linux (and other Unix-like operating systems) is used to test the connectivity between two networked devices. The "ping" command sends a small packet of data, called...

4 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.

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.

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.