Linux Basics: Network Management

A Brief Explanation of Several Confusing Points for Beginners

  1. <span>ip</span> Command: How to Use It?

  • It is the modern replacement for <span>ifconfig</span>. Think of it as a network toolbox where you just need to specify the object (address, network interface, route, etc.) and the action to perform.
  • <span>ip addr</span> (or <span>ip a</span>): Manage IP addresses.
  • <span>ip link</span>: Manage network interface devices (e.g., enable/disable).
  • <span>ip route</span> (or <span>ip r</span>): Manage routing rules (determining how packets should travel).
  • <span>wget</span> vs. <span>curl</span>: Which One to Use?

    • In summary: <span>wget</span> is a dedicated “download expert” that defaults to downloading files; while <span>curl</span> is a versatile “Swiss Army knife” that defaults to outputting to the screen.
    • Use <span>wget</span>: When you need to download files simply and directly, especially for recursive downloads of entire websites or resuming interrupted downloads.
    • Use <span>curl</span>: When you need to test APIs, send custom requests (like POST, PUT), or automate network transfers in scripts.
  • <span>ping</span>, <span>telnet</span>, <span>traceroute</span>, <span>mtr</span>: How to Diagnose Networks? – Think of Them as Different Stages of “Package Tracking”

    • They help you answer various questions from “Is it reachable?” to “Where is it unreachable?”:
    • <span>ping</span>: Asking “Can the package arrive?” – It only cares if the destination is reachable, used to test basic network connectivity.
    • <span>telnet [domain/IP] [port]</span>: Asking “Is there someone in that room at the delivery address?” – Used to test if a specific port on the target server is open, commonly used to check if a service is listening properly.
    • <span>traceroute</span>: Getting a “static delivery route map” – It answers “What transit stations did my package go through to get to you?” by listing every hop (router) the packet passes through.
    • <span>mtr</span>: Viewing a “dynamic real-time traffic report” – It combines <span>ping</span> and <span>traceroute</span>, continuously monitoring the quality of each hop to the target, telling you “Which transit station is congested (latency) or lost (packet loss)?” It is extremely powerful for troubleshooting complex network issues.
  • How to Differentiate So Many Monitoring Tools?

    • They answer different questions, helping you locate issues from different dimensions:
    • <span>ss</span> (replacement for <span>netstat</span><span>): Answers "</span><strong><span>What current network connections and listening ports are there?</span></strong><span>" (view global status)</span>
    • <span>lsof -i</span>: Answers “Which program is using a specific port/connection?” (find program from connection)
    • <span>iftop</span>: Answers “What is the real-time traffic on the network interface? Who is communicating with whom?” (view traffic sources)
    • <span>nethogs</span>: Answers “Which program is hogging my bandwidth?” (view traffic from the program perspective)

    Command Quick Reference Table

    Function Category Command Main Use Most Common Usage
    Network User View <span>w</span> Displays detailed information about currently logged-in users. <span>w</span>
    <span>whoami</span> Displays the username of the current operation. <span>whoami</span>
    Network Configuration and Testing <span>ip</span> Unified network configuration tool. <span>ip a</span> (check IP)<span>ip r</span> (check route)
    <span>ping</span> Tests network connectivity. <span>ping www.baidu.com</span>
    <span>nslookup</span> / <span>dig</span> Queries domain DNS information. <span>nslookup www.baidu.com</span><span>dig www.baidu.com</span>
    <span>telnet</span> Tests connectivity to a specific port on a remote host. <span>telnet www.baidu.com 80</span>
    <span>traceroute</span> Tracks the routing path taken by packets to reach the target. <span>traceroute www.baidu.com</span>
    <span>mtr</span> Dynamic diagnosis of network path quality (ping + traceroute). <span>mtr www.baidu.com</span>
    Network File Transfer <span>wget</span> Dedicated downloader, suitable for downloading large files. <span>wget -c [URL]</span> (resume download)
    <span>curl</span> Swiss Army knife for data transfer, commonly used for API testing. <span>curl -I [URL]</span> (view response headers)
    Network Monitoring and Statistics <span>ss</span> View socket connections, modern replacement for <span>netstat</span><span>.</span> <span>ss -tulnp</span>
    <span>lsof</span> View which process is using a specific port. <span>sudo lsof -i :80</span>
    <span>iftop</span> Real-time monitoring of network interface bandwidth. <span>sudo iftop</span>
    <span>nethogs</span> Monitor network traffic by process. <span>sudo nethogs</span>
    Firewall Management <span>ufw</span> Simple firewall configuration tool. <span>sudo ufw status</span><span>sudo ufw allow ssh</span><span>sudo ufw enable</span>

    Leave a Comment