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.
Please note that this command will run indefinitely. To stop pinging, on Mac type Command + C and on Windows type Ctrl + C.
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.
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
Here is a video demonstration of the ping command.