Ping is one of the most popular tools for troubleshooting, testing, and diagnosing network connectivity issues.
Ping sends one or more packages that create an echo effect on the network, in order to determine the location of the target. When you try to ping a remote host, your machine starts sending out ICMP echo requests and waits for a response. If the connection is established, you’ll receive an echo reply for every request.
Ping can help you determine whether a remote destination is active or inactive, check the round-trip delay, and see if there is packet loss.
ping is part of the iputils (or iputils-ping) package, which is pre-installed on almost all major Linux distributions. It is also available to install on Windows, macOS, and FreeBSD.
UDP Ping in Linux
By default, ping only sends ICMP packets, which is an internet layer protocol . That also means you cannot ping a specific port, since ports belong to the transport layer protocols like TCP and UDP.
In order to send a TCP or UDP packet and achieve a "ping" effect, you can use netcat, nmap or telnet. UDP ping is pretty useful when you want to check if SNMP is running or not.
When we talk about "ping" in this article, we mean that you want to verify a specific port of a given IP address or hostname.
UDP ping with nmap
In the example below, we will use nmap to scan port 161 UDP of the host at address example.com. Simply run nmap
with sU
(scan UDP) flag, followed by -p 161
option on the address and you will see something like this.
sudo nmap -sU -p 161 example.com
Starting Nmap 7.80 ( https://nmap.org ) at 2022-02-17 11:01 SAST
Nmap scan report for udp-ping.example.com (1.2.3.4)
Host is up (0.025s latency).
PORT STATE SERVICE
161/udp open|filtered snmp
As we can see, port 161 UDP is open, running SNMP and the port is filtered.
UDP scan works by sending a UDP packet to targeted port. For closed ports, this packet will be empty (no payload), but for any open one, a protocol-specific payload will be sent. Based on the response, or lack thereof, the port is assigned to one of four states : open, open|filtered, closed and filtered.
UDP ping with netcat
Netcat is a powerful program that supports a wide range of commands to manage networks and monitor the flow of traffic data between systems.
Netcat should be available on almost any modern distro and provides versatile options for networking. While Ubuntu ships with the BSD variant of netcat, other distros may have different versions that could offer different options for users.
If you see "nc: command not found" error, run the following commands to install netcat on your system.
Ubuntu/Debian or Debian-based distro:
sudo apt install netcat
CentOS/Red Hat based systems:
sudo dnf install nc
# OR
sudo dnf install netcat
Netcat provides its functions through nc
command. Below is an example where we use nc
command to test if port 161 UDP is listening or not. You may want to get the full debug output by using the v
switch.
nc -v -u -z example.com 161
Connection to example.com 161 port [udp/snmp] succeeded!
As you can see from the output above, netcat recognizes that port 161 often used by SNMP and the UDP scan succeeded.
We hope that the information above helped you learn how to do an UDP ping in Linux.
You may be interested in our Linux software roundups, including 8 Best Open Source CMDB software, Best Linux Video Converters or Best Python Graphics Libraries. If you have any suggestion, please feel free to leave a comment below.