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.

Sandclock 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, Sandclock 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

[Checkmk] Nâng cấp phiên bản checkmk trên CentOS 7

Checkmk ra đời vào năm 2015 trải qua quá trình phát triển được rất nhiều các cá nhân, tổ chức...

Pandas Data Frame Tutorial

Pandas for Numerical Analysis Pandas was developed out of the need for an efficient way to manage financial data in Python. ...

Ulauncher – Linux Desktop Application Launcher

Ulauncher is a simple desktop application for Linux that allows users to launch installed applications and open file directories...
Bài Viết

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

Hướng dẫn chuyển đổi windows server windows evaluation to standard và active windows server 2008 + 2012 + 2016 + 2019

How to Update Ubuntu Linux

Squid Proxy Manager cài đặt và quản lý Proxy Squid tự động trên ubuntu

Hướng dẫn cài đặt Apache CloudStack

Hướng dẫn ký file PDF bằng chữ ký số (chữ ký điện tử) và sửa lỗi mới nhất 2021 foxit reader