Essential Linux networking commands including hostname, ip, ping, curl, and wget for examining network configuration, testing connectivity, and retrieving data from URLs.
This document explores essential Linux networking commands for system administration and troubleshooting. It covers retrieving hostname information, examining network interface configurations, testing connectivity with ping, and retrieving data from web sources using curl and wget. These commands provide the foundation for diagnosing network issues and managing network interactions in Linux environments.
Linux provides several commands for examining and configuring network settings, enabling users to identify their system on the network and understand network interface details.
The hostname command displays or sets the system’s hostname, which uniquely identifies the computer on a network. Its basic syntax is:
1hostname [options]
When executed without options, it displays the current hostname:
1$ hostname
2mylinuxmachine.local
The .local suffix appears when the machine has a local domain set.
Several options can modify the output:
1$ hostname -s # Short hostname (without domain)
2mylinuxmachine
3
4$ hostname -i # IP address of the hostname
5192.168.1.10
The hostname command is particularly useful for:
The ip command is a powerful utility for displaying and configuring network interfaces. It provides comprehensive information about the network stack.
To view all network interfaces and their details:
1ip a # Short for "ip address show"
This displays complete information about all network interfaces, including:
To display details for a specific network interface:
1ip address show eth0
This command provides detailed information about the eth0 interface, including:
| Information | Description |
|---|---|
| IP Address | The assigned IPv4/IPv6 addresses |
| MAC Address | The hardware address of the interface |
| MTU | Maximum Transmission Unit size |
| Interface State | Whether the interface is UP or DOWN |
| TX/RX Statistics | Transmission and reception statistics |
The ip command has largely replaced older networking commands like ifconfig in modern Linux distributions due to its more comprehensive feature set.
Once network configuration is established, testing connectivity to remote hosts is essential for network troubleshooting.
The ping command tests connectivity to a host or IP address by sending ICMP (Internet Control Message Protocol) echo request packets and listening for echo replies. Its basic syntax is:
1ping [options] destination
For example:
1$ ping google.com
2PING google.com (142.251.41.68) 56(84) bytes of data.
364 bytes from mia07s33-in-f4.1e100.net (142.251.41.68): icmp_seq=1 ttl=55 time=29.4 ms
464 bytes from mia07s33-in-f4.1e100.net (142.251.41.68): icmp_seq=2 ttl=55 time=28.6 ms
564 bytes from mia07s33-in-f4.1e100.net (142.251.41.68): icmp_seq=3 ttl=55 time=30.1 ms
6^C
7--- google.com ping statistics ---
83 packets transmitted, 3 received, 0% packet loss, time 2003ms
9rtt min/avg/max/mdev = 28.642/29.394/30.141/0.612 ms
By default, ping continues until interrupted with Ctrl+C.
Each ping response provides:
After termination, ping provides summary statistics:
To send a specific number of ping requests, use the -c option:
1ping -c 5 google.com
This command sends exactly 5 ping requests and then exits automatically.
Other useful ping options include:
-i: Specify the interval between packets-s: Set the packet size-t: Set the Time To Live (TTL) value-W: Timeout for responsesLinux provides powerful tools for retrieving data from web sources, which are essential for downloading files, API interactions, and web scraping.
The curl command is a versatile tool for transferring data to and from servers using various protocols (HTTP, HTTPS, FTP, etc.). Its basic syntax is:
1curl [options] [URL]
To retrieve a web page:
1$ curl www.google.com
2<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en">...
This outputs the raw HTML content of the Google homepage.
To save the retrieved content to a file:
1curl -o google.txt www.google.com
The -o option specifies the output filename.
| Option | Description | Example |
|---|---|---|
-s | Silent mode (no progress meter) | curl -s example.com |
-I | Fetch headers only | curl -I example.com |
-L | Follow redirects | curl -L example.com |
-X | Specify HTTP method | curl -X POST example.com |
-d | Send POST data | curl -d "name=value" example.com |
The wget command is specialized for downloading files from the web. While similar to curl, it has features specifically designed for file retrieval. Its basic syntax is:
1wget [options] [URL]
For example:
1$ wget https://www.w3.org/TR/PNG/iso_8859-1.txt
2--2025-07-03 14:30:12-- https://www.w3.org/TR/PNG/iso_8859-1.txt
3Resolving www.w3.org (www.w3.org)... 104.18.25.119, 104.18.24.119
4Connecting to www.w3.org (www.w3.org)|104.18.25.119|:443... connected.
5HTTP request sent, awaiting response... 200 OK
6Length: 10880 (11K) [text/plain]
7Saving to: 'iso_8859-1.txt'
8
9iso_8859-1.txt 100%[===================>] 10.62K --.-KB/s in 0.001s
10
112025-07-03 14:30:12 (14.8 MB/s) - 'iso_8859-1.txt' saved [10880/10880]
By default, wget saves the downloaded file with its original filename in the current directory.
| Option | Description | Example |
|---|---|---|
-O | Specify output filename | wget -O output.txt example.com |
-r | Recursive download | wget -r example.com |
-c | Resume broken download | wget -c example.com/large-file.zip |
-b | Background download | wget -b example.com/large-file.zip |
--limit-rate | Limit download speed | wget --limit-rate=200k example.com/file.zip |
To examine a downloaded file:
1$ head -12 iso_8859-1.txt
2The ISO 8859-1 Character Set
3
4ISO 8859-1 (or Latin-1) is the first part of ISO 8859, a series
5of 16 standardized character encodings, each representing 256
6characters. ISO 8859-1 contains the ASCII character set plus a
7series of accented characters and other symbols commonly used in
8Western European languages.
9
10The following table shows ISO 8859-1. Each character is shown with
11its position in the set, its approximate description, the HTML4
12entity name which will produce it, and its Unicode (ISO 10646)
Networking commands form the foundation of Linux system administration and network troubleshooting. The hostname and ip commands provide essential information about the system’s network identity and interface configurations. The ping command offers a straightforward way to test connectivity to remote hosts and assess network stability. For retrieving data from web sources, curl provides a versatile tool for interacting with web services, while wget specializes in efficient file downloads. These commands, when used together, provide a comprehensive toolkit for diagnosing network issues, monitoring network performance, and automating network-related tasks in Linux environments.
(2) wget automatically saves files to disk, while curl displays content to standard output by default. This reflects their different design philosophies and intended use cases. wget is focused on file retrieval and downloading (writing to disk automatically), while curl is designed as a more general data transfer tool that outputs to the terminal by default unless redirected. Both tools support multiple protocols and file types, but they differ in their default behaviors and specialized features.
(1) The command will send 3 ping requests with 2 seconds interval between them. The -c 3 option limits the ping to 3 packets (count), and the -i 2 option sets the interval between consecutive packets to 2 seconds (instead of the default 1 second). After sending 3 packets and receiving responses (or timeouts), the command will complete and display summary statistics.
ping webserver.example.com to verify basic network connectivity to the server, and then use curl -o webpage.html webserver.example.com to download the main page to a local file for inspection. This approach first confirms that the server is reachable at the network level before attempting to interact with its web service. If the ping is successful but curl fails, this would indicate that the server is online but the web service might be down or misconfigured.(3) It is incorrect that the ip command can only show information but cannot modify network configurations. In fact, the ip command is a powerful utility that can both display AND modify network configurations. It can be used to add/remove IP addresses, change interface states (up/down), modify routing tables, and configure many other network parameters. This capability makes it a comprehensive tool for network administration in Linux.
The ping command can only test connectivity to IP addresses and cannot work with domain names.
False. The ping command can work with both IP addresses and domain names. When a domain name is provided (e.g., ping google.com), ping first resolves the domain name to an IP address using DNS, then sends ICMP echo requests to that IP address. This dual capability makes ping versatile for testing connectivity regardless of whether you know the specific IP address or just the domain name of the target host.
| Command | Function |
|---|---|
| A. hostname | 1. Tests connectivity to a remote host |
| B. ip | 2. Downloads files from the web |
| C. ping | 3. Displays or sets system identification |
| D. curl | 4. Transfers data to/from URLs |
| E. wget | 5. Configures network interfaces |
A-3, B-5, C-1, D-4, E-2. The hostname command displays or sets system identification, ip configures network interfaces, ping tests connectivity to a remote host, curl transfers data to/from URLs, and wget downloads files from the web.
(3) The stability and reliability of the network connection can most likely be inferred from packet loss statistics in ping results. High packet loss (packets sent but not received back) generally indicates network congestion, unreliable links, or hardware issues along the path. A stable connection typically shows 0% packet loss, while increasing percentages of loss suggest progressively more unstable connections. This makes packet loss a valuable metric for assessing network reliability.
ping domain.example to see if a domain resolves to an IP address. For more detailed DNS information, they would use the dig domain.example or nslookup domain.example commands, which show the complete DNS resolution process and returned records. To test a specific DNS server, they could use dig @dns-server-ip domain.example. These tools help verify that domain names are resolving to the expected IP addresses and that the DNS infrastructure is functioning properly.