Dynamic IP using Cloudflare

Dynamic IP using Cloudflare

I previously posted an article about updating your DNS with your dynamic IP using paid service noip.com. I recently found out that you can do the same for free using Cloudflare.

Assumptions

  1. Registered an account with Cloudflare.
  2. Domain configured and active in Cloudflare. If not, read my post on how to configure one.
  3. Installed curl and jq.

Copy the content below into update.sh.

#!/bin/bash
json='Content-Type: application/json'
email='YOUR_EMAIL_HERE'
api_key='YOUR_GLOBAL_API_KEY_HERE'
zone_id='YOUR_ZONE_ID_HERE'
domain='www1.oofnivek.com'
dns_id=$(curl -X GET "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records?type=A&name=$domain" -H "X-Auth-Email: $email" -H "X-Auth-Key: $api_key" -H "$json"|jq -r .result[0].id)
#echo -n $dns_id
ip=$(curl checkip.amazonaws.com)
curl -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$dns_id" -H "X-Auth-Email: $email" -H "X-Auth-Key: $api_key" -H "$json" \
--data '{"type":"A","name":"'$domain'","content":"'$ip'","ttl":1,"proxied":true}'
dynamic-ip-using-cloudflare
Create a sub domain for you to update dynamically
dynamic-ip-using-cloudflare
This is where you can get your global API key
dynamic-ip-using-cloudflare
Once clicked [View], your API key will be shown
dynamic-ip-using-cloudflare
You can get your Zone ID here

The API I used can be found here

List DNS Records

Update DNS Record

 

Setup Cloudflare flexible SSL

Setup Cloudflare flexible SSL

In order to setup Cloudflare flexible SSL for your WordPress site, you’ll need to move your domain name server to Cloudflare. Login to your Cloudflare, at the top menu, choose crypto, then change SSL settings to flexible.

At the top menu, choose page rules. Add a page rule to always use HTTPS for http://www.oofnivek.com/*

Take note that the URL is HTTP and not HTTPS. This is because my web server is actually serving pages using HTTP and not https. Cloudflare is the one serving my pages using https acting like a proxy between you and my server.

setup cloudflare flexible ssl
Set the SSL settings to flexible
setup cloudflare flexible ssl
Add a page rule to my site.

Install WordPress plugin

Other than the configuration in Cloudflare, we need to install WordPress HTTPS (SSL) plugin. Without this plugin, loading the page will cause mixed content error and warnings. Once installed and activated, set the value for “proxy” to yes. If properly configured, it should show secure now next to the address bar.

setup cloudflare flexible ssl
Install the WordPress HTTPS (SSL) plugin.
setup cloudflare flexible ssl
Mixed content error and warning without the plugin.
setup cloudflare flexible ssl
Set proxy settings to “yes”.
setup cloudflare flexible ssl
Properly configured flexible SSL.

Move domain from AWS Route 53 to Cloudflare

Sign up Cloudflare account

To move domain from Amazon Web Services (AWS) Route 53 to Cloudflare. First you need to have a Cloudflare account. Sign up for a free account if you do not have one. Once signed up, go to DNS (Domain Name Server), you will be assigned with two name servers.

move domain route53 cloudflare
Cloudflare name servers assigned to my account

Move domain from AWS to Cloudflare

Now in your Amazon Web Service (AWS) console. At the top menu click services, then choose Route 53. After that on the left menu, choose hosted zones.

Click on the domain you wish to move. Then choose the row with type NS (Name Server). Remove all the Amazon name servers and replace them with Cloudflare name servers.

Now on the left menu, choose registered domains, click on the domain you wish to move. Edit the name servers by removing all of the Amazon name servers and replace them with Cloudflare name servers.

That’s all, you have successfully moved your domain to Cloudflare. Your changes will take a few minutes to reflect. Read test Cloudflare DNS to test your newly moved domain.

move domain route53 cloudflare
Changed the value of my domain name servers to Cloudflare name servers in hosted zones
move domain route53 cloudflare
Changed the value of my domain name servers to Cloudflare name servers in registered domains

Cheap domain

I have been using Amazon Web Services (AWS) Route 53 to buy domains for a while now since I moved away from GoDaddy.  It is actually cheaper to buy from Amazon if you plan to use the domain for more than two years.

Amazon domain is the same price every year. GoDaddy domain is ultra cheap the first year, but year three onwards is ridiculously expensive.

Besides that, I like the fact that I have everything inside one Amazon account. It is also because of this, I was reluctant to use Cloudflare because AWS has CloudFront.