Computers are connected in a network to sources or more computer-connected through network media known as a computer 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 lo
and eth0
lo
and eth0
is 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
Ubuntu
By default in Ubuntu, it is not installed. For Installing:
sudo apt install net-tools
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
Ubuntu
By default in Ubuntu, it is not installed. In order to install:
sudo apt install ifupdown
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
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.
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
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
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
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
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
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
ethtool
It is used to print the information of the interface.
Amazon Linux / Ubuntu
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
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
ip
It provides the source, IP, link of the server.
Amazon Linux / Ubuntu
ss
It provides socket stats and displays various information based on various protocols.
Amazon Linux / Ubuntu
tracepath
It is an upgraded version of the traceroute.
Amazon Linux / Ubuntu
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
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
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
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