Using the Terminal for Basic Network Troubleshooting
Introduction
Network troubleshooting is a necessary and valuable capability for any IT professional from helpdesk technician to veteran network engineer. In this blog post we will take a look at some basic commands you can use from your terminal (specifically in a Windows environment). This post could get a little lengthy because I’ll be including examples, but stick with me and we’ll come out the other side just a bit more capable! Let’s dive in.
Working with MAC Addresses at the Data Link Layer
In the course of network troubleshooting, you will likely at some point need to investigate or find the MAC address of a device. This can be accomplished using these commands:
Command Prompt | PowerShell |
---|---|
arp | Get-NetNeighbor |
These commands display and modify entries in the Address Resolution Protocol (ARP) cache. This cache is used to store mappings between Layer 2 MAC addresses and Layer 3 IP addresses on a local area network (LAN). There are multiple ways these commands are useful.
Get a MAC address from a known IP address
Command Prompt:
|
|
Output:
|
|
PowerShell:
|
|
Output:
|
|
This will tell you which of your device’s network interfaces can see that IP address, and what the MAC address of the remote device’s network interface is.
Get an IP address from a known MAC address
Command Prompt:
|
|
Output:
|
|
PowerShell:
|
|
Output:
|
|
I’ve found this command particularly helpful in situations where I can’t reach a device that I believe to be connected to the network,
Working with IP Addresses at the Network Layer
Now that we know how to discover MAC addresses, which indicate a physical connection exists, let’s take a look at IP addresses.
Get your private IP address
Need to find the IP address of your own device?
Command Prompt | PowerShell |
---|---|
ipconfig | Get-NetIPConfiguration |
These commands will display your device’s IP configuration as set in your Network Adapter Settings.
Command Prompt:
|
|
Output:
|
|
PowerShell:
|
|
Output:
|
|
Note that you can get even more information, including listing all of your device’s interfaces and their MAC addresses, by instead using
ipconfig /all
orGet-NetIPConfiguration -Detailed
.
Get your public IP address
I won’t go into this here, because you can instead check out Get Your Public IP Address Using the Terminal!
Test communication to another IP address
Alright so we know how to find IP addresses and MAC addresses. But how do we check to see if two devices can communicate on the network?
Command Prompt | PowerShell |
---|---|
ping | Test-NetConnection |
These commands use Internet Control Message Protocol (ICMP) to “ping” the remote device, and see if it gets a response. This happens by opening a RAW socket to the IP layer, where the request is packaged and sent to the remote device. IF the devices can communicate via ICMP, then you will receive an ICMP Echo Reply back, which is displayed in your terminal.
Command Prompt:
|
|
Output:
|
|
PowerShell:
|
|
Output:
|
|
Working with Routing at the Network Layer
So we’ve got devices that have MAC addresses and IP addresses, but how do they get to each other for communication? This is accomplished via routes.
Get your device’s IP routes
Command Prompt:
|
|
Note: you can accomplish this with
netstat -r
as well, which produces the same output.
Output:
|
|
PowerShell:
|
|
Note:
Get-NetRoute
output can sometimes squish the last column of the returned table, so I like to pipe the output toFormat-Table -AutoSize
to rectify this. It’s not a huge deal, just a small thing.
Output:
|
|
Trace an IP route
We know what our IP address is, and the IP address of our remote device, as well as the routes available to our device. But how do we check to see if that’s actually the route our network traffic is taking? These commands assist with this.
Command Prompt | PowerShell |
---|---|
tracert | Test-NetConnection |
These utilities, similar to ping
, send out ICMP ping packets and couple the responses with the varying time-to-live (TTL) values to identify different routers long the route.
Command Prompt:
|
|
Output:
|
|
PowerShell:
|
|
Output:
|
|
This is helpful when network communication is not working as you’d expect, or if you suspect some device along the expected path might be down. Doing a traceroute can help narrow down where the problem actually exists, and what device to troubleshoot.
Working the TCP Protocol at the Transport Layer
Moving up a level in the OSI model, we can troubleshoot TCP connections.
Command Prompt | PowerShell |
---|---|
netstat | Get-NetTCPConnection , Test-NetConnection |
Get local TCP ports
You can use netstat
and Get-NetTCPConnection
to investigate what TCP ports are connected or listening on your device or a remote device. Additionally, you can test connecting to a remote device on a specific port using Test-NetConnection
.
Command Prompt:
|
|
Note:
PORT
should be replaced with the local port you’re interested in investigating.
Output:
|
|
PowerShell:
|
|
Note: Again,
PORT
should be replaced with the local port you’re interested in investigating.
Output:
|
|
This can be helpful if you believe that something should be communicating to or from your device. If you’re having an issue, this can verify whether the transport layer is functional on your device.
Get remote TCP ports
Similarly, we can get the TCP port utilization for remote hosts.
Command Prompt:
|
|
Output:
|
|
PowerShell:
|
|
Output:
|
|
This can be helpful if you believe that something should be communicating to or from your device. If you’re having an issue, this can verify whether the transport layer is functional on your device.
Test communication to another IP address on a specific TCP port
Rather than list TCP sessions, we can actually test a connection to a remote device on a specific TCP port as well. This is one of the most helpful commands if you’re troubleshooting network issues that appear to be occurring at the transport layer.
PowerShell:
|
|
Output:
|
|
Bonus Tool: ncat
Another great way to test a connection on a specific port is to use ncat
, which is a re-implementation of netcat
which was developed for Unix systems in the late 1990s. It’s packaged and provided with Nmap, which can be downloaded from their websites or installed using the Chocolatey package manager. If you have it installed, you can use it for this purpose as well:
PowerShell:
|
|
Output:
|
|
Note: Do remember that you should only install software in an enterprise environment where allowed/approved.
Working with Protocols at Presentation and Application Layers
Window provides commands for troubleshooting protocol errors at the presentation and application layers as well. For the sake of brevity, I will only cover DNS in this post. DNS is one of the most common protocols, and is important for proper network functionality. We can interact with our DNS using the terminal.
Resolve a DNS Name
Command Prompt | PowerShell |
---|---|
nslookup | Resolve-DnsName |
Command Prompt:
|
|
Output:
|
|
PowerShell:
|
|
Output:
|
|
These commands can be helpful when something works via IP address, but not DNS name. You can use these commands to find out what the DNS name you’re using is resolving to, and you might just find that it’s resolving to something other than what you’d expect.
Conclusion
WHEW. That’s a lot of information! If you stuck around until this point, I appreciate it and hope you found some useful information in this post. We’ve looked at how to use commands in Command Prompt (“Command Prompt”) and Windows PowerShell to perform basic network troubleshooting at multiple layers of the OSI/TCPIP model. By mastering these commands you can save time and hassle when dealing with network problems.