Page 1 of 1

Create Check to Ping Remote Server from Host

Posted: Thu Jul 23, 2026 5:57 am
by stu18
Hello,

Wondering if you guys can help. I'm trying to create a check for hosts to be able to ping remote hosts, in the same way as pinging directly from the host itself via ping command.

For example:

localhost1 ---> 192.168.1.2
localhost1 ---> 192.167.1.3

localhost2 ---> 192.168.1.2
localhost2 ---> 192.167.1.3

I've tried using check_icmp but getting the following error message:
check_icmp: Cannot bind to IP address xxx.xxx.xxx.xxx: Cannot assign requested address

Any ideas?

Re: Create Check to Ping Remote Server from Host

Posted: Thu Jul 23, 2026 10:38 pm
by kg2857
Can you ping the hosts?

Re: Create Check to Ping Remote Server from Host

Posted: Fri Jul 24, 2026 8:47 am
by stu18
Directly from the host via SSH or KVM? Yes.

Re: Create Check to Ping Remote Server from Host

Posted: Fri Jul 24, 2026 8:49 am
by stu18
I've asked ChatGTP and it has given me these solutions:

Option 1: Use NRPE (most common)

If you want Nagios to verify that Host A can reach Host B (rather than the Nagios server reaching Host B), you can:

Install the NRPE agent on Host A.
Create a custom command on Host A that runs check_ping against Host B.

For example, on Host A:

/usr/lib/nagios/plugins/check_ping -H 10.10.20.5 -w 100.0,20% -c 500.0,60%

In nrpe.cfg:

command[check_remote_ping]=/usr/lib/nagios/plugins/check_ping -H 10.10.20.5 -w 100.0,20% -c 500.0,60%

Then on the Nagios server:

define command {
command_name check_nrpe_remote_ping
command_line $USER1$/check_nrpe -H <HostA_IP> -c check_remote_ping
}

Create a service:

define service {
use generic-service
host_name HostA
service_description Ping HostB from HostA
check_command check_nrpe_remote_ping
}

This causes the ping to originate from Host A.

Option 2: Use SSH-based checks

If you don't want NRPE, you can execute the ping over SSH.

Example command definition:

define command {
command_name check_ping_via_ssh
command_line $USER1$/check_by_ssh -H $HOSTADDRESS$ -C "/usr/lib/nagios/plugins/check_ping -H 10.10.20.5 -w 100.0,20% -c 500.0,60%"
}

This requires passwordless SSH from the Nagios server to Host A.

Option 3: Use NCPA

If you're using the NCPA agent instead of NRPE, you can execute a custom plugin or script on Host A that performs the ping and returns Nagios-compatible output.

Option 4: Custom script

Create a script on Host A that pings Host B and exits with Nagios return codes.

Example:

#!/bin/bash

TARGET=10.10.20.5

if ping -c 3 -W 2 $TARGET >/dev/null; then
echo "OK - $TARGET reachable"
exit 0
else
echo "CRITICAL - $TARGET unreachable"
exit 2
fi

Call this script via NRPE, SSH, or NCPA.

Option 5: Use check_by_ssh with the standard plugin

Instead of writing a script, you can directly invoke the standard Nagios plugin remotely:

check_by_ssh -H HostA \
-C "/usr/lib/nagios/plugins/check_ping -H HostB -w 100.0,20% -c 500.0,60%"

This is a simple solution if SSH access is already configured.

Which approach is best?
NRPE: Best for traditional Nagios deployments with many remote checks.
SSH (check_by_ssh): Good if you prefer not to install an agent.
NCPA: Recommended for newer deployments using NCPA.
Custom script: Best if you need additional logic (multiple targets, retries, routing tests, etc.).

If your goal is specifically to verify network connectivity between two monitored hosts (e.g., "Can Host A reach Host B?"), using check_ping executed on Host A via NRPE or SSH is generally the cleanest and most common solution.