fbpx Ping Command in Linux: Test Network Connection with ICMP | Certificação Linux

Ping Command in Linux: Test Network Connectivity and Latency

📅 01/01/2019 ⏱ 2 min ✍️ Uira Ribeiro
Linuxcommands
Ping Command in Linux: Test Network Connectivity and Latency
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

The ping and ping6 command in Linux uses the ICMP protocol to send ECHO REQUEST messages and receive ECHO RESPONSE to test the connection between the system and another machine on the network.

It returns the response time that a network packet takes to go and return. Very useful for diagnosing a connection. The ping will test indefinitely until Ctrl-c is pressed.

Ping also has a version for IPv6, called ping6. Its operation is similar to the IPv4 ping.

The most frequent options are:

  • -c num: This option makes the ping test the connection a specific number of times.
  • -q: This option makes ping only show the final connection test statistics.

Example:

$ ping 192.168.1.1PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.175 ms64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.120 ms64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.115 ms— 192.168.1.1 ping statistics —5 packets transmitted, 5 received, 0% packet loss, time 4000msrtt min/avg/max/mdev = 0.115/0.128/0.175/0.026 ms

Ping is widely used to test if a machine is connected to the local network or if it is reachable on the remote network. For ping to work correctly, the network in question must not have any ICMP filter, especially the ECHO REQUEST and ECHO RESPONSE types.

The ping command can indicate the following possible network problems:

Name Resolution Problem:

If when executing ping on a given host using a network name (host.certificacaolinux.com.br) the ping takes a long time to respond, and cannot resolve the name to IP, it means:

  • The DNS server may be wrong (check the /etc/resolv.conf file);
  • The DNS server cannot be accessed (ping using the DNS server IP);
  • There is a UDP port 53 filter between the computer and the DNS server (check the iptables);

Connectivity Problem:

If when executing ping, a given host does not respond, it may mean:

  • The destination host is down;
  • There is no route between the computer network and the destination host (check the routing table);
  • The default gateway is wrong (check the routing table);
  • The Network Address Translation has a forwarding or address translation problem (check the firewall);
  • There is an ICMP ECHO and ECHO-REPLY filter on the network;

Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.

Liked it? Share it

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp