Bird
Raised Fist0
Linux CLIscripting~20 mins

Why network tools diagnose connectivity in Linux CLI - See It in Action

Choose your learning style10 modes available
Diagnose Network Connectivity Using Linux CLI Tools
📖 Scenario: You are a system administrator who needs to check if a computer can connect to the internet and other devices on the network. You will use simple Linux command-line tools to diagnose network connectivity step-by-step.
🎯 Goal: Build a small script that uses Linux network tools to check if the computer can reach a website and a local device, and then display the results.
📋 What You'll Learn
Create a variable with the website URL to test connectivity
Create a variable with the local device IP address to test local network connectivity
Use the ping command to check connectivity to the website
Use the ping command to check connectivity to the local device
Print the results of both connectivity tests
💡 Why This Matters
🌍 Real World
Network administrators often need to quickly check if a server or device is reachable to diagnose connectivity problems.
💼 Career
Knowing how to automate network checks with scripts saves time and helps maintain reliable network operations.
Progress0 / 4 steps
1
Set the website URL to test
Create a variable called website and set it to the string "8.8.8.8" which is a public DNS server IP to test internet connectivity.
Linux CLI
Hint

Use the syntax variable_name = "value" to create a string variable.

2
Set the local device IP to test
Create a variable called local_ip and set it to the string "192.168.1.1" which is a common local router IP address to test local network connectivity.
Linux CLI
Hint

Use the same syntax as the first step to create the local_ip variable.

3
Ping the website and local device
Use the ping command with the -c 1 option to send one ping packet to website and local_ip. Store the exit status of each ping command in variables website_status and local_status respectively. Use the syntax os.system(f"ping -c 1 {website} > /dev/null 2>&1") to run the command silently.
Linux CLI
Hint

Use os.system to run shell commands and get the exit code. Exit code 0 means success.

4
Print the connectivity results
Print two lines: one showing "Website reachable" if website_status is 0, else "Website unreachable". The second line shows "Local device reachable" if local_status is 0, else "Local device unreachable". Use print() and if statements.
Linux CLI
Hint

Use if statements to check if the status is 0 and print the correct message.

Practice

(1/5)
1. What is the main purpose of using network tools like ping and traceroute?
easy
A. To change your computer's screen resolution
B. To install new software on your computer
C. To delete files from your system
D. To check if your computer can reach another device or website

Solution

  1. Step 1: Understand what network tools do

    Network tools like ping and traceroute test connectivity between your computer and other devices or websites.
  2. Step 2: Identify the correct purpose

    They help find if a connection is working or where it might be failing, not for installing software or changing settings unrelated to networking.
  3. Final Answer:

    To check if your computer can reach another device or website -> Option D
  4. Quick Check:

    Network tools diagnose connectivity = A [OK]
Hint: Network tools test connection, not system settings [OK]
Common Mistakes:
  • Thinking network tools install software
  • Confusing network tools with system utilities
  • Assuming network tools change display settings
2. Which of the following is the correct syntax to send 4 ping requests to example.com?
easy
A. ping -c 4 example.com
B. ping example.com -count 4
C. ping /n 4 example.com
D. ping example.com -4

Solution

  1. Step 1: Recall ping command options

    The option -c specifies the count of ping requests in Linux.
  2. Step 2: Match correct syntax

    Only ping -c 4 example.com uses the correct option and order.
  3. Final Answer:

    ping -c 4 example.com -> Option A
  4. Quick Check:

    Count option for ping = -c [OK]
Hint: Use -c to set ping count in Linux [OK]
Common Mistakes:
  • Using Windows ping options on Linux
  • Placing options after the hostname incorrectly
  • Using wrong option flags like /n or -count
3. What output will you get when running ping -c 1 8.8.8.8 if the network is working?
medium
A. Request timed out.
B. Permission denied
C. 1 packets transmitted, 1 received, 0% packet loss
D. Unknown host 8.8.8.8

Solution

  1. Step 1: Understand ping output on success

    If the network works, ping shows packets sent and received with 0% loss.
  2. Step 2: Identify correct output

    1 packets transmitted, 1 received, 0% packet loss matches the success message showing 1 packet sent and received with no loss.
  3. Final Answer:

    1 packets transmitted, 1 received, 0% packet loss -> Option C
  4. Quick Check:

    Successful ping = packets received with 0% loss [OK]
Hint: Success ping shows packets received and 0% loss [OK]
Common Mistakes:
  • Confusing timeout message with success
  • Thinking unknown host means network is fine
  • Ignoring packet loss details
4. You run traceroute google.com but get the error: command not found. What is the best way to fix this?
medium
A. Install the traceroute tool using your package manager
B. Restart your computer
C. Use ping google.com instead
D. Change your DNS server settings

Solution

  1. Step 1: Understand the error meaning

    command not found means traceroute is not installed or not in PATH.
  2. Step 2: Fix by installing traceroute

    Installing traceroute with the package manager adds the command to your system.
  3. Final Answer:

    Install the traceroute tool using your package manager -> Option A
  4. Quick Check:

    Missing command = install tool [OK]
Hint: Install missing tools when command not found error appears [OK]
Common Mistakes:
  • Restarting without checking installation
  • Using ping when traceroute is needed
  • Changing DNS without cause
5. You want to check if your computer's network interface has an IP address assigned. Which command helps diagnose this?
hard
A. ping 127.0.0.1
B. ip addr show
C. nslookup google.com
D. traceroute 8.8.8.8

Solution

  1. Step 1: Understand what each command does

    ip addr show displays network interfaces and their IP addresses. ping 127.0.0.1 tests local network stack. nslookup checks DNS resolution. traceroute traces route to a host.
  2. Step 2: Identify command to check IP address

    Only ip addr show directly shows assigned IP addresses on interfaces.
  3. Final Answer:

    ip addr show -> Option B
  4. Quick Check:

    Check IP address = ip addr show [OK]
Hint: Use ip addr show to see IP addresses on interfaces [OK]
Common Mistakes:
  • Using ping to check IP assignment
  • Confusing DNS lookup with IP address check
  • Using traceroute for interface info
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard