10 Linux Network Commands to check network status

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. 

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.

Syntax : traceroute <destination>

Note : If we don’t have the traceroute service installed in our system, we can install it using the following command:
sudo apt-get install inetutils-traceroute

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

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

3. tracepath

tracepath — 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 our network is weak, it recognizes the point where the network is weak.
Syntax: tracepath <destination>
Example: tracepath google.com

4. ping

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

ping 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 : ping <destination>
Example : ping google.com

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 : ping -c <number> <destination>

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: netstat
~ % netstat

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: netstat -p
To get the details of the ports, use below
Syntax: netstat -s
This gives detailed statistics of all the ports.
To get the information of the routing table, use below
Syntax: netstat -r
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.

To set the hostname —
Use the syntax below to set the hostname.

Syntax:sudo hostname <newName>
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, we have to re-write the hostname in the hostname file, present on the server. Once set, we have to reboot the box.
In Ubuntu, /etc/hostname file is used.
In RHEL, /etc/sysconfig/network is used.

7. curl

Linux curl and wget commands are used in downloading files from the internet through CLI. The curl command has to be used with the option O to fetch the file, while the wget command is used directly.

Syntax: curl -O <fileLink>
Example: curl -O https://how.medium.com/
Syntax: wget <fileLink>
Example: wget https://how.medium.com/

8. wget

wget is a command-line utility for downloading files from the web.
With wget, we can download files using HTTP, HTTPS, and FTP protocols.

wget provides several options allowing us to download multiple files, resume downloads, limit the bandwidth, recursive downloads, download in the background, mirror a website, and much more.

Syntax : wget [option] [URL]

Let’s see some examples:
To simply download a webpage:
wget http://eg.com/sample.html
To download the file in the background:
wget -b http://www.eg.com/sample.html
To overwrite the log while downloading the file using the wget command:
wget http://www.eg.com/samplefile.txt -o /path/samplefile.txt
Resume a partially downloaded file:
wget -c http://example.com/samplefile.tar.gz
To try a given number of times:
wget –tries=10 http://eg.com/samplefile.tar.gz

9. whois

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

Syntax:whois <websiteName>
Example:whois google.com

10. scp

SCP (secure copy) is a command-line utility that allows us to securely copy files and directories between two locations.
With scp, we can copy a file or directory:
From our local system to a remote system.
From a remote system to our local system.

Between two remote systems from our 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 scp command.
scp [OPTION] user@src_host:file_name1 user@dest_host:file_name2
OPTION – 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.

scp provides several options that control every aspect of its behavior. The most widely used options are:

  1. -i — Identity_file
  2. Selects the file from which the identity (private key) for public-key authentication is read. This option is directly passed to ssh(1).
  3. -r – This option tells scp to copy directories recursively.

11. ssh

ssh stands for Secure Shell. It is a protocol used to securely connect to a remote server/system. ssh 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. ssh runs at TCP/IP port 22.
Syntax: ssh user_name@host(IP/Domain_name)
Example: ssh -i ~/pk.pem root@
The i flag — To use a private key for a specified hostname and not the default ssh key that is located in ~/.ssh