How to Use the Command 'nping' (with Examples)
Nping is a versatile network scanning and packet generation tool built by the creators of Nmap. This utility is particularly valuable for diagnosing network issues, benchmarking security systems, and generating traffic patterns over a network. By allowing users to send and receive packets, nping can help in analyzing packet latency, loss, and jitter, providing an insightful view into the health and performance of your network.
Use case 1: Ping a Specified Host Using ICMP (or TCP as Fallback)
Code:
nping example.com
Motivation: Often, network administrators need a simple way to check the accessibility and response times of a host. The nping command performs a basic health check by attempting to send packets to a target IP address, defaulting to ICMP if available. If not, it intelligently falls back to using TCP.
Explanation:
nping
: This is the command being used, invoking the nping tool.example.com
: This is the target host that nping attempts to reach.
Example Output:
Starting Nping 0.7.80 ( https://nmap.org/nping )
Host: 93.184.216.34
Sent 1 packet with 0 answers from, 93.184.216.34.
This output indicates that a packet was successfully sent to example.com, detailing the number of packets sent and received.
Use case 2: Ping a Specified Host Using ICMP When Privileged
Code:
nping --icmp --privileged example.com
Motivation: When administrators have elevated privileges, it is often preferable to utilize the ICMP protocol, given its lower overhead and more straightforward interpretation. Using --privileged
ensures the system permissions are correctly set to allow ICMP pinging.
Explanation:
--icmp
: Forces the use of the ICMP protocol, commonly used for ping operations.--privileged
: Indicates that nping should run with elevated permissions, required for raw socket operations with ICMP.example.com
: The host machine that is the target of the ICMP ping.
Example Output:
Starting Nping 0.7.80 ( https://nmap.org/nping )
SENT (0.0022s) ICMP [10.0.0.1 > 93.184.216.34 Echo request (type=8/code=0)
This shows the ICMP Echo Request sent, verifying the reachability of the destination host.
Use case 3: Ping a Specified Host Using UDP
Code:
nping --udp example.com
Motivation: UDP, being a connectionless protocol, offers a more lightweight alternative to TCP for certain applications. Using nping to generate UDP packets helps in testing firewall rules or verifying the function of UDP-based applications on the target host.
Explanation:
--udp
: Specifies that nping should use the UDP protocol for packet transmission.example.com
: The intended recipient of the UDP pings.
Example Output:
Starting Nping 0.7.80 ( https://nmap.org/nping )
SENT (0.0012s) UDP [10.0.0.1:31278 > 93.184.216.34:31337].
The result demonstrates nping’s successful sending of a UDP packet, verifying UDP service functionality.
Use case 4: Ping a Specified Host on a Given Port Using TCP
Code:
nping --tcp --dest-port 443 example.com
Motivation: For services hosted on specific ports, such as HTTPS on port 443, it is essential to confirm connectivity specifically at those ports. This command is useful for testing service availability by simulating TCP connections to the target port.
Explanation:
--tcp
: Instructs nping to use TCP, a reliable transmission protocol.--dest-port 443
: Specifies the port on which the target service resides, 443 is typically used for HTTPS.example.com
: The target host for the TCP probing on the specified port.
Example Output:
Starting Nping 0.7.80 ( https://nmap.org/nping )
SENT (0.0020s) TCP [10.0.0.1:48574 > 93.184.216.34:443 SYN].
This output confirms TCP connection attempts to example.com on port 443.
Use case 5: Ping a Certain Number of Times
Code:
nping --count 10 example.com
Motivation: Limiting the number of ping attempts can be crucial for assessing network reliability without overwhelming the network with traffic, which could be potentially disruptive.
Explanation:
--count 10
: This sets the number of packets nping will attempt to send to the host, helping to control the test’s duration.example.com
: The host that will receive the packets.
Example Output:
Max rtt: 0.451ms | Min rtt: 0.239ms | Avg rtt: 0.300ms
The summary of latency results provides insights into the round-trip time consistency.
Use case 6: Wait a Certain Amount of Time Between Each Ping
Code:
nping --delay 5s example.com
Motivation: By adding a delay between pings, you can simulate conditions of lower network bandwidth or decrease the burden placed on network resources. This is often useful in stress testing.
Explanation:
--delay 5s
: Imposes a five-second pause between each packet sent, slowing the pace of traffic.example.com
: Represents the address of the host to ping.
Example Output:
Sent 1 packet(s), Received 1 packet(s), in 5.001 seconds
The delay ensures traffic is spaced out, assisting in controlled testing processes.
Use case 7: Send the Request Over a Specified Interface
Code:
nping --interface eth0 example.com
Motivation: Networked devices with multiple interfaces often require testing on a specific one. Developers and network engineers use this to verify the function and efficiency of particular routes or hardware like LAN or Wi-Fi cards.
Explanation:
--interface eth0
: Designates the network interface for outgoing traffic, helpful for targeted analysis.example.com
: The intended target host, tested on the specified interface.
Example Output:
[eth0/10.0.0.1 -> example.com] SENT 1 packet(s)
Verification of a discrete path provides confidence in specific interfaces.
Use case 8: Ping an IP Range
Code:
nping 10.0.0.1-10
Motivation: Scanning an IP range allows administrators to monitor availability and latency across multiple hosts or devices, such as within a particular subnet, ensuring all required network elements are online and responsive.
Explanation:
10.0.0.1-10
: Specifies the range from 10.0.0.1 through 10.0.0.10, allowing broad-scope network health checks.
Example Output:
Host 10.0.0.2 is up
Host 10.0.0.3 is up
Host 10.0.0.5 is unresponsive
This example output shows the operational devices within the specified range, quickly identifying network issues.
Conclusion:
Through these diverse use cases, nping demonstrates its versatility and importance as a tool for network administrators and security teams. Whether it’s simple connectivity checks or complex, multi-factor network evaluations, nping provides adaptable functionality and insightful outputs necessary for maintaining and optimizing network performance.