If you are a backend developer or if you’re a web developer in today’s time, this article is super important for you. Because in this article we’ll be talking about how do websites really work on a DNS level. What are the top three DNS that you should know about, which allows you to bring your project live and all about that. Let’s go ahead and discuss that. Make sure you read it till the end.
So building a website from scratch, programming it with any framework or anything is one job. But actually bringing that website live is a completely different task. Whether how you set up the domain, the SSL part, DNS, everything should be in place. In this one, I want to talk a bit about how do domains work.
DNS (Domain Name System)
In DNS, there are three records I want to talk about. They are –
1) A Record
2) CNAME Record
3) NS Record
These three records are super important in DNS. Of course, there are a lot more records that exist, but these three records are super important because they allow your website to be functional.
1. A record in Websites
Let’s talk about a record first of all. Now let’s say you own the domain, xyz.com for example. You have bought it using some sort of domain register whether that’s GoDaddy oranything and you want to make your website live. One of the things which you have to do is you have to somehow map this Domain name to an IP address. That is the easiest way to make your website live. The easiest and a kind of the only way possible. Because your domain name actually needs an IP address.
For the IP address let’s say you hosted you started a new EC2 server in AWS and when you create an EC2 server AWS automatically gives you a public IP address IPV 4, which would look something like 137. something point, something point. It could be pretty much anything. Now, in order to map this domain name to this IP address, what we have to do is in your domain register you have to create an a record where your domain name which is the main domain sometimes referred as at the rate. Sometimes it is referred as the full domain. It is you know what needs to be mapped and then there’s field for IP address where you would enter this 137. something, something right away.
Now the way this would work is, whenever your computer, whenever somebody in the world, this client would ask to visit our domain which is xyz.com. Their browser would try to make their way to the DNS server all along the way to figure out what is the IP address of xyz.com. This is the last record they will hit. I mean if this record is present, this is what your browser would eventually get back. This is what your browser will also show in the networks tab in the browser. When you inspect to get a network tab and you click on that time you see the source IP address. That IP address is a record which was entered in your DNS.
2. CName Record in Websites
So now you have created a record for your root domain, you know, let’s say this IP address, 126.96.36.199. Now let’s say you are creating a subdomain called magic.xyz.com and what you are trying to do is that you want this domain to also point to xyz.com for some reason. Now some websites do this because they are your hosting provider. For example if you are hosting Vercel , you would have seen that you have to enter something known as cname.vercel-dns.com. In other cases, you might have your own custom use case, but the point I am trying to make is that if you go to your DNS now and if you try to enter magic as a cname record in your DNS and enter the domain as xyz.com, so what you have essentially done is not provided an IP address to magic.xyz.com.
In this case for the root domain, you created on a record with an IP address mapping but for the magic part of the magic domain you just created a cname for magic. So what this right here means is that this would be the record which would be returned when some random find client tries to connect to your system, but at the end of the chain, cname of magic called means that your DNS provider would perform one last request and go to xyz.com to see what is the IP address of xyz.com. So this in nutshell is actually equivalent to writing a record of magic and then 188.8.131.52. But it is almost like it’s dynamic in nature because if sometime later you change the IP address xyz.com, you don’t need to update this particular record. This record would automatically get propagated depending on what the value of xyz.com.
3. NS Record in Websites
The final record is also important but not really. In real-world scenarios, it’s not as important for the domain management part because you usually have to do it just once. But this is still important because the name server record actually gives the ownership of a particular subdomain and all of its subdomains to another provider.
So let’s say you have something like go.xyz.com record as a name server to something like ns1.xyz.com. And this ns1.xyz.com has an a record of some IP address say 3.4.5. This part is very interesting because what’s happening over here that what you are essentially saying is that if I visit abc.go.xyz.com, what the browser and what the whole universe of Domain Name System will try to do is that it will go to this particular record. It will see the name server of code of go.xyz.com and everything beyond that, I mean in terms of subdomain is handled by this particular server. The IP address of this particular name server is defined by our a record.
So the query for this particular IP address to extract out what exactly is the IP address of this domain goes to a server running on ec2. Assuming this the ec2 server and if you have opened a DNS server on port 53 then actually it is your responsibility to return the IP address of that particular domain is.This is why you would not really see using this as your custom domain. Usually, it will be provided by your own DNS provider, like Cloudflare or something. But in case you wanted to create your own DNS system, the way you would do it is you adda nameserver record to the branch where you want the DNS to be controllable. Then you add a nameserver, add an a record. The machine actually should be listening to port 53, at least UDP. And this should be responsible to return there would be DNS query and it should return answer back that DNS query. And whatever that answers back would be the resolved IP address of that particular domain. So it answers backs for example 184.108.40.206 it would probably see a Cloudflare page rather than the Cloudflare error page. So in the browser window in the network tab, you will actually see 220.127.116.11 as the resolved IP address.
So just to summarize, DNS is an extremely important networking part that you should know as a developer. I hope these three records taught you something new today. If you have any questions, let me know in the comment section.