Browse Courses

Networking Commands

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.

Examining Network Configuration

Linux provides several commands for examining and configuring network settings, enabling users to identify their system on the network and understand network interface details.

Using the hostname Command

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.

Hostname Command Options

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:

  • Identifying the current machine in a network
  • Verifying DNS resolution
  • Basic network configuration validation

Network Interface Information with ip

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:

  • Interface names (e.g., eth0, lo, wlan0)
  • MAC addresses
  • IP addresses (IPv4 and IPv6)
  • Interface state (UP/DOWN)
  • Network masks and broadcast addresses

Examining Specific Interfaces

To display details for a specific network interface:

1ip address show eth0

This command provides detailed information about the eth0 interface, including:

InformationDescription
IP AddressThe assigned IPv4/IPv6 addresses
MAC AddressThe hardware address of the interface
MTUMaximum Transmission Unit size
Interface StateWhether the interface is UP or DOWN
TX/RX StatisticsTransmission 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.


Testing Network Connectivity

Once network configuration is established, testing connectivity to remote hosts is essential for network troubleshooting.

Using the ping Command

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.

Ping Output Information

Each ping response provides:

  • Domain name resolution to IP address
  • Size of the packet being sent
  • Sequence number of each packet
  • Round-trip time (RTT) in milliseconds

After termination, ping provides summary statistics:

  • Packets transmitted and received
  • Packet loss percentage
  • Round-trip time statistics (minimum, average, maximum, and standard deviation)

Limiting Ping Requests

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 responses

Retrieving Data from URLs

Linux provides powerful tools for retrieving data from web sources, which are essential for downloading files, API interactions, and web scraping.

Using the curl Command

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.

Saving Output to a File

To save the retrieved content to a file:

1curl -o google.txt www.google.com

The -o option specifies the output filename.

Other Useful curl Options

OptionDescriptionExample
-sSilent mode (no progress meter)curl -s example.com
-IFetch headers onlycurl -I example.com
-LFollow redirectscurl -L example.com
-XSpecify HTTP methodcurl -X POST example.com
-dSend POST datacurl -d "name=value" example.com

Using the wget Command

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.

Key Features of wget

  • Recursive downloading: Can download entire websites
  • Background operation: Can continue downloads in the background
  • Resume capability: Can resume interrupted downloads
  • Bandwidth limiting: Can throttle download speeds

Common wget Options

OptionDescriptionExample
-OSpecify output filenamewget -O output.txt example.com
-rRecursive downloadwget -r example.com
-cResume broken downloadwget -c example.com/large-file.zip
-bBackground downloadwget -b example.com/large-file.zip
--limit-rateLimit download speedwget --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)

Conclusion

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.


FAQs

The primary purpose of the hostname command in Linux is to display or set the system’s hostname, which is the unique identifier for the computer on a network. When executed without options, it shows the current hostname of the machine. The hostname is a critical component of network configuration as it allows systems to identify each other on a network and is used in various network services, including DNS resolution, email delivery, and network applications.

  1. curl can only download web pages, while wget can download any file type
  2. wget automatically saves files to disk, while curl displays content to standard output by default
  3. curl supports more protocols than wget
  4. wget can only be used for HTTP requests, while curl supports multiple protocols
(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
  2. The command will ping example.com continuously for 3 minutes with 2 millisecond intervals
  3. The command will attempt to establish 3 different connections to example.com using port 2
  4. The command will send ICMP packets of size 2 bytes, repeating 3 times
(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.

The most appropriate sequence would be to first use 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.

  1. It can display detailed information about network interfaces
  2. It has largely replaced the ifconfig command in modern Linux distributions
  3. It can only show information but cannot modify network configurations
  4. It can display both IPv4 and IPv6 address information
(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.

CommandFunction
A. hostname1. Tests connectivity to a remote host
B. ip2. Downloads files from the web
C. ping3. Displays or sets system identification
D. curl4. Transfers data to/from URLs
E. wget5. 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.

  1. The physical distance between the local and remote systems
  2. The operating system running on the remote server
  3. The stability and reliability of the network connection
  4. The security level of the firewall on the remote system
(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.

A Linux system administrator would typically use a combination of commands to verify DNS resolution. They could start with 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.

The round-trip time (RTT) values displayed in ping results indicate the total time it takes for a packet to travel from the source to the destination and back. Lower RTT values suggest a faster network connection, while higher values indicate latency. The minimum, average, maximum, and standard deviation statistics provide insight into connection stability - a low standard deviation means consistent performance, while high variation suggests an unstable connection. RTT values are critical for assessing network quality, especially for applications sensitive to latency such as online gaming, video conferencing, or financial trading systems.