LinuxScripting

How to check IPs Respond – Ping Multiple IPs

Many users have multiple IPs assigned to their Dedicated Server and NVME VP Server. On our NVMe VPS users can have a maximum of 128 additional IPs or on a dedicated server users can have a maximum of 250 IPs. When users have multiple IPs assigned to their servers they want a way to check that all their IPs are functioning without having to ping each IP.

Ping IP Or Multiple IPs With Bash

A simple bash script can be used to ping multiple IPs. We have provided a quick script below. To use the script just copy the code to a new file on your server. This does not have to be run by the root user.

nano pingall.sh

Now, copy the below code the file.

#!/bin/bash
date
cat ping.txt |  while read output
do
    ping -c 1 "$output" > /dev/null
    if [ $? -eq 0 ]; then
    echo "IP $output is up"
    else
    echo "IP $output is down"
    fi
done

Save and close the file. Next place all of the IPs you want to ping in a new file called ping.txt. This file should be in the same directory as the pingall.sh file.

nano ping.txt

The file will now have a list of IPs. One IP per line.

51.68.247.104
51.68.247.105
51.68.247.106
51.68.247.107
51.68.247.108
51.68.247.109
51.68.247.110
51.68.247.111


Finally, you can run the script with the below command. This will cycle through each IP in the ping.txt file returning whether the IP is up or down.

sh pingall.sh

Tue Aug 18 10:37:33 UTC 2020
IP 51.68.247.104 is up
IP 51.68.247.105 is up
IP 51.68.247.106 is up
IP 51.68.247.107 is up
IP 51.68.247.108 is down
IP 51.68.247.109 is up
IP 51.68.247.110 is up
IP 51.68.247.111 is up

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button