This project is designed to update a CloudFlare DNS record with your current public IP address if it changes. The script checks your public IP address and compares it with the IP address currently set in the DNS record. If the IPs are different, it updates the DNS record with the new IP.
- Node.js (v14 or later)
- npm
-
Clone the repository:
git clone https://github.com/your-username/cloudflare-dns-updater.git cd cloudflare-dns-updater
-
Install the dependencies:
npm install
-
Create a
.env
file in the root of your project directory and add your CloudFlare API credentials and other required information:API_TOKEN=your_cloudflare_api_token ZONE_ID=your_cloudflare_zone_id DNS_RECORD_ID=your_dns_record_id BASE_URL=https://api.cloudflare.com/client/v4/zones/
-
Run the script:
node your-script-file.js
API_TOKEN
: Your CloudFlare API token.ZONE_ID
: The Zone ID of your CloudFlare domain.DNS_RECORD_ID
: The DNS record ID you want to update.BASE_URL
: Base URL for CloudFlare API (usuallyhttps://api.cloudflare.com/client/v4/zones/
).
- The script fetches your current public IP using the wtfismyip API.
- It retrieves the current IP address set in the specified DNS record from CloudFlare.
- If the IP addresses do not match, it updates the DNS record with the new public IP.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes.
- Commit your changes (
git commit -am 'Add some feature'
). - Push to the branch (
git push origin feature-branch
). - Create a new Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.