<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Blake K</title>
    <description>The latest articles on DEV Community by Blake K (@blake).</description>
    <link>https://dev.to/blake</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F17399%2F29b1d9ec-40d7-42c3-b19b-f393b9c90b5b.jpg</url>
      <title>DEV Community: Blake K</title>
      <link>https://dev.to/blake</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/blake"/>
    <language>en</language>
    <item>
      <title>Creating/Securing a Remote Dev Environment</title>
      <dc:creator>Blake K</dc:creator>
      <pubDate>Mon, 07 Jun 2021 15:18:19 +0000</pubDate>
      <link>https://dev.to/blake/creating-securing-a-remote-dev-environment-3558</link>
      <guid>https://dev.to/blake/creating-securing-a-remote-dev-environment-3558</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;A &lt;em&gt;remote development environment&lt;/em&gt; is an environment/server hosted externally (i.e. not on your local machine) that you connect to remotely to perform your development work on.&lt;/p&gt;

&lt;p&gt;Using the &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh" rel="noopener noreferrer"&gt;Remote-SSH&lt;/a&gt; extension on &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;Visual Studio Code&lt;/a&gt;, you can develop on a remote machine while maintaining the feel and responsiveness of developing on your &lt;em&gt;local machine&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcode.visualstudio.com%2Fassets%2Fdocs%2Fremote%2Fssh%2Farchitecture-ssh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcode.visualstudio.com%2Fassets%2Fdocs%2Fremote%2Fssh%2Farchitecture-ssh.png" alt="A diagram explaining how Remote-SSH works on VS Code"&gt;&lt;/a&gt;&lt;br&gt;
Image Source: &lt;a href="https://code.visualstudio.com/docs/remote/ssh" rel="noopener noreferrer"&gt;Visual Studio Code / Microsoft&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The way this is achieved is via a SSH Tunnel. But you can secure this a step further by requiring proof of identity via an SSO Identity Provider (like Google, Github, Facebook, Active Directory, etc) by using Cloudflare Access and Cloudflare Tunnel.&lt;/p&gt;

&lt;p&gt;There are numerous benefits to using a remote environment to perform your development on. Here's just a few:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You can switch machines without losing your work. Since your work is not on your local machine, that means that you can switch from your desktop to your laptop and not lose anything.&lt;/li&gt;
&lt;li&gt;You can develop your application/system on an environment that closer replicates the environment that your product will be deployed to.&lt;/li&gt;
&lt;li&gt;There's less of a security risk if your local machine is lost/stolen. Your code/files aren't on there.&lt;/li&gt;
&lt;li&gt;Colleagues and other developers can also connect to your remote development environment to help debug or perform any other necessary work.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Goals
&lt;/h3&gt;

&lt;p&gt;By the end of this tutorial, you will have:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A DigitalOcean droplet setup with your development stack&lt;/li&gt;
&lt;li&gt;Visual Studio Code setup locally with the Remote-SSH extension&lt;/li&gt;
&lt;li&gt;The &lt;a href="https://developers.cloudflare.com/cloudflare-one/glossary#cloudflared" rel="noopener noreferrer"&gt;cloudflared&lt;/a&gt; &lt;em&gt;daemon&lt;/em&gt; installed both on your remote and local machines&lt;/li&gt;
&lt;li&gt;An SSH config on your local machine to easily connect to your remote machine using Cloudflare Tunnel and Cloudflare Access&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A generated SSH Key

&lt;ul&gt;
&lt;li&gt;You will need to upload your public key to DigitalOcean&lt;/li&gt;
&lt;li&gt;You will need your private key in order to SSH into your Droplet initially&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;A &lt;a href="https://blake.link/digitalocean" rel="noopener noreferrer"&gt;DigitalOcean&lt;/a&gt; account

&lt;ul&gt;
&lt;li&gt;New users can use the link above to get a $100 credit valid for 60 days when you add a payment method to your account&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;A &lt;a href="https://www.cloudflare.com/" rel="noopener noreferrer"&gt;Cloudflare&lt;/a&gt; account with a domain added

&lt;ul&gt;
&lt;li&gt;This domain will be used by you to connect to the remote machine&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;A &lt;a href="https://developers.cloudflare.com/cloudflare-one/setup" rel="noopener noreferrer"&gt;Cloudflare for Teams&lt;/a&gt; account already setup

&lt;ul&gt;
&lt;li&gt;A free plan is available&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;A &lt;a href="https://developers.cloudflare.com/cloudflare-one/identity/idp-integration" rel="noopener noreferrer"&gt;SSO Integration&lt;/a&gt; already setup within Cloudflare for Teams

&lt;ul&gt;
&lt;li&gt;In this tutorial I'm using a GSuite integration to verify my identity&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;Visual Studio Code&lt;/a&gt; installed on your local machine&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Step 1 — Configuring Cloudflare
&lt;/h2&gt;

&lt;p&gt;You will create an access policy for your selected domain.&lt;/p&gt;

&lt;p&gt;Cloudflare Tunnel is a service which provides a secure connection between the nearest Cloudflare datacenter and your remote machine, without opening public ports. This tunnel is how you will connect to your remote machine securely. Previously this was a part of Cloudflare's paid Argo service, but as of April 2021 has been made free of charge.&lt;/p&gt;

&lt;p&gt;From your Cloudflare dashboard, select the domain (or &lt;em&gt;zone&lt;/em&gt;) that you have chosen to use for this tutorial.&lt;/p&gt;

&lt;p&gt;You need to &lt;strong&gt;create an access policy&lt;/strong&gt;. This policy will determine who has access to your Droplet. &lt;/p&gt;

&lt;p&gt;Click on the &lt;strong&gt;access&lt;/strong&gt; tab on your domain's Cloudflare dashboard. Scroll down to &lt;strong&gt;Access Policies&lt;/strong&gt; and hit &lt;strong&gt;Create Access Policy&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Give an application name, and the subdomain that you will use to connect to your Droplet (decide this now, you'll need it again later in this tutorial). For session duration, decide how long a session should be valid for.&lt;/p&gt;

&lt;p&gt;You need at least 1 policy. Create one by giving it a name. Then add an include-rule. For this tutorial, I decided on "emails ending in" and the domain of my GSuite account.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FIkP0cqw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FIkP0cqw.png" alt="A screenshot of a sample access policy."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you're done, hit &lt;strong&gt;save&lt;/strong&gt;. Now that your Cloudflare settings are configured, it's time to create your remote machine.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2 — Creating your Droplet
&lt;/h2&gt;

&lt;p&gt;You will create a Droplet on DigitalOcean with a new user, your preferred tools/programs, and the &lt;code&gt;cloudflared&lt;/code&gt; daemon.&lt;/p&gt;

&lt;p&gt;To begin, &lt;strong&gt;visit &lt;a href="https://cloud.digitalocean.com/droplets/new" rel="noopener noreferrer"&gt;this link&lt;/a&gt;&lt;/strong&gt; to access the Droplet creation page.&lt;/p&gt;

&lt;p&gt;For this tutorial, you will use &lt;strong&gt;Ubuntu 20.04&lt;/strong&gt; as your operating system.&lt;/p&gt;

&lt;p&gt;For the Droplet plan select the configuration that you think you will need for your development work. From personal experience, the Regular Intel, 4GB / 2 CPUs plan works great on a stack with Java 11, Apache Maven, Git, and Docker.&lt;/p&gt;

&lt;p&gt;Next, select your preferred datacenter. Typically, the datacenter closest to you is the best option to minimize latency.&lt;/p&gt;

&lt;p&gt;For additional options, enable &lt;strong&gt;IPv6 and User data&lt;/strong&gt;. Monitoring is optional but recommended if you wish to view stats about your Droplet online.&lt;/p&gt;

&lt;p&gt;A text field will appear after selecting the user data checkbox. This is where you will paste a script to be executed when the server initially boots for the first time.&lt;/p&gt;

&lt;p&gt;Below is a script that I have provided for you to use. It creates a new user, optionally installs some packages, and installs &lt;code&gt;cloudflared&lt;/code&gt;. There is a variable for the name of the user to create.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Back to the Droplet creation panel - For authentication select &lt;em&gt;SSH Key&lt;/em&gt; and upload your public SSH key if you don't already have a key uploaded.&lt;/p&gt;

&lt;p&gt;The remaining options are optional. I recommend changing the hostname to something you recognize, such as the domain name that you plan on using for that Droplet.&lt;/p&gt;

&lt;p&gt;Once finished configuring your options, press &lt;strong&gt;Create Droplet&lt;/strong&gt;. You've just created your remote machine! The next step is to configure it and ensure it is secure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 — Securing your Droplet
&lt;/h2&gt;

&lt;p&gt;You will configure the &lt;code&gt;cloudflared&lt;/code&gt; daemon and setup the SSH tunnel on your Droplet.&lt;/p&gt;

&lt;p&gt;On the DigitalOcean panel, navigate to your newly-created Droplet. Copy the public IPv4 address listed.&lt;/p&gt;

&lt;p&gt;You are going to have to &lt;strong&gt;SSH into your Droplet&lt;/strong&gt; with the username that you configured in the script provided. To do this, on your local shell run &lt;code&gt;ssh &amp;lt;your configured username&amp;gt;@&amp;lt;copied IP address&amp;gt; -i &amp;lt;path to your private SSH key&amp;gt;&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;An example might look like &lt;code&gt;ssh sammy@XXX.XXX.XXX.XXX -i ~/.ssh/id_rsa&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Navigate to &lt;code&gt;/etc/cloudflared/&lt;/code&gt; using &lt;code&gt;cd /etc/cloudflared&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Before proceeding, ensure that &lt;code&gt;cloudflared&lt;/code&gt; is up-to-date. Run &lt;code&gt;sudo cloudflared update&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next, you need to &lt;strong&gt;authenticate &lt;code&gt;cloudflared&lt;/code&gt;&lt;/strong&gt; with your desired zone (domain). &lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;cloudflared login&lt;/code&gt;. It should output a link, which you can then copy to your web browser and load.&lt;/p&gt;

&lt;p&gt;On the website, it is important that you &lt;strong&gt;select the zone that you will be using&lt;/strong&gt; to connect to the Droplet with. Click &lt;strong&gt;Authorize&lt;/strong&gt;. You can close that website once done.&lt;/p&gt;

&lt;p&gt;Return back to your SSH session. You now need to &lt;strong&gt;move the newly-downloaded certificate&lt;/strong&gt; to &lt;code&gt;/etc/cloudflared/cert.pm&lt;/code&gt;. Do this by running &lt;code&gt;sudo mv /home/sammy/.cloudflared/cert.pem /etc/cloudflared/cert.pem&lt;/code&gt;, replacing &lt;code&gt;sammy&lt;/code&gt; with your configured username.&lt;/p&gt;

&lt;p&gt;Now is the time to create the tunnel. &lt;/p&gt;

&lt;p&gt;Do this by running &lt;code&gt;cloudflared tunnel create NAME&lt;/code&gt;, replacing &lt;code&gt;NAME&lt;/code&gt; with a label for your tunnel. An id should then be printed out after running the command. Make note of it.&lt;/p&gt;

&lt;p&gt;Next, you need to &lt;strong&gt;create a configuration file&lt;/strong&gt; telling &lt;code&gt;cloudflared&lt;/code&gt; what to do when it runs.&lt;/p&gt;

&lt;p&gt;Modify and copy the provided config file below. Replace &lt;code&gt;XXX&lt;/code&gt; with the id of your created tunnel, and &lt;code&gt;YOUR.DOMAIN.HERE&lt;/code&gt; with the hostname that you wish to use to connect to your Droplet. The apex domain must match the one you selected when authenticating &lt;code&gt;cloudflared&lt;/code&gt;.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Create the file &lt;code&gt;/etc/cloudflared/config.yml&lt;/code&gt; by using your favorite text editor (such as &lt;a href="https://vimhelp.org/" rel="noopener noreferrer"&gt;vim&lt;/a&gt; or &lt;a href="https://www.nano-editor.org/docs.php" rel="noopener noreferrer"&gt;nano&lt;/a&gt;) and pasting your modified config template from above.&lt;/p&gt;

&lt;p&gt;To &lt;strong&gt;create the DNS record&lt;/strong&gt; for your configured domain name, run &lt;code&gt;cloudflared tunnel route dns &amp;lt;id&amp;gt; &amp;lt;subdomain&amp;gt;&lt;/code&gt; where &lt;code&gt;id&lt;/code&gt; is the id of the tunnel, and &lt;code&gt;subdomain&lt;/code&gt; is the subdomain you selected in your config file. You can verify on your Cloudflare DNS page that a CNAME record was created.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;cloudflared&lt;/code&gt; daemon is now fully configured. It's time to start it! It's best to &lt;strong&gt;run the daemon as a service&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;sudo cloudflared service install&lt;/code&gt; and &lt;code&gt;sudo service cloudflared start&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To &lt;strong&gt;verify that there were no errors&lt;/strong&gt; in the service starting, run &lt;code&gt;sudo service cloudflared status&lt;/code&gt;. You should see the  tunnel being started with some connections being made. Those connections are to nearby Cloudflare datacenters.&lt;/p&gt;

&lt;p&gt;With your remote machine configured, it's now time to configure your local machine so it is able to connect to your Droplet over this secure tunnel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4 — Configuring your local machine
&lt;/h2&gt;

&lt;p&gt;You will configure your local machine to use the Cloudflare Tunnel when SSHing into your Droplet, and install the Remote-SSH extension in Visual Studio Code to be able to modify files on your Droplet seamlessly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install &lt;code&gt;cloudflared&lt;/code&gt; on your local machine&lt;/strong&gt;. You can view full instructions from &lt;a href="https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation" rel="noopener noreferrer"&gt;Cloudflare's website&lt;/a&gt;. It supports Mac, Linux, Windows, and Docker. Again, it's best to run the daemon as a &lt;a href="https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/run-tunnel/run-as-service" rel="noopener noreferrer"&gt;service&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You do not need to authenticate the daemon on your local machine (i.e. do not run the login command). &lt;/p&gt;

&lt;p&gt;Now, you need to &lt;strong&gt;update your local SSH config&lt;/strong&gt; to make use of &lt;code&gt;cloudflared&lt;/code&gt; for your Droplet. The daemon has a feature which will generate most of this config for you.&lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;cloudflared access ssh-config --hostname YOUR.DOMAIN.HERE&lt;/code&gt;, replacing the variable with your domain that you put in your config on your Droplet.&lt;/p&gt;

&lt;p&gt;Determine where your local SSH config is. On Mac, it's located at &lt;code&gt;~/.ssh/config&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It should print something out like this to add to your SSH config:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host YOUR.DOMAIN.HERE
  ProxyCommand /usr/local/bin/cloudflared access ssh --hostname %h
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note, the path in your proxy command may be different depending on your operating system. That's why its important to use what the program gave to you after running the command.&lt;/p&gt;

&lt;p&gt;Append the printed text to your local SSH config using your preferred text editor. Add an additional line under the Host labeled &lt;code&gt;User&lt;/code&gt; with your Droplet's username (see below for an example). This makes it easier for Visual Studio Code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host YOUR.DOMAIN.HERE
  ProxyCommand /usr/local/bin/cloudflared access ssh --hostname %h
  User sammy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Try connecting to your Droplet&lt;/strong&gt; using this updated SSH config. Run &lt;code&gt;ssh YOUR.DOMAIN.HERE&lt;/code&gt;. If all goes well, your browser should open prompting you to select an identity provider, you login, and authorize the request. Once authorized, your local terminal will SSH into your Droplet and you can close the opened webpage.&lt;/p&gt;

&lt;p&gt;Now it's time to setup your local Visual Studio Code IDE. Open VS Code and &lt;strong&gt;install the &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh" rel="noopener noreferrer"&gt;Remote-SSH&lt;/a&gt; extension&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Once installed, by default the extension should show remote targets from your local SSH config file. You can select your newly-added target to connect to it.&lt;/p&gt;

&lt;p&gt;You can also use the &lt;code&gt;opensshremotes.openEmptyWindow&lt;/code&gt; VS Code command to select a remote target.&lt;/p&gt;

&lt;p&gt;After authentication (or if your session is still valid from your test), VS Code will connect to your Droplet and automatically install the VS Code Server (first boot only).&lt;/p&gt;

&lt;p&gt;From here, you can install extensions onto your Droplet, create directories/files, and even open a terminal in VS Code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FzLk59w8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FzLk59w8.png" alt="Image of Visual Studio Code, editing a file remotely."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Remote development environments are a great way to work. They allow you to develop and test your product in an environment closer to production, permits switching machines, and allows multiple people access to the environment. Using Cloudflare Access and Cloudflare Tunnel, this access can be granted or denied based on authentication through SSO providers, providing a clean way to authenticate and authorize users.&lt;/p&gt;

</description>
      <category>cloudflare</category>
      <category>digitalocean</category>
      <category>vscode</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>DNS Explained. Resolution</title>
      <dc:creator>Blake K</dc:creator>
      <pubDate>Sun, 24 Jan 2021 19:54:43 +0000</pubDate>
      <link>https://dev.to/blake/dns-explained-resolution-a2i</link>
      <guid>https://dev.to/blake/dns-explained-resolution-a2i</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is an article in the &lt;em&gt;DNS Explained.&lt;/em&gt; series. Click &lt;a href="https://dev.to/blake/dns-explained-introduction-history-1an7"&gt;here&lt;/a&gt; to read the introduction post. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Resolution is the process of asking for the resource records of a fully-qualified domain name (FQDN) and receiving back an answer. Every time that your computer does not have an IP address cached for a required FQDN, a resolution takes place. In this post, I discuss the main components involved in DNS resolution and explain the two main methods in which resolution is performed.&lt;/p&gt;

&lt;h1&gt;
  
  
  Components
&lt;/h1&gt;

&lt;p&gt;There are five main components that play a role in DNS resolution.&lt;/p&gt;

&lt;p&gt;The first component is the &lt;strong&gt;client&lt;/strong&gt;. This is the host that is asking the question, "Where is &lt;a href="http://www.netflix.com" rel="noopener noreferrer"&gt;www.netflix.com&lt;/a&gt; on the internet?"&lt;/p&gt;

&lt;p&gt;The second component is the &lt;strong&gt;DNS resolver&lt;/strong&gt;. Typically provided by your ISP, this serves as the first component that the client reaches out to if the answer to the DNS query is not cached by the client. Its role is to query the other components to find the answer to the original question. The way it does this depends on the type of DNS resolution being performed.&lt;/p&gt;

&lt;p&gt;Clients can configure their settings to use a DNS resolver not provided by their ISP. &lt;a href="https://developers.google.com/speed/public-dns" rel="noopener noreferrer"&gt;Google&lt;/a&gt;, &lt;a href="https://one.one.one.one/" rel="noopener noreferrer"&gt;Cloudflare&lt;/a&gt;, &lt;a href="https://www.verisign.com/en_US/security-services/public-dns/index.xhtml" rel="noopener noreferrer"&gt;Verisign&lt;/a&gt;, and &lt;a href="https://www.opendns.com/" rel="noopener noreferrer"&gt;Cisco&lt;/a&gt; are just a handful of companies that offer free-alternative DNS resolvers. Be aware of which resolver you choose though! Every site you visit will likely send a DNS query which is handled by your chosen DNS resolver. This gives that resolver an ability to see what you request and may sell this data to advertisers. Always read the policies of DNS resolvers that you are considering to use.&lt;/p&gt;

&lt;p&gt;The third component is the &lt;strong&gt;DNS Root Zone&lt;/strong&gt;, which is questioned if the DNS resolver does not have the answer in cache. Its role is to return the nameservers for the requested TLD. There are 13 root servers in the world operated by 12 organizations. These servers are anycasted and I go into more detail about them in my &lt;a href="https://dev.to/blake/dns-explained-hierarchy-and-architecture-18pj"&gt;DNS Architecture&lt;/a&gt; post.&lt;/p&gt;

&lt;p&gt;The fourth component is the &lt;strong&gt;TLD's Nameservers&lt;/strong&gt;. Its role is to return the authoritative nameservers of the requested second-level domain.&lt;/p&gt;

&lt;p&gt;Finally, the fifth component is the &lt;strong&gt;Authoritative Nameservers&lt;/strong&gt;. These servers are the responsibility of the registrant to provide, and their role is to return the resource record for the requested third-level domain (or apex domain).&lt;/p&gt;

&lt;h1&gt;
  
  
  Iterative Resolution
&lt;/h1&gt;

&lt;p&gt;There are two types of resolution, the first is iterative. In an iterative resolution, it is the responsibility of the DNS resolver to keep querying nameservers until it gets an answer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FDpK9H6o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FDpK9H6o.png" alt="A flowchart describing iterative resolution."&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Let's go through each step in more detail.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The client sends an iterative DNS query for &lt;code&gt;www.blakes.site.&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The DNS resolver receives this query. If it doesn't have an answer for this query already cached, it will continue by asking a root server where the nameservers for &lt;code&gt;.site&lt;/code&gt; are. If it is cached, the answer will be returned here and the process will terminate. Sidenote: The DNS resolver could also store cache entries for the &lt;code&gt;.site&lt;/code&gt; TLD nameservers and the &lt;code&gt;blakes.site&lt;/code&gt; authoritative nameservers and skip the appropriate steps.&lt;/li&gt;
&lt;li&gt;The root server returns the IP addresses for the &lt;code&gt;.site&lt;/code&gt; nameservers. It also can cache the &lt;code&gt;.site&lt;/code&gt; nameservers for future usage.&lt;/li&gt;
&lt;li&gt;The DNS resolver now has to ask the &lt;code&gt;.site&lt;/code&gt; TLD nameservers for the IP addresses of the &lt;code&gt;blakes.site&lt;/code&gt; authoritative nameservers. It also can cache the &lt;code&gt;.site&lt;/code&gt; nameservers for future usage.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;.site&lt;/code&gt; TLD nameservers return the IP addresses for the &lt;code&gt;blakes.site&lt;/code&gt; authoritative nameservers. The DNS resolver can cache the &lt;code&gt;blakes.site&lt;/code&gt; authoritative nameservers for future usage.&lt;/li&gt;
&lt;li&gt;The DNS resolver asks the &lt;code&gt;blakes.site&lt;/code&gt; authoritative nameservers for the resource records for the entry &lt;code&gt;www&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;blakes.site&lt;/code&gt; authoritative nameservers return the resource records for the entry &lt;code&gt;www&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The DNS resolver caches the response and returns it back to the client.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Recursive Resolution
&lt;/h1&gt;

&lt;p&gt;The alternative to iterative resolution is recursive resolution. Instead of an address to the next nameserver being sent back to the DNS resolver to then query, the nameserver makes the request itself and returns the result all the way back up to the DNS resolver.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FKNpCaLc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FKNpCaLc.png" alt="A flowchart describing recursive resolution."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's also go through this resolution step-by-step.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The client sends a recursive DNS query for &lt;code&gt;www.blakes.site.&lt;/code&gt;. Nothing new.&lt;/li&gt;
&lt;li&gt;The DNS resolver receives this query. If it doesn't have an answer for this query already cached, it will continue by asking a root server for the answer to &lt;code&gt;www.blakes.site.&lt;/code&gt;. If it is cached, the answer will be returned here and the process will terminate.&lt;/li&gt;
&lt;li&gt;If the root server did not have an answer cached, then it asks the next component that could have an answer: the TLD nameservers. The root servers can also cache the TLD nameservers for the requested domain for future use.&lt;/li&gt;
&lt;li&gt;If the TLD nameservers did not have an answer cached, then it asks the next component that could have an answer: the authoritative nameservers. The TLD nameservers can also cache the authoritative nameservers for the requested domain for future use.&lt;/li&gt;
&lt;li&gt;The authoritative nameservers find an answer for &lt;code&gt;www.blakes.site.&lt;/code&gt; and pass the answer up back to the TLD nameservers.&lt;/li&gt;
&lt;li&gt;The TLD nameservers pass the answer back up to the root server.&lt;/li&gt;
&lt;li&gt;The root server passes the answer back to the DNS resolver.&lt;/li&gt;
&lt;li&gt;The DNS resolver caches and passes the answer back to the client.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There is caching at each component, so it is possible that only a partial resolution has to take place for a query. If the requested FQDN is popular and the DNS resolver is being used by a lot of people, then it is completely possible that the root servers are never contacted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Recursive Resolution: Pros/Cons
&lt;/h2&gt;

&lt;p&gt;In general, recursive resolution tends to be faster than its iterative counterpart due to caching of final answers. However, this type of resolution creates security flaws including &lt;a href="https://www.cloudflare.com/learning/dns/dns-cache-poisoning/" rel="noopener noreferrer"&gt;cache poisoning&lt;/a&gt; and &lt;a href="https://www.cloudflare.com/learning/ddos/dns-amplification-ddos-attack/" rel="noopener noreferrer"&gt;DNS amplification attacks&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Responsibility: Recursive vs Iterative
&lt;/h2&gt;

&lt;p&gt;In recursive resolution, the burden of having to contact nameservers belongs to the server. On the flip side, for iterative resolution, the burden of contacting nameservers belongs to the client.&lt;/p&gt;

&lt;h2&gt;
  
  
  DNS Resolver Observation
&lt;/h2&gt;

&lt;p&gt;It should be noted that for both recursive and iterative resolution, it is required that the DNS resolver already know the IP addresses of the 13 root servers. Implementation wise, these addresses are simply hardcoded and &lt;a href="https://root-servers.org/" rel="noopener noreferrer"&gt;publicly available&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>dns</category>
      <category>networking</category>
      <category>domains</category>
      <category>internet</category>
    </item>
    <item>
      <title>DNS Explained. The RRR Model</title>
      <dc:creator>Blake K</dc:creator>
      <pubDate>Sun, 06 Sep 2020 04:05:01 +0000</pubDate>
      <link>https://dev.to/blake/dns-explained-the-rrr-model-3dkc</link>
      <guid>https://dev.to/blake/dns-explained-the-rrr-model-3dkc</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is an article in the &lt;em&gt;DNS Explained.&lt;/em&gt; series. Click &lt;a href="https://dev.to/blake/dns-explained-introduction-history-1an7"&gt;here&lt;/a&gt; to read the introduction post. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;DNS isn't all technical. At its core, there is a lot of policy and thus jargon created. The intent of this post is to clear up some of the most commonly used jargon relating to entities in DNS.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FK41K3cR.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FK41K3cR.png" alt="Diagram of the RRR model."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are three main stakeholders in the DNS ecosystem. Together, they form the RRR (triple-R) Model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Registrants&lt;/strong&gt; are the individuals and organizations that register a domain name. &lt;/p&gt;

&lt;p&gt;They obtain a domain name from a registrar by paying the price that that particular registrar sets. If a potential registrant thinks that a registrar's price is too high, they can look at another registrar (competition!).&lt;/p&gt;

&lt;p&gt;If Alice registers the domain name “alice.rocks”, then Alice is considered as the registrant for the domain name “alice.rocks”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Registrars&lt;/strong&gt; are third-party organizations that "sell" domain names to registrants. &lt;/p&gt;

&lt;p&gt;Domain names are not really sold but rather rented on an annual basis. The maximum length of a registrant’s active registration depends on the policy of the specific TLD, but usually is 10 years. &lt;/p&gt;

&lt;p&gt;Registrars are also the bridge between registrants and registries, because they have to interface with the specific TLD's registry to submit the domain creation. &lt;/p&gt;

&lt;p&gt;Before registrars were established, a TLD’s registry would act as the registrar. This didn’t permit much competition, so the concept of a registrar was adopted.&lt;/p&gt;

&lt;p&gt;Some notable registrars include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GoDaddy&lt;/li&gt;
&lt;li&gt;NameCheap&lt;/li&gt;
&lt;li&gt;101domain&lt;/li&gt;
&lt;li&gt;Network Solutions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Registries&lt;/strong&gt; operate the backend infrastructure for a top-level domain and process domain creations, renewals, expirations, deletions, and transfers. &lt;/p&gt;

&lt;p&gt;Their customers are registrars, who then sell to registrants. Since registries need to make money too, there is a wholesale cost for new domain creations, among other fees that are charged to registrars.&lt;/p&gt;

&lt;p&gt;There is a single registry for each TLD. The organization ICANN &lt;a href="https://www.icann.org/resources/pages/registries/registries-agreements-en" rel="noopener noreferrer"&gt;designates via contract&lt;/a&gt; the sole registry for each TLD.&lt;/p&gt;

&lt;p&gt;Some notable TLDs and their corresponding registries are:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;TLD&lt;/th&gt;
&lt;th&gt;Registry&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;.com&lt;/td&gt;
&lt;td&gt;Verisign&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;.net&lt;/td&gt;
&lt;td&gt;Verisign&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;.org&lt;/td&gt;
&lt;td&gt;Public Interest Registry&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;.gov&lt;/td&gt;
&lt;td&gt;General Services Administration&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;.coffee&lt;/td&gt;
&lt;td&gt;Donuts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;.tv&lt;/td&gt;
&lt;td&gt;Verisign&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;.site&lt;/td&gt;
&lt;td&gt;Radix&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;.me&lt;/td&gt;
&lt;td&gt;DoMEn d.o.o&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Registrants, registrars, and registries make up the RRR model within DNS. Registrants are end-customers leasing a domain name. The organizations that offer the means to obtain a domain name are registrars. Registrars have to communicate with the backend systems of each TLD they want to offer, which are managed by the TLD's registry.&lt;/p&gt;

</description>
      <category>dns</category>
      <category>networking</category>
      <category>rrr</category>
      <category>domain</category>
    </item>
    <item>
      <title>DNS Explained. Hierarchy and Architecture</title>
      <dc:creator>Blake K</dc:creator>
      <pubDate>Tue, 28 Jul 2020 16:56:49 +0000</pubDate>
      <link>https://dev.to/blake/dns-explained-hierarchy-and-architecture-18pj</link>
      <guid>https://dev.to/blake/dns-explained-hierarchy-and-architecture-18pj</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is an article in the &lt;em&gt;DNS Explained.&lt;/em&gt; series. Click &lt;a href="https://dev.to/blake/dns-explained-introduction-history-1an7"&gt;here&lt;/a&gt; to read the introduction post. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the first post for this series, I described DNS being both hierarchical and decentralized. In this post, we will dive into what that really means.&lt;/p&gt;

&lt;h1&gt;
  
  
  DNS is Hierarchical
&lt;/h1&gt;

&lt;p&gt;Hierarchy is obtained through levels of domains, starting at the root server (represented by a period ".").&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FxOdVIPZ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FxOdVIPZ.png" alt="A tree showcasing the levels of domains that DNS provides."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may have heard of top-level domains (TLDs) before. Some examples of TLDs include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;.com&lt;/li&gt;
&lt;li&gt;.net&lt;/li&gt;
&lt;li&gt;.org&lt;/li&gt;
&lt;li&gt;.us&lt;/li&gt;
&lt;li&gt;.de&lt;/li&gt;
&lt;li&gt;.coffee&lt;/li&gt;
&lt;li&gt;.ninja&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They are called top-level domains because well, they are at the top level (excluding the root)! Organizations can register second-level domains under &lt;a href="https://data.iana.org/TLD/tlds-alpha-by-domain.txt" rel="noopener noreferrer"&gt;any valid TLD&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Because DNS is hierarchical, that means that two separate second-level domains can both use the same third-level domain For example, &lt;code&gt;mail.google.com&lt;/code&gt; and &lt;code&gt;mail.yahoo.com&lt;/code&gt; are both allowed because the uniqueness of the third level domain is limited to the scope of the second-level domain. This was not possible under the predecessor hosts.txt system.&lt;/p&gt;

&lt;h1&gt;
  
  
  Root Zone Servers
&lt;/h1&gt;

&lt;p&gt;In the above graphic, I introduced a new DNS concept called the root server. The root is the base of the DNS hierarchy tree. While I described it as a single point, it is actually more than that.&lt;/p&gt;

&lt;p&gt;In reality, the root server is called the Root Zone servers. It's called the Root Zone because there are actually 13 Root servers. These servers are spread out geographically and are the starting place for traversing DNS via resolution.&lt;/p&gt;

&lt;p&gt;ICANN appoints operators for these 13 root servers. There are 12 total operators.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Host name&lt;/th&gt;
&lt;th&gt;IP Addresses&lt;/th&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;a.root-servers.net&lt;/td&gt;
&lt;td&gt;198.41.0.4, 2001:503:ba3e::2:30&lt;/td&gt;
&lt;td&gt;Verisign, Inc.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;b.root-servers.net&lt;/td&gt;
&lt;td&gt;199.9.14.201, 2001:500:200::b&lt;/td&gt;
&lt;td&gt;University of Southern California, Information Sciences Institute&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;c.root-servers.net&lt;/td&gt;
&lt;td&gt;192.33.4.12, 2001:500:2::c&lt;/td&gt;
&lt;td&gt;Cogent Communications&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;d.root-servers.net&lt;/td&gt;
&lt;td&gt;199.7.91.13, 2001:500:2d::d&lt;/td&gt;
&lt;td&gt;University of Maryland&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;e.root-servers.net&lt;/td&gt;
&lt;td&gt;192.203.230.10, 2001:500:a8::e&lt;/td&gt;
&lt;td&gt;NASA (Ames Research Center)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;f.root-servers.net&lt;/td&gt;
&lt;td&gt;192.5.5.241, 2001:500:2f::f&lt;/td&gt;
&lt;td&gt;Internet Systems Consortium, Inc.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;g.root-servers.net&lt;/td&gt;
&lt;td&gt;192.112.36.4, 2001:500:12::d0d&lt;/td&gt;
&lt;td&gt;US Department of Defense (NIC)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;h.root-servers.net&lt;/td&gt;
&lt;td&gt;198.97.190.53, 2001:500:1::53&lt;/td&gt;
&lt;td&gt;US Army (Research Lab)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;i.root-servers.net&lt;/td&gt;
&lt;td&gt;192.36.148.17, 2001:7fe::53&lt;/td&gt;
&lt;td&gt;Netnod&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;j.root-servers.net&lt;/td&gt;
&lt;td&gt;192.58.128.30, 2001:503:c27::2:30&lt;/td&gt;
&lt;td&gt;Verisign, Inc.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;k.root-servers.net&lt;/td&gt;
&lt;td&gt;193.0.14.129, 2001:7fd::1&lt;/td&gt;
&lt;td&gt;RIPE NCC&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;l.root-servers.net&lt;/td&gt;
&lt;td&gt;199.7.83.42, 2001:500:9f::42&lt;/td&gt;
&lt;td&gt;ICANN&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;m.root-servers.net&lt;/td&gt;
&lt;td&gt;202.12.27.33, 2001:dc3::35&lt;/td&gt;
&lt;td&gt;WIDE Project&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;You may be asking yourself, how do hosts and resolvers know about these 13 root servers? The answer is simple: they're hardcoded!&lt;/p&gt;

&lt;p&gt;You can view the locations of all the root zone servers &lt;a href="https://root-servers.org/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  DNS is Decentralized
&lt;/h1&gt;

&lt;p&gt;This hierarchical structure of domain levels permits decentralization too. DNS is decentralized in terms of not a single party is responsible for providing the nameservers at each level.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FYfJOzH3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FYfJOzH3.png" alt="A tree showcasing the different name server operators."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At each second-level domain, there are a set of nameservers. These nameservers are used during resolution to provide the IP addresses of third+ level domains within the scope of that specific second-level domain.&lt;/p&gt;

&lt;p&gt;Since the scope is limited to that particular second-level domain, the registry of the TLD does not need to operate this, and instead, the responsibility is given to the second-level domain registrant to provide this functionality.&lt;/p&gt;

&lt;p&gt;If the domain registrant does not want the responsibility of providing their own nameservers, there exist third-party companies that offer managed DNS services. &lt;a href="https://www.cloudflare.com/dns/" rel="noopener noreferrer"&gt;Cloudflare&lt;/a&gt; is one of the largest managed DNS providers. Most registrars also offer this service.&lt;/p&gt;

&lt;h1&gt;
  
  
  Observations
&lt;/h1&gt;

&lt;p&gt;We can make a few observations about DNS from the fact that it is both hierarchical and decentralized.&lt;/p&gt;

&lt;p&gt;Firstly, DNS is scalable due to its hierarchy. By having "zones" of TLDs, the infrastructure for each zone can be spread out and independently scaled. This is great because some TLDs have more registrations than others.&lt;/p&gt;

&lt;p&gt;Secondly, since the hierarchy begins with the root, and the root is represented by a period, the fully qualified domain name (FQDN) technically ends with a period too. This is official and was documented in &lt;a href="https://tools.ietf.org/html/rfc1034" rel="noopener noreferrer"&gt;RFC 1034&lt;/a&gt;. You can try it out in your browser and verify that it still works: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;smile.amazon.com.&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;www.google.com.&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dev.to./blake&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, FQDNs are parsed from right to left. This is because the root starts on the right-hand side, and the lowest level is on the left-hand side.&lt;/p&gt;

</description>
      <category>dns</category>
      <category>architecture</category>
      <category>domain</category>
      <category>networking</category>
    </item>
    <item>
      <title>DNS Explained. Introduction/History</title>
      <dc:creator>Blake K</dc:creator>
      <pubDate>Tue, 28 Jul 2020 16:56:24 +0000</pubDate>
      <link>https://dev.to/blake/dns-explained-introduction-history-1an7</link>
      <guid>https://dev.to/blake/dns-explained-introduction-history-1an7</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Imagine this scenario.&lt;/p&gt;

&lt;p&gt;Netflix has a lot of fresh content being released. You decide that you want to watch the next season of &lt;a href="https://www.netflix.com/title/80241248"&gt;&lt;em&gt;The Politican&lt;/em&gt;&lt;/a&gt;. So, you open up your favorite browser, type in &lt;code&gt;netflix.com&lt;/code&gt;, and hit enter. Almost instantly, Netflix's profile selection screen pops up. &lt;/p&gt;

&lt;p&gt;You probably already know that an HTTP(S) request over a TCP connection is made to Netflix's servers and that Netflix sends back a HTTP(S) response, which is eventually rendered by your browser as the screen you end up seeing. However, a key part is missing here. &lt;/p&gt;

&lt;p&gt;In order to make a TCP connection, you need four things:&lt;/p&gt;

&lt;p&gt;1) The Source IP&lt;br&gt;
2) The Source Port Number&lt;br&gt;
3) The Destination IP&lt;br&gt;
4) The Destination Port Number&lt;/p&gt;

