BreakingExpress

Diagnose connectivity points with the Linux ping command

Networked computer systems are so widespread today that the majority of us take it with no consideration that a pc on one aspect of a room can contact one on the opposite aspect of the room, a lot much less the opposite aspect of the world. When it really works as designed, networking is what makes the Internet, the cloud, file shares, media streaming, distant administration, printing, and far more potential. When one thing goes fallacious, it could possibly typically be difficult to diagnose. One of essentially the most basic diagnostic instruments for networked connectivity is the ping command.

The primary ping

When you possibly can’t attain a pc in your native community, or a server on the Internet, you possibly can ping it. A ping sends an Internet Control Message Protocol (ICMP) packet to a vacation spot IP deal with. ICMP is, by design, a rudimentary format used principally for diagnostics: It’s basically a name and response sign.

But there’s an order to troubleshooting, and it begins as near dwelling as potential. When doubtful, first ping your personal pc to make sure you’re working a networking stack. The pc you are working can be known as your localhost, and it has a particular IP deal with assigned for talking to itself: 12.0.0.1.

The ping command understands the localhost hostname, its IP deal with, and a shortcut of simply 0.

You can management what number of indicators you ship with the -c (as in depend) choice.

ping 0 -c1
PING 0 (127.0.0.1) 56(84) bytes of knowledge.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.069 ms

--- 0 ping statistics ---
1 packets transmitted, 1 obtained, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.069/0.069/0.069/0.000 ms

After you have established that your native networking stack is up and working, you possibly can ping your router. The deal with of a router often begins with 192,168, or 10. The actual IP deal with is determined by your router’s configuration.

When you do not specify what number of pings to ship, you possibly can cease ping from working with Ctrl+C.

ping 192.168.0.1 
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of knowledge.
From 192.168.0.100: icmp_seq=2 Redirect Host(New nexthop: 192.168.0.1)
From 192.168.0.100: icmp_seq=3 Redirect Host(New nexthop: 192.168.0.1)
From 192.168.0.100: icmp_seq=4 Redirect Host(New nexthop: 192.168.0.1)
From 192.168.0.100: icmp_seq=5 Redirect Host(New nexthop: 192.168.0.1)
^C

If you possibly can attain your router, meaning your wired or wi-fi connection is working. 

What about different hosts on my community? You can ping every kind of units. Not all are assured to reply (some units drop ICMP packets), however many do. For occasion, I can ping my printer:

$ ping 192.168.0.4 

Pinging past your community

Beyond establishing that your personal community is working as anticipated, you may as well ping out into the broader world past your router. Again, not all servers are permitted to obtain, a lot much less reply to, ICMP. However, there are some that do, and a significant server to the working of the Internet is a nameserver.

Google’s DNS server is comparatively simple to recollect, and it does reply to pings:

ping -c 2 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of knowledge.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=116 time=53.3 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=116 time=53.5 ms

--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 obtained, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 53.304/53.424/53.544/0.120 ms

When a website has apparently disappeared, you may be capable of probe the worldwide DNS community to search out out what its host server’s deal with is, after which ping that server. This at the least tells you whether or not the host is down or whether or not it is only a internet server concern.

For instance, say you are attempting unsuccessfully to achieve instance.com. First, discover the IP deal with utilizing the host command:

$ host instance.com
instance.com has deal with 93.184.216.34
instance.com has IPv6 deal with 2606:2800:220:1:248:1893:25c8:1946
instance.com mail is dealt with by 0

And then ping the web site’s host by IP:

$ ping 93.184.216.34 -c 1

Ping and IPv6

Ping works over IPv4 in addition to IPv6. Using solely certainly one of them explicitly might be enforced by specifying -4 or -6

Packet measurement

You can change the scale of the ICMP packets you are sending with the -s choice. The default packet measurement is 56, which interprets into 64 ICMP information bytes when mixed with the 8-byte header. This command sends 43 bytes:

$ ping -s 35 -c 5 8.8.8.8

You can print a timestamp earlier than every ping report in your terminal with the -D choice. This offers the UNIX epoch time, plus microseconds:

ping -D 8.8.8.8 
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of knowledge.
[1634013430.297468] 64 bytes from 8.8.8.8: icmp_seq=1 ttl=116 time=53.3 ms
[1634013431.298738] 64 bytes from 8.8.8.8: icmp_seq=2 ttl=116 time=53.1 ms

Ping time

You can change the time interval between pings utilizing the -i choice. This modifications the ping interval to 2 seconds:

$ ping -s 2 

You can even cease pinging after some worth of time (in seconds) with the -w choice:

$ ping -w 6

Variants

There are many implementations of ping. The iputils bundle offers a ping command, Busybox has a ping command, and there is one from BSD and others. There’s even a GUI for ping: Gping is obtainable for Linux, macOS, and Windows. You can discover extra info for gping on Github

Learn to ping

The ping command is straightforward, however it may be eyes and ears out on the huge expanse that’s your community. Next time you’ve got connectivity points, let ping be the primary device you flip to.

Exit mobile version