How To Use The ping Command (in Windows, Mac, and Linux)

Ping command tutorial for Windows, Mac, and Linux

Hey there! Some links on this page may be affiliate links which means that, if you choose to make a purchase, I may earn a small commission at no extra cost to you. I greatly appreciate your support!

In this tutorial, you will not only learn how to use the ping command to get the IP address of a website or server, but also some other cool tips and tricks that you can do with ping. This tutorial will work for Windows, Mac, and Unix operating systems.

  • Windows: open Command Prompt
  • Mac and Linux: open Terminal

Below are a handful of different examples of the ping command. Regardless of what operating system you use, all ping commands and arguments should be the same.

1. Basic ping Command

Let’s do a simple ping to the Google domain name to find the IP address.

ping google.com

Please note that this command will run indefinitely. To stop pinging, on Mac type Command + C and on Windows type Ctrl + C.

Example of ping command with IP address

2. Ping an IP Address

You can also ping an IP address to test internet connectivity. A useful tip is to ping a well-known DNS server.

ping 8.8.8.8

3. Ping at an Interval

By default, ping executes every 1 second. You can specify an interval to ping at with the -i flag.

ping -i 5 google.com
ping -i 0.1 google.com

4. Ping Your localhost

Sometimes it can be useful to ping your own local host. You can do this by name or IP address.

ping localhost
ping 127.0.0.1

5. Stop Pinging After a Count

By default, ping will execute indefinitely until you interrupt it. To stop pinging after a certain number of times, you can use the -c flag. The following will ping for a count of 3 then stop.

ping -c 3 google.com

6. Ping with an Audible Beep

The -a flag will will play an audible sound when the ping command executes.

ping -a google.com

7. Change Ping Packet Size

The default ping packet size is 64 bytes. This includes an 8 byte header. You can specify the packet size with the -s flag. The following will create a packet of size 108 bytes which includes the header.

ping -s 100 localhost

8. Ping IPv4

Some implementations of ping allow you to explicitly use the IPv4 protocol. This allows you to get back an IPv4 address with ping.

ping -4 google.com
ping4 google.com

9. Ping IPv6

Some implementations of ping allow you to explicitly use the IPv6 protocol. This allows you to get back an IPv6 address with ping.

ping -6 google.com
ping6 google.com

Here is a video demonstration of the ping command.

YouTube video

Facebook
Twitter
Pinterest
LinkedIn
Reddit

Meet Tony

Tony from Tony Teaches Tech headshot

With a strong software engineering background, Tony is determined to demystify the web. Discover why Tony quit his job to pursue this mission. You can join the Tony Teaches Tech community here.

Leave a Reply

Your email address will not be published. Required fields are marked *