<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DNS | TekCookie</title>
	<atom:link href="https://tekcookie.com/category/dns/feed/" rel="self" type="application/rss+xml" />
	<link>https://tekcookie.com</link>
	<description>Everything about IT</description>
	<lastBuildDate>Wed, 06 Oct 2021 14:49:55 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/tekcookie.com/wp-content/uploads/2021/06/cropped-TekCookie-211.png?fit=32%2C17&#038;ssl=1</url>
	<title>DNS | TekCookie</title>
	<link>https://tekcookie.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">174510684</site>	<item>
		<title>Dynamic DNS with CloudFlare and PowerShell</title>
		<link>https://tekcookie.com/dynamic-dns-with-cloudflare-and-powershell/</link>
					<comments>https://tekcookie.com/dynamic-dns-with-cloudflare-and-powershell/#comments</comments>
		
		<dc:creator><![CDATA[jeffythampi]]></dc:creator>
		<pubDate>Sun, 14 Feb 2021 15:07:53 +0000</pubDate>
				<category><![CDATA[DNS]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Cloudflare]]></category>
		<category><![CDATA[cloudflare api]]></category>
		<category><![CDATA[cloudflare api using PowerShell]]></category>
		<category><![CDATA[DDNS]]></category>
		<category><![CDATA[Dynamic DNS]]></category>
		<guid isPermaLink="false">https://tekcookie.com/?p=1900</guid>

					<description><![CDATA[CloudFlare does provide free plan where one can add one domain and proxy the traffic for FREE. Cloudflare also do give the provision to manage the domain using API&#8217;s. We will see how to create a DNS record and update the record using PowerShell. To manage the DNS record in cloudflare, we need to obtain [&#8230;]]]></description>
										<content:encoded><![CDATA[				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-d6b5e917     "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							Table Of Contents						</div>
																<div class="uagb-toc__list-wrap">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#validating-cloudflare-api-key-using-powershell" class="uagb-toc-link__trigger">Validating cloudflare API key using Powershell</a><li class="uagb-toc__list"><a href="#adding-a-new-record-to-cloudflare-dns" class="uagb-toc-link__trigger">Adding a new record to Cloudflare DNS</a><li class="uagb-toc__list"><a href="#edit-an-existing-cloudflare-dns-record" class="uagb-toc-link__trigger">Edit an existing Cloudflare DNS record</a></ol>					</div>
									</div>
				</div>
			


<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p>CloudFlare does provide free plan where one can add one domain and proxy the traffic for FREE. Cloudflare also do give the provision to manage the domain using API&#8217;s.</p>



<p>We will see how to create a DNS record and update the record using PowerShell.</p>



<p>To manage the DNS record in cloudflare, we need to obtain the API token and permission to edit the DNS records.</p>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p>To obtain the API token, login to cloudflare, under your domain portal, click on &#8220;Get your API token&#8221;. Also note the &#8220;Zone Id&#8221; in the page, which is required in the API.</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" fetchpriority="high" decoding="async" width="781" height="900" src="https://i0.wp.com/tekcookie.com/wp-content/uploads/2021/02/image-1.png?resize=781%2C900&#038;ssl=1" alt="" class="wp-image-2803" srcset="https://i0.wp.com/tekcookie.com/wp-content/uploads/2021/02/image-1.png?w=781&amp;ssl=1 781w, https://i0.wp.com/tekcookie.com/wp-content/uploads/2021/02/image-1.png?resize=260%2C300&amp;ssl=1 260w, https://i0.wp.com/tekcookie.com/wp-content/uploads/2021/02/image-1.png?resize=768%2C885&amp;ssl=1 768w" sizes="(max-width: 781px) 100vw, 781px" /></figure>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p>Click on &#8220;API Tokens&#8221; tab and click &#8220;Create Token&#8221; button. </p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/tekcookie.com/wp-content/uploads/2021/02/image-2.png?w=1080&#038;ssl=1" alt="" class="wp-image-1904"/></figure>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p>click the &#8220;Use Template&#8221; button as shown below.</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/tekcookie.com/wp-content/uploads/2021/02/image-3.png?w=1080&#038;ssl=1" alt="" class="wp-image-1905"/></figure>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p>Select the zone setings as below with the required domain details and click &#8220;Continue to summary&#8221;</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/tekcookie.com/wp-content/uploads/2021/02/image-4.png?w=1080&#038;ssl=1" alt="" class="wp-image-1906"/></figure>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p>Click &#8220;Create Token&#8221; to generate the api key. </p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/tekcookie.com/wp-content/uploads/2021/02/image-5.png?w=1080&#038;ssl=1" alt="" class="wp-image-1907"/></figure>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p>Copy the generated key to access the DNS using PowerShell.</p>



<pre class="wp-block-preformatted">Sample Token : p6bfghn0rsdfghc-34ggb5tdas8w7ysdftj-C4
Sample ZoneID : 6cd345qefad7c71dfg5q23573017</pre>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Validating cloudflare API key using Powershell</h2>



<p>Run the below script in PowerShell to validate the access</p>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">Invoke-RestMethod -Method Get -Uri "https://api.cloudflare.com/client/v4/user/tokens/verify" -Headers @{
 "Authorization" = "Bearer p6bfghn0rsdfghc-34ggb5tdas8w7ysdftj-C4"
 "Content-Type" = "application/json"
 } </code></pre>



<p>Result with success = True shows that the key is valid and accepted.</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/tekcookie.com/wp-content/uploads/2021/02/image-6.png?w=1080&#038;ssl=1" alt="" class="wp-image-1912"/></figure>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p>To know your public IP,  please refer to my other post</p>



<figure class="wp-block-embed is-type-wp-embed is-provider-tekcookie wp-block-embed-tekcookie"><div class="wp-block-embed__wrapper">
<blockquote class="wp-embedded-content" data-secret="JkZMdlu1S7"><a href="https://tekcookie.com/get-your-public-ip-using-powershell/">Get your Public IP using PowerShell</a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  title="&#8220;Get your Public IP using PowerShell&#8221; &#8212; TekCookie" src="https://tekcookie.com/get-your-public-ip-using-powershell/embed/#?secret=JkZMdlu1S7" data-secret="JkZMdlu1S7" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div></figure>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Adding a new record to Cloudflare DNS</h2>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell"> $token = "p6bfghn0rsdfghc-34ggb5tdas8w7ysdftj-C4"
 $hostname = "dyDNS.domain.com"
 $ip = Invoke-RestMethod -uri "https://ifconfig.io/ip"  #Your Public IP 
 $zoneid = "6cd345qefad7c71dfg5q23573017"
 $url = "https://api.clouflare.com/client/v4/zones/$zoneid/dns_records"

 $Body = @{
     "type" = "A"
     "name" =  $hostname
     "content" = $ip
     "proxied" = $true # To mask the real IP
 }

 $Body = $Body | ConvertTo-Json

 $result = Invoke-RestMethod -Method post -Uri $url -Headers @{
 "Authorization" = "Bearer p6bfghn0rsdfghc-34ggb5tasdas8w7ysdftj-C4"
 } -Body $Body -ContentType "application/json"

 $result.result</code></pre>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Edit an existing Cloudflare DNS record</h2>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell"> $hostname = "dyDNS.domain.com"
 $zoneid = "6cd345qefad7c71dfg5q23573017"
 $token = "p6bfghn0rsdfghc-34ggb5tdas8w7ysdftj-C4"
 $url = "https://api.cloudflare.com/client/v4/zones/$zoneid/dns_records" 

 # Fetch the record information
 $record_data = Invoke-RestMethod -Method get -Uri "$url/?name=$hostname" -Headers @{
 "Authorization" = "Bearer $token"
 } 

 # Modify the IP from the fetched record
 $record_ID = $record_data.result[0].id
 $record_data.result[0].content = Invoke-RestMethod -uri "https://ifconfig.io/ip" #Your Public IP 

 $body = $record_data.result[0] | ConvertTo-Json

 # Update the record
 $result = Invoke-RestMethod -Method put -Uri "$url/$record_ID" -Headers @{
 "Authorization" = "Bearer $token"
 } -Body $body -ContentType "application/json"</code></pre>



<p>Run this script in a Scheduled Task, your Public IP will get updated in DNS !!!</p>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Hope you like this article and thank you for reading.</p></blockquote>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://tekcookie.com/dynamic-dns-with-cloudflare-and-powershell/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1900</post-id>	</item>
	</channel>
</rss>
