Skip to content

Instantly share code, notes, and snippets.

@024x
Last active August 15, 2023 03:29
Show Gist options
  • Select an option

  • Save 024x/9b6ee97be13a53e0dfb6fafcd100297e to your computer and use it in GitHub Desktop.

Select an option

Save 024x/9b6ee97be13a53e0dfb6fafcd100297e to your computer and use it in GitHub Desktop.
Very Basic DNS Explanation for absolute beginners - A gist that explains the very basic concept of DNS (Domain Name System) for absolute beginners with examples - Satyendra

Domain Name System (DNS):

Imagine that you want to visit a friend's house, but you don't know their address. You only know their name and phone number. How would you find their house?

You could call them and ask for their address, right? But that would be inconvenient and time-consuming, especially if you have many friends and you want to visit them often. Wouldn't it be easier if you had a book that lists all your friends' names and addresses, so that you can just look them up whenever you want?

That's what DNS does for the Internet. It is a system that keeps a record of all the domain names (like www.google.com) and their corresponding IP addresses (like 216.58.216.164), so that you can find any website or service on the Internet by just typing its name in your web browser or other application.

But DNS is not just one book, it is a network of many books, or servers, that are distributed all over the world. Each server has a copy of some or all of the DNS records, and they can communicate with each other to update and synchronize their information. This way, DNS can handle millions of requests every day, and provide fast and reliable service.

DNS is a system that helps us to find the addresses of computers and other devices on the Internet. DNS stands for Domain Name System, and it works like a phone book that maps names to numbers. For example, when you type www.google.com in your web browser, DNS helps you to find the IP address of the server that hosts the Bing website. IP address is a unique number that identifies a device on the Internet, such as 216.58.216.164.

There are different types of DNS records, depending on what kind of information they store. Here are some of the most common ones:

  • A record:

    This is like the basic entry in the book, that tells you the address of your friend's house. It maps a domain name to an IP address. For example, an A record for www.google.com would tell you that its IP address is 216.58.216.164.
    (This is the most basic type of DNS record, and it stands for Address record. It maps a domain name to an IP address. For example, an A record for www.google.com would point to 216.58.216.164.)

  • TXT record:

    This is like a note that you can attach to the entry in the book, that gives you some extra information about your friend or their house. It can be used for various purposes, such as verifying that you are really their friend, providing some security details, or adding some comments. For example, a TXT record for bing.com could tell you that it uses SPF to prevent email spoofing.
    (This is a type of DNS record that allows you to store text information related to a domain name. It can be used for various purposes, such as verifying the ownership of a domain, providing security information, or adding notes. For example, a TXT record for bing.com could contain the text "v=spf1 include:spf.protection.outlook.com -all", which is used to prevent email spoofing.)

  • CNAME record:

    This is like an alias or a nickname that your friend uses, instead of their real name. It maps a domain name to another domain name, instead of an IP address. It can be used to create subdomains or shortcuts for a domain name. For example, a CNAME record for mail.bing.com could tell you that it is actually outlook.office365.com, which is the real name of the email service.
    (This is a type of DNS record that stands for Canonical Name record. It maps a domain name to another domain name, instead of an IP address. It can be used to create aliases or subdomains for a domain name. For example, a CNAME record for mail.bing.com could point to outlook.office365.com, which is the actual domain name of the email service.)

  • MX record:

    This is like the entry in the book that tells you where to send mail or packages to your friend's house. It specifies the mail servers that are responsible for receiving and delivering email messages for a domain name. It also assigns a priority value to each mail server, so that you can use the most preferred one first. For example, an MX record for bing.com could tell you to send mail to bing-com.mail.protection.outlook.com with a priority of 0, which means it is the highest priority mail server.
    (This is a type of DNS record that stands for Mail Exchange record. It specifies the mail servers that are responsible for receiving and delivering email messages for a domain name. It also assigns a priority value to each mail server, so that the most preferred one can be used first. For example, an MX record for bing.com could point to bing-com.mail.protection.outlook.com with a priority of 0, which means it is the highest priority mail server.)

