Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

This Bash script is designed to automatically update the "A" record for a specified domain name in Cloudflare. "A" records are DNS records that point your domain name to an IP address. This script uses Cloudflare's HTTP API to perform these updates.

Here's what each part of the script does:

  1. The API_TOKEN is passed to the script as a command line argument. This token is a unique key that allows the script to interact with the Cloudflare API.
  2. The current date and time are fetched and saved to the current_time variable. This is used later in the script to mark when updates were performed.
  3. The current public IP of the machine running the script is retrieved using the Amazon's Check IP service and stored in the public_ip variable.
  4. Various variables are defined: ZONE_ID is the unique identifier for your Cloudflare zone (which usually contains one or more domain names), RECORD_NAME is the domain name for which the DNS record is to be updated.
  5. The H1, H2, and H3 variables are used to store the headers for the HTTP requests made to Cloudflare's API.
  6. The script makes a GET request to the Cloudflare API to retrieve all DNS records for the ZONE_ID.
  7. From the returned DNS records, the RECORD_ID for the required RECORD_NAME is extracted.
  8. If no RECORD_ID is found, the script prints an error message and stops execution.
  9. The script checks if the current public IP of the machine is different from that in the DNS record.
  10. If the IP address is different, the script generates a JSON payload with the new IP address and updates the DNS record through the Cloudflare API.

To use this script, you need to replace the following placeholders:

  • Replace xxxxxxxxxxxxxxxxxxxxxx with your Cloudflare Zone ID.
  • Replace record.domain.com with the domain name you wish to update.
  • Replace youremail@address.com with your email.

To use the script, copy this script to your local machine:

  1. Create a new file using any text editor and paste the script into that file.
  2. Save the file with an appropriate name, such as homeservice.greatdomain.com.sh.

To change permissions of the file so it can run as a script:

chmod +x homeservice.greatdomain.com.sh

The above command makes the script executable. You can execute the script using the command below, ensuring to replace <your-api-token> with your actual Cloudflare API token:

./homeservice.greatdomain.com.sh <your-api-token>

About

This Bash script is designed to automatically update the "A" record for a specified domain name in Cloudflare. "A" records are DNS records that point your domain name to an IP address. This script uses Cloudflare's HTTP API to perform these updates.

Resources

Stars

Watchers

Forks

Contributors

Languages