What command would you use for showing network statistics in the Linux terminal?

Linux is one of the most widely used operating systems that is being used for different requirements and developments. Most of us might have used it for some time in our development career. While working on Linux knowing the right command saves a lot of time and headache. I generally refer to the below article to find commands that I use most frequently.

Linux Commands Cheat Sheet | Tips and Tricks

The Linux commands that every software developer should know.

medium.com

1. ifconfig

ifconfig — Interface configurator.

This command is used to display the route and the network interface. It is also used for initializing an interface, configuring it with an IP address, and enabling or disabling it.

Syntax : ifconfig

2. traceroute

traceroute — Used for troubleshooting the network. It detects the delay and determines the pathway to the specified target.

  • It provides the names and identifies every device on the path.
  • It follows the route to the destination
  • It determines where the network latency comes from and reports it.

Syntax : traceroute

Note : If you don’t have the traceroute service installed in your system, you can install it using the following command:

curl https://www.google.com
0

Command:

curl https://www.google.com
1

The output of the above command will have the following information: the specified hostname, size of the packets, the maximum number of hops required, the IP address.

Note: To avoid the reverse DNS lookup, add -n in the command syntax.

Command:

curl https://www.google.com
2

The output indicates the network delays. The asterisks shown in the output indicate a potential problem in reaching that host. They indicate the packet loss during communication to the network.

Generally, the traceroute command sends UDP packets. It can as well send TCP or ICMP packets.

  • To specifically send in ICMP, use this,

Command:

curl https://www.google.com
3

  • To send a variant of TCP, use this,

Command:

curl https://www.google.com
4

3. tracepath

curl https://www.google.com
5 — similar to the traceroute command.

It is used to detect network delays. However, it doesn’t require root privileges and is installed in Ubuntu by default.

It traces the route to the specified destination and identifies each hop in it. If your network is weak, it recognizes the point where the network is weak.

Syntax:

curl https://www.google.com
6

Example:

curl https://www.google.com
7

4. ping

Linux ping is one of the most used network troubleshooting commands. It checks for the network connectivity between two nodes.

curl https://www.google.com
8 stands for Packet INternet Groper.

The ping command sends the ICMP echo request to check the network connectivity. It keeps executing until it is interrupted. We can use the ctrl+c key to interrupt the execution.

Syntax :

curl https://www.google.com
9

Example :

curl http://example.{one, two, three}.com
0

We can also use the IP address to ping directly. We can limit the number of packets by including “-c” in the ping command.

Syntax :

curl http://example.{one, two, three}.com
1

5. netstat

Linux netstat command refers to the network statistics.

It provides statistical figures about different interfaces which include open sockets, routing tables, and connection information.

Syntax:

curl http://example.{one, two, three}.com
2

Output:

vikram@100200300 ~ % netstat
Active Internet connections
Proto Recv-Q Send-Q Local Address Foreign Address (state)
tcp4 0 0 1.2.3.4.5865 4.3.2.1.https ESTABLISHED
tcp4 0 0 1.100.1.3.542 1.40.1.17.18903 SYN_SENT

Observe the output displaying all the open sockets.

Variations in netstat command:

Below are a few variations of the netstat command used.

  • To display the programs, use below

Syntax:

curl http://example.{one, two, three}.com
3

  • To get the details of the ports, use below

Syntax:

curl http://example.{one, two, three}.com
4

This gives detailed statistics of all the ports.

  • To get the information of the routing table, use below

Syntax:

curl http://example.{one, two, three}.com
5

This gives information related to the routing table.

6. hostname

Linux hostname is the simple command used to view and set the hostname of a system.

Syntax:

curl http://example.{one, two, three}.com
6

To set the hostname —

Use the syntax below to set the hostname.

Syntax:

curl http://example.{one, two, three}.com
7

The hostname set through this command is not permanent. It will be reset to the name in the hostname file back when the system reboots.

To permanently set a hostname, you have to re-write the hostname in the hostname file, present on the server. Once set, you have to reboot the box.

  • In Ubuntu, /etc/hostname file is used.
  • In RHEL, /etc/sysconfig/network is used.

7. curl

curl is a command-line tool to transfer data to or from a server, using any of the supported protocols (HTTP, FTP, IMAP, POP3, SCP, SFTP, SMTP, TFTP, TELNET, LDAP, or FILE).

curl:

Syntax:

curl http://example.{one, two, three}.com
8

Example:

The most basic use of

curl http://example.{one, two, three}.com
9 is typing the command followed by the URL.

curl https://www.google.com

This displays the content of the URL on the terminal. The URL syntax is protocol dependent and multiple URLs can be written as sets like:

curl http://example.{one, two, three}.com

URLs with numeric sequence series can be written as:

curl ftp://ftp.example.com/file[1-20].jpeg

Below Options can be used with the curl command:

  • o: using this flag we can save the downloaded file on the local machine with the name provided as the parameters.

Syntax:

curl -o [file_name] [URL...]

Example:

curl -o curl_file.html https://www.google.com

8. wget

  • curl ftp://ftp.example.com/file[1-20].jpeg
    0 is a command-line utility for downloading files from the web.
  • With
    curl ftp://ftp.example.com/file[1-20].jpeg
    1, you can download files using
    curl ftp://ftp.example.com/file[1-20].jpeg
    2,
    curl ftp://ftp.example.com/file[1-20].jpeg
    3, and
    curl ftp://ftp.example.com/file[1-20].jpeg
    4 protocols.
  • curl ftp://ftp.example.com/file[1-20].jpeg
    1 provides several options allowing you to download multiple files, resume downloads, limit the bandwidth, recursive downloads, download in the background, mirror a website, and much more.

Syntax :

curl ftp://ftp.example.com/file[1-20].jpeg
6

Let’s see some examples:

  • To simply download a webpage:

curl ftp://ftp.example.com/file[1-20].jpeg
7

  • To download the file in the background:

curl ftp://ftp.example.com/file[1-20].jpeg
8

  • To overwrite the log while downloading the file using the
    curl ftp://ftp.example.com/file[1-20].jpeg
    1 command:

curl -o [file_name] [URL...]
0

  • Resume a partially downloaded file:

curl -o [file_name] [URL...]
1

  • To try a given number of times:

curl -o [file_name] [URL...]
2

9. whois

Linux whois command is used to fetch all the information related to a website. You can get all the information about a website including the registration and the owner information.

Syntax:

curl -o [file_name] [URL...]
3

Example:

curl -o [file_name] [URL...]
4

10. scp

SCP (secure copy) is a command-line utility that allows you to securely copy files and directories between two locations.

With

curl -o [file_name] [URL...]
5, you can copy a file or directory:

  1. From your local system to a remote system.
  2. From a remote system to your local system.
  3. Between two remote systems from your local system.

When transferring data with scp, both the files and password are encrypted so that anyone snooping on the traffic doesn’t get anything sensitive.

SCP Command Syntax:

Let’s review the basic syntax of the

curl -o [file_name] [URL...]
5 command.

curl -o [file_name] [URL...]
7

  • curl -o [file_name] [URL...]
    8 - scp options such as cipher, ssh configuration, ssh port, limit, recursive copy, etc.

Local files should be specified using an absolute or relative path, while remote file names should include a user and host specification.

curl -o [file_name] [URL...]
5 provides several options that control every aspect of its behavior. The most widely used options are:

  • curl -o curl_file.html https://www.google.com
    0 — Identity_file
    Selects the file from which the identity (private key) for public-key authentication is read. This option is directly passed to ssh(1).
  • curl -o curl_file.html https://www.google.com
    1 - This option tells
    curl -o [file_name] [URL...]
    5 to copy directories recursively.

11. ssh

curl -o curl_file.html https://www.google.com
3 stands for Secure Shell. It is a protocol used to securely connect to a remote server/system.
curl -o curl_file.html https://www.google.com
3 is secure in the sense that it transfers the data in encrypted form between the host and the client. It transfers inputs from the client to the host and relays back the output.
curl -o curl_file.html https://www.google.com
5 runs at
curl -o curl_file.html https://www.google.com
6

Syntax:

curl -o curl_file.html https://www.google.com
7

Example:

curl -o curl_file.html https://www.google.com
8

The

curl -o curl_file.html https://www.google.com
9 flag — To use a private key for a specified hostname and not the default ssh key that is located in ifconfig0

You can consider following me to get notified whenever I publish such helpful articles.

That’s all for this article. Thank you for reading it. I hope I have made the above commands very clear. I write on multiple topics that include Java Programming, Data structure, and Big O, SQL, GIT, Linux, Software development, etc.

What is the Linux command to see the network statistics?

The ifstat command prints network interface statistics. The interface keeps records of the previous data displayed in history files. By default, it only displays the difference between the last and current calls.

Which command is used to check the network statistics?

The netstat -M command displays the network memory's cluster pool statistics.

What command would you use for showing network connections in the Linux terminal?

netstat command – It is used to display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

What command would you use for showing network statistics in the Linux Terminal you can use parameters in alphabetic order?

Netstat command is used to examine network connections, routing tables, and various network settings and statistics.