There are also some other terms related to DNS that you should know:

  • TTL:

    This stands for Time To Live, and it is like the expiration date of the entry in the book. It tells you how long you can keep the information in your memory or cache, before you have to look it up again from the server. This can improve the speed and efficiency of finding your friend's house, but it also means that any changes to their address may not be reflected immediately. The TTL value is measured in seconds, and it can vary depending on the type and purpose of the entry. For example, an A record for www.google.com may have a TTL of 300 seconds, which means you can keep it in your cache for up to 5 minutes.
  • Proxy:

    This is like a middleman or a messenger that helps you to communicate with your friend's house. A proxy can perform various functions, such as filtering, caching, modifying, or encrypting the messages that pass through it. A proxy can also hide or change your address or your friend's address, which can provide anonymity or security benefits. For example, you may use a proxy service to visit a website that is blocked in your country, or to protect your identity online.

Creating a subdomain

A subdomain is a part of a domain name that can be used to organize or categorize different sections of a website. For example, if your domain name is example.com, you can create a subdomain called blog.example.com for your blog section, or shop.example.com for your online store section.

To create a subdomain, you need to have access to your domain name registrar or web host, where you can manage your DNS records. DNS stands for Domain Name System, and it is a system that helps us to find the addresses of computers and other devices on the Internet. DNS records are like entries in a phone book that map names to numbers. For example, an A record maps a domain name to an IP address, which is a unique number that identifies a device on the Internet.

Depending on your domain name registrar or web host, the steps to create a subdomain may vary slightly, but the general process is as follows:

  • Navigate to your domain name registrar or web host and log in to your account.
  • Select domains from your account dashboard and find the domain name that you want to create a subdomain for.
  • Select the option to add or manage subdomains. This may be under advanced DNS settings, or under a separate subdomains section.
  • Enter the name of your subdomain in the field provided. This is usually the prefix of the subdomain, such as blog or shop. Do not include the main domain name or the dot (.) after the prefix.
  • Choose the type of DNS record that you want to create for your subdomain. The most common type is A record, which points your subdomain to an IP address. You can also use other types of records, such as CNAME, which points your subdomain to another domain name, or MX, which specifies the mail servers for your subdomain.
  • Enter the value of the DNS record that you want to create for your subdomain. This is usually the IP address or the domain name that you want your subdomain to point to. For example, if you want blog.example.com to point to 192.168.0.1, you would enter 192.168.0.1 as the value of the A record.
  • Optionally, enter the TTL (Time To Live) value for your DNS record. This is a number that determines how long your DNS record can be cached by other servers or clients before it needs to be updated. The default value is usually 1 hour (3600 seconds), but you can change it if you want.
  • Save your changes and wait for them to propagate. This may take up to 48 hours for your new subdomain to be visible and accessible on the Internet.

Choosing the right DNS record type for your subdomain

It depends on what you want to achieve with your subdomain. Here are some common scenarios and the corresponding DNS record types that you can use:

  • If you want to point your subdomain to an IP address, such as a web server or a cloud service, you can use an A record or an AAAA record. An A record is for IPv4 addresses, and an AAAA record is for IPv6 addresses. For example, if you want to create a subdomain called blog.example.com and point it to the IP address 192.168.0.1, you can use an A record like this:

    blog.example.com. 3600 IN A 192.168.0.1

  • If you want to point your subdomain to another domain name, such as a third-party service or a CDN, you can use a CNAME record. A CNAME record is an alias that redirects your subdomain to another domain name. For example, if you want to create a subdomain called shop.example.com and point it to a Shopify store called example-store.myshopify.com, you can use a CNAME record like this:

    shop.example.com. 3600 IN CNAME example-store.myshopify.com.

  • If you want to use your subdomain for email purposes, such as sending or receiving emails, you can use an MX record or a TXT record. An MX record specifies the mail servers that handle the email messages for your subdomain. A TXT record can be used to store additional information for email security, such as SPF, DKIM, or DMARC. For example, if you want to create a subdomain called mail.example.com and use it for email with Google Workspace, you can use an MX record and a TXT record like this:

    mail.example.com. 3600 IN MX 1 ASPMX.L.GOOGLE.COM. mail.example.com. 3600 IN MX 5 ALT1.ASPMX.L.GOOGLE.COM. mail.example.com. 3600 IN TXT "v=spf1 include:_spf.google.com ~all"

    There are also other types of DNS records that you can use for different purposes, such as NS, SOA, SRV, PTR, NAPTR, etc.

If you want to learn more, you can check out these links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment