How to test your network or server using ping in Terminal

Jump to First Reply
Posted:
in macOS

The UNIX ping command lets you test network servers and latency. Here's how to use it in the macOS Terminal app.

A black square button with a white command prompt icon, featuring a greater-than symbol and underscore, overlaying gray text background.
Terminal for macOS



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).

In Terminal you can test remote servers and connection times using ping.
Using ping to test apple.com.



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):

  1. Audible bell (for failures)

  2. Test count

  3. Wait times

  4. Type of network service

  5. TTL

  6. A source address

  7. Packet size

  8. Packet flooding

  9. Recording of routes

  10. Remote netmask printing

  11. Bypass routing tables

  12. Quiet or verbose mode (for error messages)

  13. 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.




Read on AppleInsider

Comments

  • Reply 1 of 8
    mfrydmfryd Posts: 249member
    If you didn't specify the number of tests to run using the -c flag, press Control-C on your keyboard to end the tests.

    dewmeAlex1Nappleinsideruser
     2Likes 0Dislikes 1Informative
  • Reply 2 of 8
    DAalsethdaalseth Posts: 3,282member
    I use ping quite a bit, whenever the network seems funky. You also can ping IP addresses directly or a URL, which is nice. My standard form is to ping the border router at the University I used to work at, it’s across the continent and I know the address by heart even after all these years. Then ping a standard URL, google, apple, my local ISP, CNN, someone like that. If those look OK then I’ll ping the service I’m having trouble with, like the remote system I log into. It’s not uncommon that I’ll have tech support on the line, and they’re saying to restart my router or it’s a local problem with my ISP. Then I’ll send them screenshots of my pings showing everything is good locally, and nationwide and the slowdown starts at their border. I get put on hold, they come back and say try it again and it’s fine. 
    Alex1Nappleinsideruser
     2Likes 0Dislikes 0Informatives
  • Reply 3 of 8
    dewmedewme Posts: 6,002member
    The Net Analyzer app for iOS and iPadOS includes the Ping feature among other useful network probing utilities like Port scanner and Whois. It also has a WiFi network scanner that supports IPV4 and IPV6, speed tester, etc. Nice little utility, especially for folks who are less Unix command line aware. But yeah, the Terminal has always been something that I’ve depended on.
    edited December 2024
     0Likes 0Dislikes 0Informatives
  • Reply 4 of 8
    Muuss… my hero (RIP). Ping plus traceroute were *NIX network diagnostic apps I relied on to find network faults. I would run ping in parallel on multiple windows with each ping targeted at a different traceroute host on the way to a target. This would pinpoint a connection fault even if the fault was intermittent. More recently poor WiFi locations could be diagnosed by walking around while pinging (menu-bar WiFi strength meters have been made useless long ago, but ping packet throughput measure is instant). Then along came “mtr” https://www.tecmint.com/mtr-a-network-diagnostic-tool-for-linux/ (works on most *NIX). When run as super-user, mtr combines ping with traceroute and does the job all in one terminal window.

    Mtr source: https://github.com/traviscross/mtr
    edited December 2024
    DAalsethAlex1Nappleinsideruser
     2Likes 0Dislikes 1Informative
  • Reply 5 of 8
    softeky said:
    Muuss… my hero (RIP). Ping plus traceroute were *NIX network diagnostic apps I relied on to find network faults. I would run ping in parallel on multiple windows with each ping targeted at a different traceroute host on the way to a target. This would pinpoint a connection fault even if the fault was intermittent. More recently poor WiFi locations could be diagnosed by walking around while pinging (menu-bar WiFi strength meters have been made useless long ago, but ping packet throughput measure is instant). Then along came “mtr” https://www.tecmint.com/mtr-a-network-diagnostic-tool-for-linux/ (works on most *NIX). When run as super-user, mtr combines ping with traceroute and does the job all in one terminal window.

    Mtr source: https://github.com/traviscross/mtr
    Yeah, plus 1 for mtr. Great for identifying a dodgy hop on a route to a server. Often an overloaded private peer, perhaps from an ISP to a major service. 
     0Likes 0Dislikes 0Informatives
  • Reply 6 of 8
    Remember, Ping may be QoS'd to a lower priority and may not indicate true network latency. Something like traceroute is better as it takes an average of each hop. Even still - there are many things that cause latency in app/web page performance. This is only a small part of the puzzle.
     0Likes 0Dislikes 0Informatives
  • Reply 7 of 8

    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.
    mfryd said:
    If you didn't specify the number of tests to run using the -c flag, press Control-C on your keyboard to end the tests.


    Command-z?!?  I know it is equivalent to Control-C, but the typical macOS cancel chord works too Command-.
    edited January 2
     0Likes 0Dislikes 0Informatives
  • Reply 8 of 8
    Command-z  is the shortcut for Undo, it is usually meaningless in Terminal.
    Control-z suspends (pauses, not stops) the current process. Use jobs to see suspended processes and fg to continue it in the foreground (or bg to resume it in the background). 
    Command-. is equivalent to Control-c but nothing to do with Command-z.
     0Likes 0Dislikes 0Informatives
Sign In or Register to comment.