According to the TOS of CloudFlare that CDN only support port 80 (native HTTP) and port 443(native HTTPS).
You must change your port 80 to others if you want to use in China. Besides, there is a block on China Telecom that IPV6 port 80 (or like port 8080) can only be accessed in their network.
Preparation
- A domain hosted in the CloudFlare.
- A terminal (Mobile, Router, PC, etc.)
Create Sub Domain and Extract API Info
1.First of all, log into CloudFlare and select the domain you want to relay. Then, change the tab to 'DNS'.
2.Press F12 to open Chrome DevTool, turn to tab 'Network' and create a subdomain you want to relay.
3.Left click a packet named dns_records and turn to the tab 'Preview' you can see 'name', 'id','zone_id'. Mark it down, we'll use it soon.
4.Switch to 'My Profile' page. Change to the 'API Tokens' tab and create a Token on the right top of the page.
Then, create an API Token with the least privilege principle.
Markdown the Token.
5.CloudFlare now uses the way that the OAuth does. So, the authentication header now is like: 'Authorization: Bearer TOKEN'
Script
Replace the name, id, zone, and token that just marked down.
PHP Version (IPV6 version by default)
<?php
!defined('CLOUDFLARE_NAME')&&define('CLOUDFLARE_NAME','replace with name');
!defined('CLOUDFLARE_RECORD_ID')&&define('CLOUDFLARE_RECORD_ID','replace with id');
!defined('CLOUDFLARE_TOKEN')&&define('CLOUDFLARE_TOKEN','replace with token');
!defined('CLOUDFLARE_ZONE_ID')&&define('CLOUDFLARE_ZONE_ID','replace with zone_id');
function puturl($url,$data){
$data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt ($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer '.CLOUDFLARE_TOKEN,
'Content-Length: ' . strlen($data)
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output,true);
}
function geturl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
$ipv4_address = geturl('http://v4.ip.zxinc.org/getip');
$ipv6_address = geturl('http://v6.ip.zxinc.org/getip');
$data_v4 = [
'type'=>'A',
'name'=>CLOUDFLARE_NAME,
'content'=>$ipv4_address,
'ttl'=> 300,
'proxied' =>false
];
$data = [
'type'=>'AAAA',
'name'=>CLOUDFLARE_NAME,
'content'=>$ipv6_address,
'ttl'=> 300,
'proxied' =>false
];
puturl('https://api.cloudflare.com/client/v4/zones/'.CLOUDFLARE_ZONE_ID.'/dns_records/'.CLOUDFLARE_RECORD_ID, $data);
Shell Version (IPV6 version by default)
#!/bin/sh
CLOUDFLARE_ZONE_ID="replace with zone_id"
CLOUDFLARE_TOKEN="replace with token"
CLOUDFLARE_RECORD_ID="replace with id"
CLOUDFLARE_NAME="replace with name"
IPV6_ADDRESS=`curl http://v6.ip.zxinc.org/getip`
IPV4_ADDRESS=`curl http://v4.ip.zxinc.org/getip`
curl -X PUT "https://api.cloudflare.com/client/v4/zones/NULL/dns_records/$CLOUDFLARE_RECORD_ID" -H "Authorization: Bearer $CLOUDFLARE_TOKEN" -H "Content-Type: application/json" --data "{\"type\":\"AAAA\",\"name\":\"$CLOUDFLARE_NAME\",\"content\":\"$IPV6_ADDRESS\",\"ttl\":300,\"proxied\":false}"
#curl -X PUT "https://api.cloudflare.com/client/v4/zones/NULL/dns_records/$CLOUDFLARE_RECORD_ID" -H "Authorization: Bearer $CLOUDFLARE_TOKEN" -H "Content-Type: application/json" --data "{\"type\":\"A\",\"name\":\"$CLOUDFLARE_NAME\",\"content\":\"$IPV4_ADDRESS\",\"ttl\":300,\"proxied\":false}"
CloudFlare API Wiki
Important!
1.You can place it into Crond.
2.Please make full use of a firewall to prevent the cyber attack due to IPV6 exposed.
Free Domain
1.Github Education Package
2.Freenom Domain