Ping is a popular command and tool used to check and test the network connectivity on computer networks. The ping command simply sends ICMP packets to the target system to get a response to their requests. When the request is replied this means there is no problem with the network connectivity problem with the target or remote system. The Mac computers or MacOS operating system provides the ping command which is used similar to the Unix, Linux ping command. The ping command is provided by default and installed with the MacOS operating system and there is no need for an extra installation process.
Open Terminal
The ping command is executed via terminal and as a first step, the terminal should be opened in order to ping the remote target system. Follow Applications->Utilities->Terminal to open terminal. You can also use alternative terminal applications which you want.
Ping Remote Target System
Now on the terminal we can run the ping command to ping remote system. The remote system can be printer, server, computer or a web site etc. We can specify the remote server as an IP address or hostname. Lets test network connectivity for the remote target system with its IP address.
$ ping 192.168.1.1
Alternatively, we can use hostnames in order to ping the remote system. But in order for to hostname to work properly, the hostname should be resolved into an IP address without a problem. In the following example, we will ping the hostname www.wisetut.com .
$ ping www.wisetut.com
The output will be like below. By default, the ping command will run forever unless it is stopped with the CTRL+c keys in MacOS. So we will stop the continuous ping with the CTRL+c keys which will print some statistics like below.
PING www.wisetut.com (172.67.71.238) 56(84) bytes of data. 64 bytes from 172.67.71.238 (172.67.71.238): icmp_seq=1 ttl=128 time=39.7 ms 64 bytes from 172.67.71.238 (172.67.71.238): icmp_seq=2 ttl=128 time=37.9 ms 64 bytes from 172.67.71.238 (172.67.71.238): icmp_seq=3 ttl=128 time=38.0 ms 64 bytes from 172.67.71.238 (172.67.71.238): icmp_seq=4 ttl=128 time=62.3 ms 64 bytes from 172.67.71.238 (172.67.71.238): icmp_seq=5 ttl=128 time=37.9 ms 64 bytes from 172.67.71.238 (172.67.71.238): icmp_seq=6 ttl=128 time=37.8 ms --- www.wisetut.com ping statistics --- 6 packets transmitted, 6 received, 0% packet loss, time 5007ms rtt min/avg/max/mdev = 37.801/42.255/62.342/9.006 ms
- 64 bytes is the size of the ICMP payload.
- icmp_seq is the sequence number of the ICMP package for this ping operation.
- ttl is the time to live parameter for the ping result.
- time is the time to reach to the target.
And the total statistics provide the following information and metrics about the ping.
- 6 packets transmitted show how many ICMP or ping packets sent to the target.
- 6 received shows how many responses received for the request.
- 0% packet loss is the percentage of lost packets or unreplied ICMP or ping packets.
- time 5007is the total time from start of the ping packet to the end.
- min is the minimum round trip time from sending the ICMP packet to get a response.
- avg is the average round trip time from sending the ICMP packet to get a response.
- max is the maximum round trip time from sending the ICMP packet to get a response.
Is The Remote Target Host Is Down?
You may ask yourself that if the remote target system or host is down. The ping command provides real-time information about ping packets and a generic information and statistics about the pings. If the remote host is unreachable or down the ping packets will not replied and see no real-time ping packet printed to the terminal. Also the statistics about the ping will be provide information like more than 0% packet loss and less received packet count then transmitted like below.
9 packets transmitted, 0 received, 100% packet loss, time 8199ms
Set Ping Count
By default, MacOSX operating system ping command runs forever. But in some cases we may need limited packet count to the remote target system. We can use the -c option in order to specify ping or ICMP packet count.
$ ping -c 10 www.wisetut.com
Specify Ping Source Network Interface/IP Address
If the MacOS has multiple network interfaces or IP addresses the ping uses the first network interface as the source by default. But we can use another network interface for the ping command. The -S
option is used to specify the source address.
$ ping -S 192.168.1.10 google.com