&lt;p&gt;The above four requirements are often referred to as the "TCP 4-Tuple". Now, you already have the source IP and port number, because you are the source! And thanks to &lt;a href="https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml"&gt;IANA&lt;/a&gt;, the destination port number is already known based on the protocol used (HTTP: 80/HTTPS: 443).&lt;/p&gt;

&lt;p&gt;The only thing missing to make the TCP connection is the destination IP address. DNS is how you obtain it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do we have domain names?
&lt;/h2&gt;

&lt;p&gt;First of all, why do we even have domain names? If we typed the destination IP address, the problem of obtaining the IP address wouldn't exist.&lt;/p&gt;

&lt;p&gt;This is correct, but would involve the end-user memorizing the IP addresses of all the sites they wish to visit. You could probably memorize a few IPv4 addresses, but good luck memorizing 5+, or even a single IPv6 address.&lt;/p&gt;

&lt;p&gt;Domain names exist so humans don't have to memorize IP addresses. In addition, IP addresses for hosts can change; having a domain name point automatically to the updated address is really handy.&lt;/p&gt;

&lt;h2&gt;
  
  
  History
&lt;/h2&gt;

&lt;p&gt;Before diving straight into DNS, it is beneficial to know the history of the system and the motivations behind its creation.&lt;/p&gt;

&lt;p&gt;The predecessor of DNS was the &lt;code&gt;hosts.txt&lt;/code&gt; file for ARPANET (the predecessor of the Internet). This plain-text file was centrally maintained by the Stanford Research Institute and mapped domain names to addresses of computers on ARPANET. Since the number of hosts on ARPANET was under 1,000 at the time, it was a sufficient solution to mapping domain names. However, there were significant drawbacks.&lt;/p&gt;

&lt;p&gt;The first drawback is that updates to the file were manually processed by hand. This resulted in long initial delays.&lt;/p&gt;

&lt;p&gt;Second, once the original file at Stanford was updated, all hosts on ARPANET also had to have an updated copy of the hosts.txt file. This resulted in propagation times being measured in the span of &lt;em&gt;days&lt;/em&gt;. Imagine not having your domain name be accessible for days after you submit an update!&lt;/p&gt;

&lt;p&gt;Third, once a domain was claimed, nobody else could have it. If MIT claimed "mail", then George Washington University could not claim "mail". There was no hierarchy, so great domain names couldn't be used by multiple organizations (like "mit.mail" "gwu.mail" which are possible today).&lt;/p&gt;

&lt;p&gt;As you can imagine, this simple file "system" wasn't going to cut it for when the future internet comes around with thousands of hosts. A new scalable and automatic system had to be made and put in place.&lt;/p&gt;

&lt;h2&gt;
  
  
  Defining DNS
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Domain_Name_System"&gt;Wikipedia&lt;/a&gt; defines DNS as, "a hierarchical and decentralized naming system for computers, services, or other resources connected to the Internet or a private network."&lt;/p&gt;

&lt;p&gt;I don't know about you, but this definition doesn't really tell me much. Let's reword that a bit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DNS is a hierarchical naming system that maps strings (called fully-qualified domain names or FQDN) to values called resource records (which can contain a corresponding IP address).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Simply put, you query DNS with a domain name (e.g. &lt;a href="http://www.netflix.com"&gt;www.netflix.com&lt;/a&gt;) and DNS will eventually return an IP address back to you. This returned value is the destination IP address needed to complete the TCP 4-Tuple.&lt;/p&gt;

&lt;h2&gt;
  
  
  Diving Deeper
&lt;/h2&gt;

&lt;p&gt;DNS at its core is a key-value system where the key is a fully-qualified domain name and the value is a resource record. Though DNS has additional components that are vital to the overall health and performance of the system.&lt;/p&gt;

&lt;p&gt;We have described a real-life use case for DNS, in addition to briefly going over the need for domains in general, DNS' history and technical definition. Keep reading the "DNS Explained." series to dive deeper into more DNS topics including the RRR model and resolution!&lt;/p&gt;

</description>
      <category>networking</category>
      <category>dns</category>
      <category>network</category>
      <category>domain</category>
    </item>
    <item>
      <title>Searching &amp; Sorting w/ Binary Search Trees</title>
      <dc:creator>Blake K</dc:creator>
      <pubDate>Fri, 05 Apr 2019 23:29:19 +0000</pubDate>
      <link>https://dev.to/blake/searching-sorting-w-binary-search-trees-3354</link>
      <guid>https://dev.to/blake/searching-sorting-w-binary-search-trees-3354</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Binary Search Trees are an incredibly useful data structure that holds comparable values in a particular order. &lt;/p&gt;

&lt;p&gt;With this particular ordering, it allows for fast lookups and a straightforward way to sort the values in the tree.&lt;/p&gt;

&lt;p&gt;Regarding use cases, Binary Search Trees are one of the bases for more abstract data structures such as &lt;a href="https://en.wikipedia.org/wiki/Set_(abstract_data_type)" rel="noopener noreferrer"&gt;sets&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Associative_array" rel="noopener noreferrer"&gt;maps&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Definitions&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Before we talk about searching and sorting with Binary Search Trees (BSTs), let's make sure we're on the same page regarding terminology.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;Node&lt;/strong&gt; holds&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A value.&lt;/li&gt;
&lt;li&gt;References to other nodes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A &lt;strong&gt;Tree&lt;/strong&gt; is a data structure that has&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One parent node.&lt;/li&gt;
&lt;li&gt;Zero, one, or multiple child nodes.&lt;/li&gt;
&lt;li&gt;No duplicate nodes.&lt;/li&gt;
&lt;li&gt;No node that references previously defined nodes (i.e. no looping).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A tree is implemented as one root node, consisting of children of subtrees that have the properties above.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A parent node is considered as the root node of that specific subtree.&lt;/li&gt;
&lt;li&gt;The root node is the starting node for the entire tree.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you hear the term "Binary Tree", you might feel a little intimidated! But worry not, it's a straightforward concept to grasp.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;Binary Tree&lt;/strong&gt; is a tree with&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;At most two child nodes (one left, one right) for any parent node.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let's define what this entire post is about - Binary Search Trees.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;Binary Search Tree&lt;/strong&gt; is a particular type of binary tree where &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The left child node is less than the parent node.&lt;/li&gt;
&lt;li&gt;The right child node is greater than the parent node. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Implementation&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The following code samples are written in C.&lt;/p&gt;

