Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST TOOLS

Bash Tutorial

Bash HOME Bash Intro Bash Get Started

Basic Commands

Bash Commands Bash List (ls) Bash Change Dir (cd) Bash Print Dir (pwd) Bash Echo (echo) Bash Concatenate (cat) Bash Copy (cp) Bash Move (mv) Bash Remove (rm) Bash Timestamp (touch) Bash Make Dir (mkdir) Bash Find Files (find) Bash Manual (man) Bash Alias

Pipes and Redirection

Bash Redirection Bash Pipes (|) Bash Build Commands (xargs)

Text Processing

Bash Search Text (grep) Bash Pattern Scan (awk) Bash Stream Editor (sed) Bash Remove Section (cut) Bash Sort Lines (sort) Bash View End (tail) Bash View Start (head) Bash Count (wc) Bash Unique Lines (uniq) Bash Translate (tr) Bash Compare Files (diff)

System Monitoring

Bash Process Status (ps) Bash List Processes (top) Bash Disk Space (df) Bash Directory Usage (du) Bash Memory Usage (free) Bash Terminate (kill) Bash Uptime

Networking

Bash Ping Bash URL Transfer (curl) Bash Downloader (wget) Bash Remote Connect (ssh) Bash Secure Copy (scp) Bash File Sync (rsync)

File Compression

Bash Compress (zip) Bash Extract (unzip) Bash TAR Archive

File Permissions

Bash Ownership Bash Modify (chmod) Bash Ownership (chown) Bash Group (chgrp)

Scripting

Bash Syntax Bash Script Bash Variables Bash Data Types Bash Operators Bash If...Else Bash Case Bash Loops Bash Functions Bash Script Arguments Bash Read Input (read) Bash Exit Codes Bash Arrays Bash Strings Bash Here Documents Bash Trap Signals (trap) Bash Schedule (cron)

Bash Cert

Bash Certificate

Bash Reference

Bash Glossary

Exercises and Quiz

Bash Compiler Bash Exercises Bash Challenges Bash Quiz

Bash ping Command - Send Request to Network Hosts


Share

Using the ping Command

The ping command is used to send ICMP ECHO_REQUEST to network hosts.

It's a useful tool for checking network connectivity and diagnosing network issues.


Basic Usage

To ping a host, use ping hostname:

Example

ping google.com
PING google.com (172.217.14.206) 56(84) bytes of data.
64 bytes from 172.217.14.206: icmp_seq=1 ttl=118 time=14.5 ms
64 bytes from 172.217.14.206: icmp_seq=2 ttl=118 time=14.2 ms
64 bytes from 172.217.14.206: icmp_seq=3 ttl=118 time=14.3 ms
64 bytes from 172.217.14.206: icmp_seq=4 ttl=118 time=14.4 ms
^C
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 14.200/14.350/14.500/0.112 ms

On Linux, ping keeps sending packets until you press Ctrl+C. Then it prints the statistics.


Options

The ping command has options to change how it works:

  • -c - Send a specific number of ping requests
  • -i - Wait a specific number of seconds between sending each packet
  • -t - Set the IP Time to Live (TTL)
  • -q - Quiet output, only show summary
  • -s - Specify the number of data bytes to be sent


Send a Specific Number of Ping Requests

The -c option allows you to send a specific number of ping requests.

This is useful for limiting the number of packets sent.

Example: Send a Specific Number of Ping Requests

ping -c 4 google.com
PING google.com (172.217.14.206) 56(84) bytes of data.
64 bytes from 172.217.14.206: icmp_seq=1 ttl=118 time=14.5 ms
64 bytes from 172.217.14.206: icmp_seq=2 ttl=118 time=14.2 ms
64 bytes from 172.217.14.206: icmp_seq=3 ttl=118 time=14.3 ms
64 bytes from 172.217.14.206: icmp_seq=4 ttl=118 time=14.4 ms

--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 14.200/14.350/14.500/0.112 ms

Understanding Ping Results

The output of the ping command provides several key pieces of information:

  • Bytes: The size of the ICMP packet sent
  • Time: The round-trip time it took for the packet to reach the host and return, measured in milliseconds
  • TTL (Time to Live): The remaining lifespan of the packet, which decreases by one for each hop
  • Packet Loss: The percentage of packets that were lost during transmission
  • Round-Trip Time Statistics: Includes minimum, average, maximum, and mean deviation (mdev) of the round-trip times

In the example above:

  • Each packet is 64 bytes
  • The round-trip times vary slightly, indicating network latency
  • The TTL value is 118, showing the packet's remaining lifespan
  • There is 0% packet loss, indicating a stable connection
  • The round-trip time statistics provide insights into network performance

Wait a Specific Number of Seconds Between Sending Each Packet

The -i option allows you to wait a specific number of seconds between sending each packet.

This can be useful for reducing network traffic when using ping.

Example: Wait a Specific Number of Seconds Between Sending Each Packet

ping -c 2 -i 2 google.com
PING google.com (172.217.14.206) 56(84) bytes of data.
64 bytes from 172.217.14.206: icmp_seq=1 ttl=118 time=14.5 ms
64 bytes from 172.217.14.206: icmp_seq=2 ttl=118 time=14.2 ms

--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 14.200/14.350/14.500/0.150 ms

Set the IP Time to Live (TTL)

The -t option allows you to set the IP Time to Live (TTL).

This determines the maximum number of hops a packet can take before being discarded.

The TTL you set applies to the packets you send. The ttl= value in each reply is set by the remote host, so it does not change.

Example: Set the IP Time to Live (TTL)

ping -c 1 -t 64 google.com
PING google.com (172.217.14.206) 56(84) bytes of data.
64 bytes from 172.217.14.206: icmp_seq=1 ttl=118 time=14.5 ms

--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 14.500/14.500/14.500/0.000 ms

Quiet Output

The -q option enables quiet output, only showing the summary of the ping results.

This is useful for scripts or when you only need the final statistics.

Example: Quiet Output

ping -c 4 -q google.com
PING google.com (172.217.14.206) 56(84) bytes of data.

--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 14.200/14.350/14.500/0.112 ms

Specify Data Bytes

The -s option allows you to specify the number of data bytes to be sent.

This can be useful for testing network performance with different packet sizes.

Example: Specify Data Bytes

ping -c 1 -s 128 google.com
PING google.com (172.217.14.206) 128(156) bytes of data.
136 bytes from 172.217.14.206: icmp_seq=1 ttl=118 time=14.5 ms

--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 14.500/14.500/14.500/0.000 ms


Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.