Ubuntu: How to Ping a Remote Server/IP Address

Updated: January 28, 2024 By: Guest Contributor Post a comment

Introduction

Pinging is a fundamental network command used to test the reachability of a host on an Internet Protocol (IP) network and measure the round-trip time for messages sent from the originating host to a destination computer. In this tutorial, we are going to discuss how to ping a remote server or IP address using the Ubuntu operating system. We’ll cover basic ping usage, custom options for more advanced pinging, interpreting the ping output and troubleshooting some common network issues using ping.

Prerequisites

Before you begin, make sure you have a terminal window open on your Ubuntu system. You can open the terminal by searching for it in the applications menu or by using the shortcut Ctrl + Alt + T.

Basic Ping Usage

The simplest form of the ping command is by following the syntax: ping [options] destination. Below are examples to get you started:

Example 1: Pinging by IP Address

$ ping 192.168.1.1

This command will ping the device with the IP address 192.168.1.1 and display the results.

Example 2: Pinging by Hostname

$ ping hostname.com

Similarly, you can ping by hostname which will resolve to an IP and perform the ping to that IP.

Advanced Ping Commands

The ping command has several options that can be used to customize its behavior. Here are several common ones:

Example 3: Specifying the Number of Packets

$ ping -c 5 192.168.1.1

Using the -c option, you can specify the number of packets to be sent. The example above sends five ICMP packets to the target IP.

Example 4: Setting the Time To Live (TTL)

$ ping -t 45 hostname.com

The -t option sets the TTL value. This example sends ICMP packets with a TTL of 45.

Example 5: Pinging Flood

$ sudo ping -f 192.168.1.1

Using the -f option with ping sends packets as fast as possible, typically used for stress testing. This command requires administrative privileges, hence the use of sudo.

Example 6: Specifying Packet Size

$ ping -s 100 hostname.com

The -s option allows you to specify the size of packets to send. The example sends packets that are 100 bytes in size.

Example 7: Pinging with a Deadline

$ ping -w 10 192.168.1.1

The -w option specifies a deadline, in seconds, before ping exits regardless of how many packets have been sent or received. Here, ping will stop after 10 seconds.

Example 8: Interval Between Sending Packets

$ ping -i 3 hostname.com

This sets an interval of 3 seconds between sending each packet. By default, the interval is 1 second.

Interpreting the Ping Results

When you issue a ping command, it returns information with each echo reply. Here’s an example of what a typical ping result looks like:

PING hostname.com (93.184.216.34): 56 data bytes
64 bytes from 93.184.216.34: icmp_seq=0 ttl=57 time=11.632 ms
64 bytes from 93.184.216.34: icmp_seq=1 ttl=57 time=10.689 ms
64 bytes from 93.184.216.34: icmp_seq=2 ttl=57 time=9.674 ms

--- hostname.com ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 9.674/10.665/11.632/0.804 ms

The above results indicate the number of bytes received in response to each ICMP packet, the sequence number of the packet, the TTL value, and the time it took for the round-trip. In the summary, it shows the total packets transmitted and received, packet loss percentage, the total time of the operation, and a summary of round-trip times as minimum, average, maximum, and standard deviation.

Troubleshooting with Ping

Here are common issues that you might face, and how to troubleshoot them with ping:

Example 9: Request Timed Out

Request timed out.

This indicates that there was no response received within the expected timeframe. This might be due to the host being down, packet filtering, or network congestion.

Example 10: Destination Host Unreachable

Destination Host Unreachable

This message generally means that the router can’t forward your packet to the host. Possible causes might be routing issues or that the host does not exist.

Example 11: Time To Live Exceeded

Time To Live Exceeded

If you receive this message, it usually means that the packet has traversed too many routers, and each hop decrements the TTL value by one until it hits zero, which causes the router to discard the packet. This often indicates a routing loop.

Conclusion

Ping is a very useful and uncomplicated tool. With a better understanding of the command and its output, you will be well equipped to diagnose and resolve basic network connectivity issues.