Linux Networking Commands
# CHAPTER 10
Linux Networking Commands
1. Introduction
A Linux server operating in isolation is a useless metal box. The entire purpose of a server is to communicate—to serve web pages, route database queries, and establish secure tunnels across the globe. When a user submits an IT ticket stating, "The web application is down," the problem could be a broken physical cable, a misconfigured firewall, or a crashed DNS server. To diagnose the fault, you cannot rely on visual network maps; you must probe the digital ether using the command line. In this chapter, we will master the essential Linux networking toolkit. We will test connectivity withping, interact with web APIs using curl, download files via wget, verify open ports, and establish remote control using the omnipresent ssh protocol.
2. Learning Objectives
By the end of this chapter, you will be able to:-
Verify local IP configurations using the modern
ip acommand.
-
Test Layer 3 network connectivity and latency using
ping.
-
Isolate path routing failures using
traceroute.
-
Interact with web servers and APIs directly from the terminal using
curl.
-
Download files from the internet without a browser using
wget.
-
Identify listening services and open ports using
netstatorss.
-
Securely log into remote servers using
ssh.
3. Checking Your Own Network (ip)
Before blaming the internet, you must check your own machine. Does your Linux server even have an IP address?
Historically, administrators used the ifconfig command. Today, this is deprecated. The modern standard is the ip command.
Look for the interface named eth0 or enp3s0. Below it, you will see your inet (IPv4 address), proving you are connected to the local network.
4. Testing Connectivity (ping and traceroute)
1. The Ping Command:
ping sends a tiny ICMP radar pulse to a destination to see if it is alive.
*Note for Windows users:* In Windows, a ping stops after 4 tries. In Linux, a ping will run *forever* until you press Ctrl + C to stop it.
-
*Pro-tip:* If
ping 8.8.8.8succeeds, butping google.comsays "Temporary failure in name resolution," your internet works, but your DNS is broken!
2. The Traceroute Command:
If a ping fails, you need to know exactly which router dropped the packet. traceroute lists every physical "hop" your packet takes across the global internet.
5. Interacting with the Web (curl and wget)
A headless Linux server does not have Google Chrome. How do you test a website or download a file?
1. Testing Web Servers (curl):
curl is a magic wand for interacting with HTTP. If you type curl example.com, the terminal will print the raw HTML code of the website directly onto your screen. It proves the web server is answering requests.
2. Downloading Files (wget):
If you need to download a software installation package from the internet, you use wget.
6. Checking Open Ports (netstat / ss)
If you start a web server, how do you mathematically prove it is actually listening for traffic on Port 80?
You use Socket Statistics (ss) or the legacy netstat command.
If you do not see Port 80 in the output, your web server has crashed, and no firewall rule in the world will fix it.
7. Remote Control (ssh)
You will rarely sit physically in a freezing datacenter plugging a keyboard into a server rack. You will manage servers from your couch over the internet using Secure Shell (SSH).
SSH creates an encrypted, cryptographic tunnel to the remote server.
*Syntax:* ssh [Username]@[IP Address]
The terminal will ask for a password. Once authenticated, your local terminal prompt will vanish, replaced by the terminal prompt of the remote server. You are now commanding the server from afar!
8. Diagrams/Visual Suggestions
*Visual Concept: The SSH Tunnel* Draw a laptop on the left (Local Machine) and a Server Rack on the right. Draw an open padlock icon. Show a command likerm -rf traveling across the internet in plaintext.
Below it, draw a solid, blue pipe connecting the laptop to the server. Label it SSH Port 22. Draw a closed padlock. Show the command rm -rf being transformed into x8f!L9 (encrypted gibberish) inside the pipe, mathematically protecting the command line interface from eavesdroppers.
9. Best Practices
-
Never expose SSH to the public internet on Port 22: Automated hacker bots constantly scan the entire global internet looking for open Port 22s. They will attempt to brute-force guess your root password 50,000 times a second. Always alter your SSH configuration (
/etc/ssh/sshd_config) to listen on a random, high port (like Port 2222) to hide from automated attacks.
10. Common Mistakes
-
Forgetting the protocol in
wget: Beginners often typewget www.google.com. The command fails.wgetis a strict utility; you must provide the absolute Uniform Resource Locator (URL), including the protocol. You must typewget https://www.google.com.
11. Mini Project: The Network Diagnostic Flow
Simulate a troubleshooting scenario:-
1.
Confirm you have an IP: Type
ip a.
-
2.
Ensure you can reach the internet: Type
ping -c 4 8.8.8.8(The-c 4tells Linux to only send 4 pings, just like Windows).
-
3.
Ensure DNS is working: Type
ping -c 4 google.com.
-
4.
Test HTTP application delivery: Type
curl -I https://google.com(The-Iflag asks for the HTTP Headers. You should see a "200 OK" response).
12. Practice Exercises
-
1.
Contrast the operational use cases of
curlandwget. While both interact with web servers, in what specific scenario iswgetthe superior tool?
-
2.
Explain the forensic value of the
ss -tulpn(ornetstat -tulpn) command for a security administrator suspecting a malware infection.
13. MCQs with Answers
A system administrator needs to download a .tar.gz installation package directly from a software vendor's website to a remote, headless Linux server. Which command line utility accomplishes this?
Which command is used to securely log into the command line interface of a remote Linux server across the internet using encrypted cryptographic keys?
14. Interview Questions
- Q: A developer complains that their newly deployed Python web application is not reachable over the network. Walk me through the exact CLI commands you would use on the server itself to verify (A) the server has an IP, and (B) the Python app is actively listening on TCP Port 8080.
-
Q: Explain why the legacy
telnetprotocol was entirely abandoned by the IT industry in favor of thesshprotocol for remote server administration.
-
Q: You attempt to
pinga corporate database server and receive 100% packet loss. However, you are still able to successfullysshinto the exact same database server. Explain the network security architecture that causes this behavior.
15. FAQs
Q: I rancurl and my screen filled with a million lines of unreadable code. How do I stop it?
A: You likely curled a massive web page or a binary file. Remember your escape hatch! Press Ctrl + C instantly to terminate the running curl process and regain control of your terminal prompt.
16. Summary
In Chapter 10, we expanded our reach beyond the local filesystem into the global network. We verified our local Layer 3 configuration usingip a and diagnosed routing pathways using the classic ping and traceroute sonars. We bridged the gap to the Application Layer, replacing the GUI web browser with the precision of curl for API interactions and wget for direct file downloads. We deployed ss to audit our server's listening ports, acting as an internal security check. Finally, we wielded ssh, the undisputed king of remote management, proving that physical proximity to a server is entirely irrelevant to a modern engineer.