&lt;p&gt;We can represent a Node as a structure containing fields holding a value (in this case an integer), and pointers to the left and right child nodes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Node Structure
typedef struct node {
    struct node *left; // Pointer pointing to left child node.
    struct node *right; // Pointer pointing to right child node.
    int val; // The value the node is holding.
} node_t;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Sorting&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;There are different ways that you can traverse a tree. There is &lt;a href="https://en.wikipedia.org/wiki/Tree_traversal#Pre-order_(NLR)" rel="noopener noreferrer"&gt;pre-order&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Tree_traversal#In-order_(LNR)" rel="noopener noreferrer"&gt;in-order&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Tree_traversal#Out-order_(RNL)" rel="noopener noreferrer"&gt;out-order&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Tree_traversal#Post-order_(LRN)" rel="noopener noreferrer"&gt;post-order&lt;/a&gt;, etc. As this post is specifically about Binary Search Trees, we're not going to go into too much detail about generic tree traversals. However, &lt;strong&gt;in-order traversal&lt;/strong&gt; plays a significant role in BSTs.&lt;/p&gt;

&lt;p&gt;In-order traversal follows the pattern &lt;code&gt;LEFT PARENT RIGHT&lt;/code&gt;.&lt;br&gt;
Let's take the following BST as an example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FIT0I6cK.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FIT0I6cK.png" alt="BST: 5, 3, 7"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you traverse the BST using in-order traversal, you'll start with the left node (3), move back to the parent node (5) and end with the right node (7), resulting in 3, 5, 7.&lt;/p&gt;

&lt;p&gt;Take a look at that result, does anything stick out to you? In case you didn't notice, it returned a sorted result!&lt;/p&gt;

&lt;p&gt;This property of the in-order traversal result is no coincidence.&lt;/p&gt;

&lt;p&gt;Try it with any BST; you will always end up with a sorted result. Not convinced? Let's try it one more time with a more complex BST.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FRUE2Ynr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FRUE2Ynr.png" alt="BST: 50, 27, 99, 7, 42, 84"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember that in-order traversal goes like this: Left, Parent, Right.&lt;/p&gt;

&lt;p&gt;So starting at 50, go left to 27. 27 has a left child (7), so go there next. 7 doesn't have a left child so that's our first entry. Then move up back to 7's parent (27) which is our second entry, then go to 27's right child (42) which is now our third entry.&lt;/p&gt;

&lt;p&gt;So far, our result is:&lt;br&gt;
&lt;code&gt;7, 27, 42&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, we're done with the subtree where 27 is the root. 50 is the parent of 27, so that's our fourth entry. We then head to 50's right child, 99. However, 99 has a left child (84), so we go there instead. 84 is now our fifth entry. We then go to 84's parent (99) which is our sixth entry. Then we go to 99's right child, which doesn't exist - so we're done!&lt;/p&gt;

&lt;p&gt;Our result from the in-order traversal is:&lt;br&gt;
&lt;code&gt;7, 27, 42, 50, 84, 99&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Would you look at that, it's completely sorted!&lt;/p&gt;

&lt;p&gt;Here's a C implementation of in-order traversal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void printInOrder(node_t *parent) {
    // Safety Check.
    if (parent == NULL) {
        return;
    }

    // Print Left Subtree.
    printInOrder(parent-&amp;gt;left);

    // Print Parent.
    printf("%d, ", parent-&amp;gt;val);

    // Print Right Subtree.
    printInOrder(parent-&amp;gt;right);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this recursive implementation, we check if the provided Node is &lt;code&gt;NULL&lt;/code&gt; or not. This is our base case.&lt;/p&gt;

&lt;p&gt;We then recursively call our in-order function on the left child. This will continue calling until there are no more left-children. Then, it will print the current (left) node value. Afterwards, it will again recursively call our in-order function for the right-children.&lt;/p&gt;

&lt;p&gt;What we end up with is the values of our provided BST printed out sorted.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Searching&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If we want to search for a provided value in a BST, how would we do it?&lt;/p&gt;

&lt;p&gt;Searching takes advantage of three features of BSTs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There are no duplicates.&lt;/li&gt;
&lt;li&gt;Values can be compared to each other.&lt;/li&gt;
&lt;li&gt;Values to the left are smaller than the parent, and values to the right are greater than the parent.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We start searching at the root node. If the provided value matches the value of the root node, we can simply return because the value has been found. &lt;/p&gt;

&lt;p&gt;But if the value isn't a match, we have two options: traverse left or traverse right.&lt;/p&gt;

&lt;p&gt;Which should we do?&lt;/p&gt;

&lt;p&gt;Well, if the provided value is less than the current node we are looking at, we search left. Otherwise, we search right. This property of having lesser values as the left-child and greater values as the right-child unqiuely defines a Binary Search Tree, so take advantage of it!&lt;/p&gt;

&lt;p&gt;In C, this &lt;code&gt;contains&lt;/code&gt; function is implemented as so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool contains(node_t *parent, const int *value) {
    // Safety Check.
    if (parent == NULL) {
        return false;
    }

    // Found match!
    if (parent-&amp;gt;val == *value) {
        return true;
    }

    // Check left subtree.
    if (*value &amp;lt; parent-&amp;gt;val) {
        return contains(parent-&amp;gt;left, value);
    }

    // Check right subtree.
    return contains(parent-&amp;gt;right, value);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not only is this data structure favored for its search efficiency, it's also preferred for its ease of implementation. The search function can be implemented recursively.&lt;/p&gt;

&lt;p&gt;As you can see in the implementation, we disregard the right subtree if the value we are looking for is less than that subtree's parent value. Likewise, we disregard the left subtree if the value we are searching for is greater than the subtree's parent value.&lt;/p&gt;

&lt;p&gt;Since we either search left or right until the provided value is found, we on average search only half of the nodes in the BST. This makes the average efficiency of searching in a BST &lt;code&gt;O(log n)&lt;/code&gt;.The worst case is &lt;code&gt;O(n)&lt;/code&gt; where all nodes need to be searched (this is where &lt;a href="https://en.wikipedia.org/wiki/Self-balancing_binary_search_tree" rel="noopener noreferrer"&gt;self-balancing trees&lt;/a&gt; would be useful).&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Full Demo&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you'd like to try out or view the full C implementation demo that includes some testing, &lt;a href="https://gist.github.com/heyimblake/122d9e519b18266e4f24cbe5e550dcbe" rel="noopener noreferrer"&gt;click here&lt;/a&gt;!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Wrapping things Up&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Binary Search Trees are useful data structures when it comes to searching and sorting. By taking advantage of in-order traversal and the properties of this special tree, you can implement both searching and sorting functions not only efficiently, but also easily.&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>c</category>
      <category>datastructures</category>
      <category>computerscience</category>
      <category>algorithms</category>
    </item>
  </channel>
</rss>
