0
0
Linux CLIscripting~20 mins

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

Choose your learning style9 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
Need a 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
Need a 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
Need a 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
Need a hint?

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