Introduction
Network connectivity is a fundamental aspect of any modern computing system. When issues arise, knowing how to diagnose them is a critical skill for any developer or system administrator. This lab will guide you through a series of essential Linux commands to test and troubleshoot network connections systematically.
You will learn how to use ping to check basic reachability, traceroute to map the path your data takes across the network, nslookup to verify DNS resolution, and ip route to inspect your system's routing table. By the end of this lab, you will have a solid foundation for diagnosing common network problems.
Ping Localhost with ping 127.0.0.1 Command
In this step, you will use the ping command to test the network stack on your local machine. This is the most basic and essential first step in any network troubleshooting process.
The ping command sends ICMP (Internet Control Message Protocol) ECHO_REQUEST packets to a target host and waits for an ECHO_RESPONSE. The address 127.0.0.1 is the standard "localhost" or "loopback" address, which always points to the machine you are on. A successful ping to localhost confirms that your system's networking software is running correctly.
We will use the -c 4 option to send only 4 packets, preventing the command from running indefinitely.
Execute the following command in your terminal:
ping -c 4 127.0.0.1
You should see an output similar to the following, indicating that the packets were sent and received successfully.
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.045 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.049 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.048 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.047 ms
--- 127.0.0.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3074ms
rtt min/avg/max/mdev = 0.045/0.047/0.049/0.001 ms
The 0% packet loss line confirms that the local network interface is working correctly.
Ping Gateway with ping 172.60.0.1 Command
In this step, you will test connectivity to your local network's gateway. The gateway is a router that connects your local network to other networks, including the internet. Pinging the gateway successfully confirms that your machine can communicate with your local network.
First, you need to find the IP address of your default gateway. You can do this using the ip route command and filtering for the "default" route.
Run this command to find your gateway:
ip route | grep default
The output will show you the default route. The IP address immediately following via is your gateway's address. In this lab environment, it is typically 172.60.0.1.
default via 172.60.0.1 dev eth1
Now, use the ping command to test connectivity to this gateway address. Remember to use the -c 4 option.
ping -c 4 172.60.0.1
A successful output will look like this:
PING 172.60.0.1 (172.60.0.1) 56(84) bytes of data.
64 bytes from 172.60.0.1: icmp_seq=1 ttl=64 time=0.075 ms
64 bytes from 172.60.0.1: icmp_seq=2 ttl=64 time=0.051 ms
64 bytes from 172.60.0.1: icmp_seq=3 ttl=64 time=0.052 ms
64 bytes from 172.60.0.1: icmp_seq=4 ttl=64 time=0.053 ms
--- 172.60.0.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3060ms
rtt min/avg/max/mdev = 0.051/0.057/0.075/0.010 ms
This result confirms your machine can communicate with the local network gateway.
Trace Route with traceroute google.com Command
In this step, you will use traceroute to trace the network path from your machine to an external destination, like google.com. This command is useful for identifying where a connection might be failing along its path.
The traceroute command may not be installed by default. First, update your package list and then install it. It's good practice to run sudo apt-get update before installing new packages.
sudo apt-get update
Now, install the traceroute utility. The -y flag automatically answers "yes" to any prompts.
sudo apt-get install -y traceroute
Once the installation is complete, you can run traceroute to google.com. This will show you the sequence of routers (hops) that packets pass through to reach the destination.
traceroute google.com
The output will list each hop, its IP address, and the round-trip time for packets to reach it. The output will vary, but it will look something like this (we've truncated it for brevity):
traceroute to google.com (142.250.191.46), 30 hops max, 60 byte packets
1 uswest5 (172.60.0.1) 0.031 ms 0.010 ms 0.010 ms
2 10.220.8.54 (10.220.8.54) 0.289 ms 10.220.8.38 (10.220.8.38) 0.275 ms 10.220.8.54 (10.220.8.54) 0.263 ms
3 11.73.4.217 (11.73.4.217) 2.134 ms 11.73.4.241 (11.73.4.241) 2.141 ms 11.73.4.185 (11.73.4.185) 1.409 ms
...
8 142.251.65.127 (142.251.65.127) 4.316 ms 2.849 ms 4.335 ms
9 nuq04s42-in-f14.1e100.net (142.250.191.46) 4.296 ms 1.556 ms 2.964 ms
Each line represents a router on the path. Asterisks * * * indicate that the router did not respond to the probe in time.
Check DNS Resolution with nslookup google.com Command
In this step, you'll check Domain Name System (DNS) resolution. DNS is the internet's phonebook; it translates human-readable domain names (like google.com) into machine-readable IP addresses (like 142.250.199.14). If DNS isn't working, you won't be able to reach websites by their name, even if your network connection is otherwise fine.
The nslookup command is a tool used to query DNS servers to get this information.
Run the following command to look up the IP address for google.com:
nslookup google.com
The output shows you which DNS server answered your request and the IP addresses associated with the domain name.
Server: 127.0.0.11
Address: 127.0.0.11#53
Non-authoritative answer:
Name: google.com
Address: 142.250.191.46
Name: google.com
Address: 2607:f8b0:4005:80f::200e
The Server and Address lines show the DNS resolver your system is using. The Non-authoritative answer section provides the IPv4 (Address: 142.250.191.46) and IPv6 (Address: 2607:...) addresses for google.com. A successful response like this confirms that DNS resolution is working correctly.
Resolve Connectivity Issues with ip route show
In this step, you will examine the kernel's IP routing table. The routing table is a set of rules that your system uses to determine where to send network traffic. An incorrect or missing route is a common cause of connectivity problems.
The ip route show command (or its shorter alias ip r) displays the main routing table. This is one of the most important commands for diagnosing network issues at a low level.
Execute the command to view your routing table:
ip route show
The output will list all the routes your system knows about.
default via 172.60.0.1 dev eth1
172.60.0.0/16 dev eth1 proto kernel scope link src 172.60.1.160
The most critical line is the default route.
default via 172.60.0.1 dev eth1: This line means that for any destination not explicitly listed in the table, traffic will be sent to the gateway at172.60.0.1(which you pinged in Step 2) through the network interfaceeth1.
If this default route were missing, your system would not know how to send traffic to the internet, and commands like ping google.com would fail with a "Network is unreachable" error. Understanding this table is key to resolving such issues, often by adding a correct default route using a command like sudo ip route add default via <gateway_ip>.
Summary
Congratulations on completing this lab! You have learned a systematic approach to testing and diagnosing network connectivity issues on a Linux system.
You practiced using the following essential commands:
ping: To test reachability to the local machine and the network gateway.ip route: To find your default gateway and inspect the system's routing table.traceroute: To trace the path packets take to a remote host, identifying potential points of failure.nslookup: To verify that the Domain Name System (DNS) is correctly resolving hostnames to IP addresses.
This logical progression—from self, to local network, to the internet, and finally checking name resolution—provides a powerful framework for troubleshooting nearly any network problem you might encounter.



