Skip to content

This is a simple bash script that checks if your public IPv4 address has changed, if so, it changes it in your specific CloudFlare zone using their API.

Notifications You must be signed in to change notification settings

Krystian-Zak/bash-script-IPv4-CloudFlare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

General info

This is a simple bash script that checks if your public IPv4 address has changed, if so, it changes it in your specific CloudFlare zone using their API.

Requirements

  • CloudFlare API Token for your specific zone
  • jq - to interpret and work with JSON
  • curl
  • public IPv4
  • task scheduler - e.g. cron

Configuration

To run this script, you need to:

  1. Specify the file where you will store your "old" IPv4 address, for example /home/youruser/ip:
    IPFILE=<IPv4 FILE>
  1. Put the generated CloudFlare API token for your ZONE:
    CLOUDFLARE_API_TOKEN=<CLOUDFLARE API TOKEN>
  1. Specify the name of your zone:
    ZONE_ID=$(curl -X GET "https://api.cloudflare.com/client/v4/zones?name=<ZONE NAME>" \
  1. Optionally, on last step you can send email with your email client (for me it is mutt), when the IPv4 has been changed:
echo -e "$(date) - Your IPv4 address has been changed from $OLDIP to $NEWIP" | mutt -s "Your IPv4 address has been changed on CloudFlare - zone name" <your e-mail address>
  1. Add automatic script execution to the schedule of tasks at a specified time, for example crontab:
*/15 *  * * *   <user>      /<path-to-scripts>/cloudflare-ip-check.sh

Also I left else statements, so you can make your own e.g. error alert, logs.

About

This is a simple bash script that checks if your public IPv4 address has changed, if so, it changes it in your specific CloudFlare zone using their API.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages