| technology | networking - Erik Mikac
5 Network Diagnostic Commands Every Linux Admin Should Know
Linux distribution systems are considered the gold standard in regard to networking. Mainly because they come with a vast array of network diagnostic tools. For times when turning it off and on again don't suffice, here are five network diagnostic tools that can assist in networking. The five tools we will focus on are Ping, NSLookup, NetStat, Dig, and Host.
Before delving into the different tools, it's important to know that these tools are by and large for the Linux OS. For those who do not have access to a Linux environment, let's review how to access some of these tools from Windows and Mac. While it is great to access these diagnostic tools from Windows or Mac, it is highly recommended to use the real deal. The commands used on other operating systems may be the same, but will operate differently. Using a Linux distribution will best prepare you for CompTIA's Linux+ test and real-world applications.
How do I get to the Terminal on Mac?
The Mac terminal is a program that provides a low-level interface to your macOS operating system. It is known as a command-line interface, and will allow you to run most of the tools listed below. There are a couple of ways to get to the terminal. The first way is to press ⌘ + space. This will bring up the spotlight bar. Then simply type terminal and hit Return.
Another way is to find it in the Launchpad. The Launchpad defaults onto the Mac Dock on the bottom (or side) of the screen. It can be searched for there and launched. Next let's take a looks at how to access some of these commands on Windows.
How do I Access PowerShell in Windows?
PowerShell is a versatile command-line interface that gives users greater power over their Windows operating system. A few of the commands we will be looking at can be executed on PowerShell. Download instructions can be found here on Microsoft's website. The installation process is similar for any other executable, so if you have ever downloaded anything on Windows this should be familiar. Once PowerShell is downloaded, it should be searchable on the Run search bar. Double click the executable and you're in!
Now that we have an adequate environment for each operating system, let's start digging into the tools themselves. The compatible operating systems will be listed just below each header. For the remainder of this post, it will assume you have a Linux operating system.
Ping is a tool used to determine whether or not a server is available. Think of a submarine using sonar to ping an object far away. The submarine can verify its existence by detecting sound waves bouncing from the object back to the boat. For example, open up the command prompt and type ping -c 4 www.google.com. This will ping the Google server four times.
Alternatively, you can just type ping www.google.com. This will work on PowerShell and default to pinging four times. However, on Linux and MacOS, the user will have to cancel the ping by typing cmd+c on Mac or ctrl+c on Windows keyboard.
It is obvious we will get a response back from Google. The real reason to use ping is if you were getting some sort of HTTP error from the server such as a 500. This tool could be used to verify that the server is up and running. Here is an example of a server that is not responding to a Ping.
Last login: Sun Apr 18 08:39:28 on ttys000
PING 184.108.40.206 (220.127.116.11): 56 data bytes
Request timeout for icmp_seq @
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
Request timeout for icmp_seq 4
— 18.104.22.168 ping statistics —
6 packets transmitted, 9 packets received, 100.0% packet loss
Often one web address will have multiple IP addresses attached to it. For example www.google.com may have several. That is because IP addresses are often assigned dynamically, while the actual name of the website remains the same.
NSLookup assists the user in discovering which IP address a domain name resolve to. It is best used in the three following situations:
- Troubleshooting DNS resolution issues. I.E, your web address is going to the wrong IP or cannot be resolved.
- Using the IP address to discover a domain name, or vice versa.
- Discovering mail servers for a domain.
NSLookup can be used in two modes: interactive mode and non-interactive mode. To access interactive mode, just type nslookup into the CLI and a command prompt will appear. For non-interactive mode simply type nslookup <domain> and it will provide the IP address.
So far, we have looked at Ping and NSLookup — both are related to diagnosing issues on remote machines. However, what if there is a problem on the very machine we are operating on? That is when netstat comes into play.
NetStat displays which ports are active on your machine, their status, and what they're connected to. Often netstat will be used when troubleshooting firewall issues.
Netstat comes with several useful options. For instance, if you only want to look at TCP ports, at -t to the end of the netstat command. This narrow down all of the ports to the ones that are (probably) the most important.
PowerShell: Not Available
Dig stands for Domain Information Groper. As the name suggests, it is a tool to gather information about a particular domain. Similarly to NSLookup, Dig is used to troubleshoot DNS issues. Dig is not only good for troubleshooting, but for learning more about a particular server in general. Here is an example using the dig command on www.cbtnuggets.com, and then a breakdown of what the eight sections mean.
; <<>> DIG 9.10.6 <<>> cbtnuggets.com
;; global options: +cmd
;; Got answer: