Linux Ping Command

Chưa phân loại
Ping is a diagnosing tool which allows to check the connectivity of any IP address by sending ICMP packets designed to report errors and operational information. This tool is present in all OS (Operating Systems) and it is perhaps the most basic command to interact with a network or devices through it.

Ping uses ranges from device availability check to more complex security auditing being the basis of many methods available on different security scanners such as Nmap, Angry IP Scanner, etc.

This tutorial explains briefly how this command works and how to use it applying flags to customize the “communication” between devices.

Contrary to Windows under Linux the ping is continuous (like ping -t in Windows), this tutorial will show examples for ping changing packet sizes and intervals to accelerate or slow the packets, how to add sound when replies are received,

Introduction to the Internet Protocol and ICMP ( Internet Control Message Protocol)

The following text extract belongs to the ping command man page:

“ping uses the ICMP protocol’s mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway. ECHO_REQUEST datagrams (”pings”) have an IP and ICMP header, followed by a struct timeval and then an arbitrary number of ”pad” bytes used to fill out the packet.”

What we call ping is an ECHO_REQUEST, or a ECHO_RESPONSE packet.
These are packets whose datagram contains IP and ICMP packets in the header.

The ECHO_REQUEST will seek a reply, the ECHO_RESPONSE to confirm the destination is online.

“…the protocol ICMP (Internet Control Message Protocol) also belongs to the Internet Layer to diagnose and report errors in the communication. Despite the ICMP protocol belongs to the Internet Layer the reliability of the connection relies on the third level layer, the Transport layer.” (Source

All About Linux Ping Command

A simple ping can be executed without flags defining only the target, the following example shows a ping to Google’s DNS, pinging Google DNS is one of the most popular ways to check if you have internet connection. If you can ping the IP address but you can’t ping domain names, you should probably add the “nameserver” line within your /etc/resolv.conf file.

# ping

As you can see in the output, the device pinging is receiving 64 bytes from the IP, with the sequence of ICMP packets increase, Time to Live and time to reach the destination in milliseconds (ms).

You can specify the size in bytes of the packets with the -s flag and you can also ping targets by using a domain name instead of the IP address as in the example below:

# ping -s 30

The -a flag will produce a sound (beep) when getting a reply from the destination Gigopen.

# ping -a

The option above may be  good when the host is unreachable and you want to keep it pinging until it becomes online.

The -i flag allows to set intervals in seconds, the following example shows pings each 7 seconds.

# ping -i 7

While the example above shows how to define a 7 seconds interval, you can speed up pings by running:

# ping -i 0.5

Since under Linux the ping tool runs continuously (like “ping -t” in Windows) you can specify a deadline by adding the flags -w and -W.
The following example with low case -w determines an unconditional deadline for the ping process:

# ping -w 2

The big case -W will instruct ping to timeout only if replies are not being received, then the -W instructs the time to wait for a reply, in the following example there are replies, therefore the timeout should not be functional:

# ping -W 2

As you see the operation was interrupted by a CTRL+C.

The -r flag is used to ping directly the destination without checking the routing table. The routing table is information usually saved in routing devices such as routers or gateways containing information on the path packets should follow to reach the destination. The hop-by-hop routing way gives the path to the next routing device in a manner packets always must check for the routing table on each routing device to go to the next device (or hop). Using the -r flag the packet will go directly to the specified address regardless of the routing table, if used with a device out of our network it will return error, it may work within the same network as in the examples shown below:

# ping -r

As you can see the ping against didn’t reach the destination while it worked for a local network IP  address.
Some of ping flags in Linux include:

[-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface] [-l preload] [-m mark]
[-M pmtudisc_option] [-N nodeinfo_option] [-p pattern] [-Q tclass] [-s packetsize]
 [-S sndbuf] [-t ttl] [-T timestamp_option] [-w deadline] [-W timeout].

Note: flags for other OS (Operating Systems) such as Windows variate and are not the same.

You can get more information on the ping command at the man page (

I hope you found this brief article on All About Linux Ping Command useful.

Keep following LinuxHint for additional updates and tips on Linux and Networking.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

How to install Simplenote 1.0.8 on Ubuntu, Linux Mint, CentOS, RHEL

Simplenote 1.0.8 the most recent update, is a light, clean, and free note taking application. It is now available for iOS,...

How to Install and Configure Consul Server on Ubuntu 18.04

Consul is an open source service discovery tool which is based and built on Golang. It helps you discovering services application...

Install SQLite and SQLite Browser on Ubuntu 18.04 LTS

SQLite is a lightweight database software. It is a command line application. You must use the command line or SQLite API...
Bài Viết

Bài Viết Mới Cập Nhật

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh

Mua proxy Onet uy tín tại

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1

Thuê địa chỉ IPv4 IPv6 trọn gói ở đâu chất lượng, giá RẺ nhất?