Linux CLI network troubleshooting in one line

Filed under Development
Topics covered: , ,

Over the years I’ve seen bloated tools and bad how-tos for basic troubleshooting, probably just like you. Earlier this year I got my hands on a troubleshooting flowchart from a company I’d once worked for. It was good that they had developed a process, but I  was astounded at how drawn out it was to get the most basic information and how it missed certain key points. After receiving questions from my own team, I jotted an email to my co-workers that explained a succinct, one line networking troubleshoot for the Linux command line. It’s not meant to fix, but tell you where your problem is which is often more than half the troubleshooting battle. I think it’s decent enough that I decided to share it here, with a bit of addition.


Linux CLI network troubleshooting in one line:

ifconfig | grep "eth0"; route; ping; traceroute; curl icanhazip.com

You can run this line from the command line. It is a series of commands intended to run on linux systems. All of these should work without SUDO permissions. In linux command line the | (pipe) symbol “pipes” the output from one command to another as input. It is made on the American English keyboard by pressing shift+\ (under the backspace). In Linux command line the semicolon (;) tells the command line to run the next command after the preceding command has been run. With this line, the computer will progress through each of the commands successively.

Step 1: See if your interface works. See if you can get an IP.

ifconfig will show us our interface information and verify our interface works. Piping the output to grep and searching for the ethernet interface expedited showing us just the interface we expect to be testing. On some systems you may need to modify this to match your ethernet interface. If we are connected, this command should give us our IP.

Step 2: Verify you are on the right network. Check your gateway to identify your subnet.

route returns the default destination and the gateway. It does more than that, but that’s what we care about in this case.

Step 3: Verify basic internet access.

ICMP echo requests (pings) are basic networking checks. is an IPv4 address of a Domain Name Service (DNS) server belonging to Google. We can rely on to be up and responsive as long as we have basic internet access (provided the fact that we’re not pinging during a global thermonuclear war). This ping will verify that we have an outbound connection and can receive a response.

Step 4: Verify our connection and service provider.

traceroute will attempt to tell us all of the network “hops” between us an a given target. If we fail to get a response from, it will tell us if our issue is isolated to our intranet or the internet, identifying if this is a local or ISP related issue. This also lets us verify that our ISP is who it is supposed to be, ensuring that our connection has not been hijacked.

Step 5: Test DNS.

Curl is a command line utility that, in this case returns the URL request for a website “icanhazip.com”. Icanhazip.com simply returns the WAN side address for the device accessing the page. This line lets us evaluate DNS functionality on the router or network side. If this doesn’t evaluate, it informs us that there is a DNS error to address.