This material was compiled with active participation of neural networks and the text may contain typos!

The attached script itself has been tested and debugged — it is suitable for production use. Provided as-is. Use at your own risk!

Automatic IP Switching#

PrivateFlare is not just infrastructure for affiliates, but also a smart fault-tolerance tool. Today we are introducing a new feature: automatic IP address switching when a node becomes unavailable.

Why Is This Needed?#

The scenario is familiar to everyone who works with traffic:

  • A site or landing page suddenly stops responding
  • The reason — the node is blocked or unavailable
  • Traffic is wasted while you manually change the A record in Cloudflare

Now you no longer need to do this manually.

How the Automation Works#

We have prepared a PHP script that can be run via cron or as a daemon. It does the following:

  • Checks node availability via a specified URL (GET or POST with JSON payload).
  • If there is no valid response (200, 301, 302) within 5 seconds — the node is considered dead.
  • The script queries the list of A records in Cloudflare via API.
  • Finds the current IP and replaces it with the next one in rotation from the specified pool:
Pool: [1.1.1.1, 2.2.2.2, 3.3.3.3]
Was IP: 2.2.2.2 → becomes: 3.3.3.3
Was last → becomes first
  • Updates the DNS record via Cloudflare API.
  • Sends a notification to Telegram so you stay informed.

What Does This Give You?#

  • Less traffic downtime — IP changes within seconds of a failure.
  • Painless scaling — add as many nodes as you want.
  • Full autonomy — no manual DNS edits, no manual fixes, no panic.
  • Telegram notifications — know about all actions in real time.

How to Set Up#

  • Install PHP >= 7.4.
  • Specify in the config:
    • domain
    • hostname (e.g., node1.domain.com)
    • Cloudflare API Token and Zone ID
    • IP address pool
    • Telegram bot token
    • chat ID (see below)
  • Add the script call to cron or run it as a systemd service.

How to Get a Telegram Chat ID?#

There are two simple methods:

Method 1 — via @userinfobot#
  • Open Telegram.
  • Find the bot @userinfobot.
  • Start it — it will immediately show your ID. This is the chat_id you need.
Method 2 — via your own bot#

If you want to receive notifications from your own bot:

  • Send any message to your bot.
  • Go to the following link, substituting your token:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates

Find in the JSON response the line:

"chat": {
  "id": 123456789,
  ...
}

123456789 is your chat_id.

How to Run the Script?#

Choose a convenient method:

1. Via cron#

Run the script regularly, for example, every 2 minutes:

*/2 * * * * php /path/to/checker.php

Replace /path/to/checker.php with the actual path to your file.

2. Via web (over HTTP)#

Place the script on a server accessible via URL, for example:

https://yourhost.com/tools/checker.php

You can call it:

  • from monitoring systems (UptimeRobot, Pingdom, HetrixTools)
  • from CI/CD pipelines (GitLab CI, Jenkins)
  • from automation tools (Home Assistant, Zabbix)
  • manually via browser or curl:
curl https://yourhost.com/tools/checker.php

Download the script