The UNIX ping command lets you test network servers and latency. Here’s how to use it in the macOS Terminal app.
The UNIX ping
command is a tiny UNIX network tool that allows you to test your network, that of your ISP or organization, remote servers, and network latency.
ping
is one of the oldest and simplest UNIX commands and is available in virtually all UNIX distributions, including macOS.
ping
was written by the late Mike Muuss in 1983 at the US Army Defense Ballistics Lab. Sadly, Muuss died young in 2000 at the age of 42, in a car accident on Interstate 95 in Maryland.
Muuss was also the author of several 3D/CAD apps at the time, as well as the UNIX utility ttcp
which measures network throughput using TCP and UDP protocols. Muuss’ original technical web page is still available on one of the first fifty servers on the internet: a US Army FTP server for the Ballistics Lab.
The ping
command works by using the Internet Control Message Protocol (ICMP) – in particular by sending ECHO_REQUEST
packets, and by utilizing its Time To Live (TTL), latency, and packet loss detection to measure round trip hops to a given internet-connected computer at either an IP address or domain name.
Don’t confuse Time To Live with a different subject from electronics: Transistor-to-transistor Logic (also abbreviated ‘TTL’).
The name “ping” comes from submarine SONAR technology which detects underwater vessels by emitting sound waves, and then measuring the time it takes for echoes to return.
With ping
you can detect if your network is working, hops in between your computer and the destination, round-trip times, and whether a given computer is online or not.
You can also use ping
to look for general network and packet errors.
Using ping on macOS
To use ping
on macOS, open the Terminal application in your Startup Disk’s /Applications/Utilities folder, then type the ping
command followed by a space, then an IP address or domain name. Press Return on your keyboard to start the command.
For example, you can ping
Apple itself in Terminal with:
ping
apple.com and pressing Return.
If your computer has a working internet connection you’ll see ping
begin its tests, which will keep running until you stop it by pressing Command-Z on your keyboard (unless you specified the -c
(count) option with the command).
When you use ping
, you can specify either the IP address of the target computer or a domain name. If you use a domain, ping
will use DNS to resolve the domain name to that domain’s default server (or to a gateway or CDN that points to the default server).
There is also an IPv6-enabled version of ping
called ping6
which is also available on macOS.
Options
ping
has several dozen options. To see them type:
man ping
in Terminal and press Return.
Options include (but are not limited to):
- Audible bell (for failures)
- Test count
- Wait times
- Type of network service
- TTL
- A source address
- Packet size
- Packet flooding
- Recording of routes
- Remote netmask printing
- Bypass routing tables
- Quiet or verbose mode (for error messages)
- SO_DEBUG flag (for recording)
Apple also provides a few more options found only in the macOS version of ping
including:
- Network interface to bind
Prohibiting cellular interfaces
Receive timestamp
See the man
page in Terminal for full options.
You can also ping your own computer’s network interface to see if the device is working properly or not.
If any duplicate or damaged packets are detected, ping
will display those too.
Default ping
results displayed in Terminal for each test show:
- Bytes received
IP of responder
TTL
Round trip time (in ms)
Packet sequence number
If you didn’t specify the number of tests to run using the -c
flag, press Command-Z on your keyboard to end the tests.
ping
is a quick and easy way to conduct network tests on your own network, your Mac, and on remote machines. Once you know how it works, you’ll find yourself using it all the time.