Script that can be used to provide your own dynamic DNS with CloudFlare DNS.
|
|
5 jaren geleden | |
|---|---|---|
| README.md | 5 jaren geleden | |
| ddns.php | 5 jaren geleden |
/*
*
* CUSTOM DYNAMIC DNS SOLUTION FOR USE WITH CLOUDFLARE
* ===============================================================================================
* ===============================================================================================
*
* Christopher Pei
* ------------------------------------------
* September 05, 2018 R1
* November 27, 2018 R2
* November 28, 2018 R3
* ===============================================================================================
*
*/
#API Credential Setup Instructions#
Settings or organized in a tabular format with SETTING NAME on the left and VALUE on the right. Please only edit the VALUE data/columns. When editing, please keep values inside the quotation- marks ("") and do not remove any parentheses (()) or semi-colons (;).
Set Basic Options
Since this script may be publicly accessible on your web server, you can use the DDNS_PASSWORD
setting so that this string must be provided in order to access this script.
To access the script with the password, you use a web browser and access it as follows:
/ddns.php?psswd=56789
replacing 56789 with your DDNS Password. For example, if this script is located
on your webserver at https:www.google.com/ddns.php and your DDNS Password is
4392, you would use your browser to access it as follows:
https:www.google.com/ddns.php?passwd=4392
Alternatively, if you wish to disable this security feature, leave the VALUE empty (nothing between the quotation marks). Then you can access the script just via the name itself. In the example above but without a DDNS Password, you would access it as follows:
https:www.google.com/ddns.php
define(__NAMESPACE__ . '\DDNS_PASSWORD', '56789' );
For many of these settings, you will have access to your CloudFlare account to acquire the appropriate information.
1). Login to your CloudFlare account at: https://dash.cloudflare.com/login
2). If applicable, select your account.
3). If applicable, select the domain you wish to use.
4). Under the "Domain Summary" section, locate the "Zone ID". Copy this value and paste
this into the VALUE for the "CF_ZONE_ID" setting.
5). In the same section, click "Get your API Key". Scroll down the page and under the
"API Keys" locate the "Global API Key" and click "View". Copy this value and paste
this into the VALUE for the "CF_API_KEY" setting.
6). The e-mail address you use to login to CloudFlare is your API username. Provide
this into the VALUE for the "CF_API_USERNAME" setting.
define(NAMESPACE . "\CF_API_USERNAME", "your_email@domain.com");```
## Create The DNS Record ##
Now, if you have not already done so, it is time to create a subdomain on the domain
that you wish to use for the custom dynamic DNS:
1). Navigate to https:dash.cloudflare.com/websites and select the domain you wish to
use for the custom dynamic DNS service.
2). Go to the "DNS" section, and under the "Search" box, select "A" from the drop-down
menu, enter your desired subdomain in the "Name" field.
3). Copy and past the value of the "Name" field into the VALUE for the "FQDN" setting.
Do not include ANY trailing slashes and do NOT include either "http:" or "https:"
in the setting value.
4). Enter any IP address into the "IPv4 address" field (even "1.2.3.4" is okay; this will
be updated by the script automatically later, so its current value is not relevant).
5). If this dynamic DNS is going to be used for HTTP traffic (such as a website), then you
can leave the "Automatic TTL" and orange cloud enabled to benefit from CloudFlare's
reverse proxy security. However, if this will be used for something else (such as FTP,
SSH, Remote Desktop, etc) then modify the TTL to "2 minutes" and DISABLE the orange
cloud. Disabling the orange cloud will disable CloudFlare's reverse proxy, which is
required for non-HTTP protocols.
6). When finished, click the "Add Record" button.
define(NAMESPACE . "\FQDN", "something.example.com" );```
This is where it might seem funky. CloudFlare is somewhat "stupid" in the sense that it provides no NORMAL way to get the ID of a DNS record, which is a unique ID that identifies a particular DNS record for your website. The only way to do this is programmatically, via their API.
For simplicity, I have programmed this ability directly into this script:
1). Please be sure that all other settings are already provided--- otherwise this script
cannot authenticate with the CloudFlare API to find the ID of your DNS record. The
VALUE of CF_ZONE_ID, CF_API_KEY, and CF_API_USERNAME must be provided. (Please see
the [Set Your API Credentials] section above for help).
2). Using a web browser of your choice, access this PHP script in the URL as follows:
/ddns.php?psswd=12345&dump=1
replacing "12345" with your DDNS Password. For example, if this script is located
on your webserver at "https:www.google.com/ddns.php" and your DDNS Password is
"4392", you would use your browser to access it as follows:
https:www.google.com/ddns.php?passwd=4392&dump=1
If your DDNS Password is disabled, access this PHP script in the URL as follows:
/ddns.php?dump=1
For example:
https:www.google.com/ddns.php?dump=1
3). If successful, the script will output a long string. Please carefully copy and paste
the string into the VALUE for the "CF_DNS_RECORD_ID" setting.
If you wish to use CloudFlare's reverse proxy security, which will mask your your IP, set this value to "true" (without quotations). Otherwise, set it to "false" (without quotations). Note that the CloudFlare reverse proxy feature is currently for HTTP services only, and will not work for other services, such as FTP, SSH, Remote Desktop, etc. A value of "true" is equivalent to the "orange-cloud" DNS setting on your CloudFlare control panel, while a value of "false" is equivalent of the "grey-cloud" DNS setting.
define(__NAMESPACE__ . "\USE_CF_REV_PROXY", false );