This repository provides a DNS monitoring service that checks the health of multiple IP addresses and dynamically updates DNS records using the Cloudflare API. The service also sends notifications via Telegram whenever a DNS record is updated.
- Automatic DNS Failover: Monitors multiple IP addresses and updates DNS records if a primary IP becomes unavailable.
- Configurable Health Checks: Customize the port, timeout, and interval for health checks.
- Telegram Notifications: Receive real-time notifications via Telegram when DNS records are updated.
- Multi-language Support: Supports English and Chinese languages for configuration.
- Interactive Menu: Provides an interactive menu to manage configuration.
- A server running a supported Linux distribution (Ubuntu, Debian, CentOS, RHEL, Fedora).
- Python 3 installed on the server.
jq
,supervisor
, andnginx
installed on the server.- Cloudflare account with an API key and email.
- Telegram bot token and chat ID.
bash <(curl -L -s https://raw.githubusercontent.com/zytakeshi/CloudflareDnsFailoverForVpns/main/setup_dns_monitor.sh)
The installer will prompt you to enter:
- Cloudflare API key
- Cloudflare email
- Telegram Bot API token
- Telegram Chat ID
- Custom Telegram API URL
- Health check port, timeout, and interval
- Fail threshold
Use the interactive menu to:
- List domains
- Modify domain IP addresses
- Delete domains
- Add new domains
- Configure the language
If you are using a server in China and facing issues connecting to the Telegram API, you can set up an Nginx reverse proxy to route requests to Telegram.
## Telegram API Reverse Proxy
server {
listen 80;
listen [::]:80;
server_name telegram.example.com;
# Enforce HTTPS
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name telegram.example.com;
## Update with your SSL certificate paths
ssl_certificate /etc/nginx/cert/full_chain.pem;
ssl_certificate_key /etc/nginx/cert/private.key;
## DNS resolver
resolver 8.8.8.8;
# Forward bot requests to Telegram API
location ~* ^/bot {
proxy_buffering off;
proxy_pass https://api.telegram.org$request_uri;
proxy_http_version 1.1;
}
# Optional: You can use this to check server status, or disable it with return 403;
location / {
try_files $uri $uri /index.html;
}
}
To stop and remove the DNS monitor service, follow these steps:
-
Stop the Service:
sudo supervisorctl stop dnsmonitor
-
Remove the Supervisor Configuration:
sudo rm /etc/supervisord.d/dnsmonitor.conf
-
Reload Supervisor:
sudo supervisorctl reread sudo supervisorctl update
-
Remove the DNS Monitor Files:
rm -rf /path/to/dns-monitor
This project is licensed under the GNU 3.0 License.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or features you'd like to add.