You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Shell script to manage dynamic IP addresses in Cloudflare DNS
1
+
# Shell script to manage dynamic IP addresses in Cloudflare DNS
2
+
3
+
## Introduction
4
+
5
+
Use this script as a template for managing dynamic IP addresses in Cloudflare DNS using API v4.
6
+
7
+
Documentation about updating a DNS record through Cloudflare API v4 is available here: https://api.cloudflare.com/#dns-records-for-a-zone-update-dns-record.
8
+
9
+
## Installation
10
+
11
+
1. Read the [documentation of the API](https://api.cloudflare.com/) and generate your authentication token.
12
+
13
+
2. Get your DNS zone's ID from your dashboard.
14
+
15
+
3. Get your DNS record's ID using the API:
16
+
17
+
```console
18
+
$ curl -X GET "https://api.cloudflare.com/client/v4/zones/ZONE_ID/dns_records" \
19
+
-H "Authorization: Bearer TOKEN"
20
+
```
21
+
22
+
4. Install `jq` JSON parser:
23
+
24
+
```console
25
+
# apt install jq
26
+
```
27
+
28
+
5. Download the script file `cloudflare-dynamic-ip.sh` and fill in all the settings:
29
+
30
+
- Authentication
31
+
-`TOKEN`
32
+
-`ZONE_ID`
33
+
- Common record settings
34
+
-`ZONE_NAME`
35
+
-`RECORD_TYPE`
36
+
-`RULE_PROXIABLE` (default `true`)
37
+
-`RULE_PROXIED` (default `true`)
38
+
-`RULE_LOCKED` (default `false`)
39
+
-`STORED_IP`
40
+
- Specific record settings
41
+
-`RECORD_ID`
42
+
-`RECORD_NAME`
43
+
44
+
6. Create a `cloudflare-dynamic-ip-last.txt` for storing the last IP and preventing from calling the API if there is no change. Ensure that the user running the script has permission to read and write this file.
45
+
46
+
## Usage
47
+
48
+
Run the script:
49
+
50
+
```console
51
+
$ bash cloudflare-dynamic-ip.sh
52
+
```
53
+
54
+
## Cron
55
+
56
+
If you want to run the script programatically, you can use Cron jobs:
0 commit comments