Top 20 Network Troubleshooting Commands for Linux | 2021

Linux Networking Commands 1

Computers are connected in a network to sources or more computer-connected through network media known ascomputer network. There are a wide variety of network devices that can connect devices to each other. PC loaded with Linux running machine can also be a part of the community whether it is a small or massive network by its multitasking and multiuser natures. Maintaining the device and keeping the network up is a challenge of the system/network Administrator’s activity. In this blog, we’re going to overview regularly used network troubleshooting commands.

ifconfig

This command shows all available interfaces. If nothing is connected then basically two interfaces are available loand eth0

loand eth0is present in the folder /etc/sysconfig/network-scripts

If you want to display a particular interface then you can run ifconfig <interface>

SYNTAX : ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]

Amazon Linux

network troubleshooting commands

Ubuntu

By default in Ubuntu, it is not installed. For Installing:

sudo apt install net-tools

network troubleshooting commands

ifup/ifdown

It brings the interface up or down based on the command. In order to use this command, you need root privilege.

These commands are present in /usr/sbin. If you are using this in some cloud provider then don’t use ifdown eth0. It will disconnect you from that instance.

If you want to up or down the interface then ifup <interface> or ifdown<interface>

Amazon Linux

network troubleshooting commands

Ubuntu

By default in Ubuntu, it is not installed. In order to install:

sudo apt install ifupdown

network troubleshooting commands

ping

It is used to check connectivity between two systems whether two systems are reachable or not.

In order to use this command ping -c <number of packet to sent> IP

SYNTAX: ping [-a] [-c count] [-i interval] [-I interface]

Amazon Linux / Ubuntu

network troubleshooting commands

traceroute

It says what are particular routes or gateway or networks are taken in order to reach a particular network.

SYNTAX : traceroute [ -46dFITnreAUDV ] [ -f first_ttl ] [ -g gate,... ] [ -i device ] [ -m max_ttl ] [ -N squeries ] [ -p port ] [ -t tos ] [ -l flow_label ] [ -w waittime ] [ -q nqueries ] [ -s src_addr ] [ -z sendwait ] [ --fwmark=num ] host [ packetlen ]

Amazon Linux /Ubuntu

Below I have run traceroute on infohubblog.com and it requires a total of 28 hops. The number of hops keeps changing.

network troubleshooting commands

netstat

It tells all the open ports, routes, gateway on the current server

SYNTAX: netstat { [-vWeenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]

In order to check the open port.

netstat -nltp

In order to check routes and gateway.

netstat -r

Amazon Linux / Ubuntu

network troubleshooting commands

dig

It is used to check details such as the IP, CNAME, QUERY TIME, Name Server of a particular domain.

SYNTAX: dig [@global-server] [domain] [q-type] [q-class] {q-opt}  {global-d-opt} host [@local-server] {local-d-opt} [ host [@local-server] {local-d-opt} [...]]

In order to use this command dig <domain name>

Amazon Linux / Ubuntu

network troubleshooting commands

nslookup

It is used to find the detail of the domain such as canonical name, IP.

In order to use this command nslookup <domain>

Amazon Linux / Ubuntu

network troubleshooting commands

route

It prints the same information as netstat -r. But simply route print gateway name and in order to figure out the IP address of gateway then route -n

SYNTAX: route [-nNvee] [-FC] [<AF>]

Amazon Linux / Ubuntu

network troubleshooting commands

host

It is used to check all associated IP addresses with the domain.

SYNTAX: host [-aCdilrTvVw] [-c class] [-N ndots] [-t type] [-W time]

Amazon Linux / Ubuntu

network troubleshooting commands

We can even figure type of record associated with domain.In order to figure out CNAME using host -t CNAME <domain> or MX Record host -t MX <domain>

arp

In order to find hardware information such as Mac Address, Interface etc then you can use arp command. arp stands form Address resolution Protocol.

SYNTAX: arp [-vn]  [<HW>] [-i <if>] [-a] [<hostname>]

Amazon Linux / Ubuntu

network troubleshooting commands

ethtool

It is used to print the information of the interface.

Amazon Linux / Ubuntu

Screenshot 2021 08 19 at 7.51.01 AM

hostname

In order to find hostname then you can simply run hostname command and in order to find IP address then run hostname -I

Amazon Linux / Ubuntu

network troubleshooting commands

nmap

It is by default not installed. You need to install it separately. From the local machine, you can check the IP address of the remote machine that what ports are open, what is the operating system running.

Amazon Linux

yum install nmap -y

Ubuntu

apt-get install nmap

network troubleshooting commands

ip

It provides the source, IP, link of the server.

Amazon Linux / Ubuntu

network troubleshooting commands

ss

It provides socket stats and displays various information based on various protocols.

Amazon Linux / Ubuntu

network troubleshooting commands

tracepath

It is an upgraded version of the traceroute.

Amazon Linux / Ubuntu

network troubleshooting commands

iperf

It is not installed by default. You need to install it separately.

SYNTAX: iperf [-s|-c host] [options]

Amazon Linux

sudo amazon-linux-extras install epel && yum -y install iperf

Ubuntu

apt-get install iperf

network troubleshooting commands

tcpdump

Whatever traffic we are receiving we will get that information from tcpdump. You can even find it on an individual port or interface.

SYNTAX: tcpdump [-a] [ -B size ] [ -c count ]

Amazon Linux / Ubuntu

network troubleshooting commands

telnet

This command is not installed in Amazon Linux by default i. You need to install it separately. It is used to check connectivity with other servers using IP and Port.

SYNTAX: telnet [-4] [-6] [-8] [-E] [-L] [-S tos] [-a] [-c] [-d] [-e char] [-l user]

Amazon Linux

yum install telnet

network troubleshooting commands

For more related to Linux Command do check out Linux Terminal Command Blog

For Reference :

https://ubuntu.com/tutorials/command-line-for-beginners#1-overview

 

Leave a comment

Your email address will not be published.


*