Check out a free preview of the full Full Stack for Front-End Engineers, v3 course
The "DNS & URLs" Lesson is part of the full, Full Stack for Front-End Engineers, v3 course featured in this preview video. Here's what you'd learn in this lesson:
Jem discusses the meaning and function of DNS, nameservers, and URL. An exercise in looking up domain names with nslookup and dig and a breakdown of the anatomy of a URL are also covered in this segment.
Transcript from the "DNS & URLs" Lesson
[00:00:00]
>> After all that information, we know a tiny bit more how the Internet works, but there's still so much more. How do domains work? I mean you see IP addresses, but that's not the same as an actual domain name, how does all that work? We know all this happens at the TCP connection level, which is running on packets of data, but what else?
[00:00:24]
We need something called the domain name system. Think of a domain name system as, I don't know, like a phone book. So instead of you memorizing 127.0.0.1, you know its local host. That's probably not the best example, but. Instead of remembering, I don't know, the IP address for frontendmasters.com off the top of my head.
[00:00:47]
But instead of remembering that, you remember frontendmasters.com because that's easier to remember. You remember google.com, you remember netflix.com, Facebook etc., all that's possible by using the domain name system. The things that hold the records, these giant phone books that map names to IP addresses, are called nameservers. Nameservers are independent entities that again hold all this information, they share with each other.
[00:01:09]
That's how in a second when we buy our domain name how whatever ISP you're using, whatever service you're using, will know how to talk to a different service. And they're all using nameservers to translate all these things. And think what the Internet would be without domain names, it would never make it as far because no one is gonna remember all these IP address off the top of their head.
[00:01:30]
So your computer talks to the browser. The browser actually talks to the name server and says like, hey, this person wants to go to google.com, but that doesn't mean anything to me, I actually need the IP address to actually make the connection. It talks to the name server, the name server is like, okay, I got you, here's the IP address, then we use that IP and then we talk to a server.
[00:01:49]
The server then talks back to the browser only on the IP level, and then it gets back to us. All that's hidden from us, all we know is we typed in frontendmasters.com and it showed up in our browser. But underneath is this really complex mechanism of parties working independently but all together.
[00:02:11]
We're almost there to buying our domain, probably the most exciting part. There's two types of records we need know in DNS. There's an A record, so that maps a name to an IP address, pretty straightforward, this is the one we're gonna use. There's also CNAME, that's where I can map a name to another name.
[00:02:28]
So instead of frontendmasters.com, I could say Masters Frontend, and we can map them the same way without having to create a new IP address in the middle. And don't go to that website, I don't know what it is. I should stop making random websites, it's the Internet. Okay, so let's dive in a little bit to the DNS, cuz I want you to see how these systems work, we're not gonna touch it too much.
[00:02:50]
But again, I want you to know and not just believe that these things work, I want you to understand how these systems are all connected. So to see the nameservers for a particular domain, we're gonna use the nslookup tool. So in your terminal you can say nslookup frontendmasters.com, any address you want, and you should get a list back of some IP addresses that are associated to those domains.
[00:03:18]
Now if you wanna have fun, just plug one of those IP addresses into your browser and it'll connect to that domain. And let's check out what frontendmasters.com looks like. Let's go to frontendmasters.com. Again, I don't know what Frontend Masters is, don't go there, I take no responsibility for random addresses.
[00:03:40]
There we go, that's more like it. So frontendmasters.com doesn't just have one IP, it has multiple IP addresses, and the names from our lookup can give us some of them. I think there's some flags we can get to get all of them, but usually it's only to give us three.
[00:03:56]
Cuz most domains have multiple IP addresses and that would not be super useful. So that's nslookup, that's pretty useful if you have a domain name and you're like, where's it actually mapping to, this will tell you. Now if we wanna go deeper, beyond the nameserver into the actual DNS records for a domain, we can use a tool called dig.
[00:04:17]
So let's go ahead and clear, let's dig frontendmasters.com. A bit more verbose. But again it's giving us the same IP addresses as the nameserver, but now it's telling us these are A records. Which we just talked about, these A records are DNS records that map frontendmasters.com to an IP address.
[00:04:42]
These are all stored on the nameservers and the actual domain registrars, yes.
>> Can you clarify, my one domain name could have multiple IP addresses, is it because they're hosted on different servers?
>> Yeah, very few websites these days, very few commercial websites are just running on one server, they're almost always running on multiple servers and they're load balanced across.
[00:05:08]
And so when we go to frontendmasters.com, we don't actually know where we're going. But usually through the combination of CDNs and load balancers, it's gonna direct us to the shortest path. But these are all available for us if any IP address ever goes down. So yeah, very few web applications only have one IP address these days, it's just very easy to scale up and it's good for resiliency.
[00:05:33]
So dig is a good way of digging into the, [LAUGH] digging, sometimes the tools all work out, to get to the DNS records. And we're so close to buying a domain, I know you want it. But we have to learn all this stuff before, cuz you have to know how this works in order to understand how all the systems talk to each other.
[00:05:52]
The last one we're gonna cover is a URL, probably something you don't spend a lot of time thinking about. But again, rules and cooperation. URLs have a structure, they have rules, they have things they can do, they have things they can't do. URL stands for Uniform Resource Locator, where something is, that's all it does, or it's all it says.
[00:06:15]
You can break your URL down into domain, so yourdomain.com, frontendmasters.com. The subdomain, which is anything with a dot in front of the actual domain. So test, dev, doesn't matter, that's called the subdomain. TLD is a top level domain. So TLDs are actually owned by companies at this point.
[00:06:35]
It used to be .com was the only one, it's owned by, I wanna say ICANN which is kind of the governing body of domain names. And every time you buy a domain you pay them a small fee, and that helps keep all these processes working together. Then companies came along and said you know what, this is some BS, why can't I have my own domain name?
[00:06:55]
So that's what companies did, they created their own, they paid ICANN. So now Google owns .google, I don't know of any of the other ones. But now there's a lot of fun domain names, maybe 10 years ago, about 15 years ago, there's .com, .net, .org. I feel like .nets are always the sketchy ones cuz you're always like, who has a .net domain name, that doesn't seem right.
[00:07:16]
But now there's .science, .best, I feel like .cooking is one. There's a lot of them, so you can kinda make any sort of domain you want these days. Anything after the domain, after the TLD, the top level domain, is called the path, that's probably one as front engineers we're most familiar with.
[00:07:35]
And then anything after the path followed by a question mark is known as the query parameters, and those can go on, and on, and on. So yeah, even URLs, the thing you use every single day, they have rules and they have processes.
>> So question about just the top level domain.
[00:07:50]
Back in the day, there was a lot of cybersquatting rules where you couldn't buy a company's name if they didn't have their domain name yet. Do you know do those same cybersquatting rules kind of apply to top level domains? Like if I wanted to go out and buy the .microsoft, I'm assuming they would own that already but if I bought .microsoft is there rules around not doing that?
[00:08:15]
>> There are, again, ICANN is the regulatory body that arbitrates these disputes. You'll never be able to buy Microsoft because they're already gonna have an arrangement with Microsoft. And if Microsoft's like, we don't want to buy that then it just wouldn't exist, they wouldn't go down that path.
[00:08:34]
Similar like you're never gonna own a .google domain name, Google owns that, it's never gonna change. Where it gets tricky when it comes to this concept of cybersquatting and can you buy a TLD, can you buy a domain, is in individual cases where a company wants to buy it because they're like, this is our trademark, this is our IP, this is something.
[00:08:54]
But the other person has a legitimate case where they're not squatting, they're not just, like, it's an empty website that's filled with ads or one of those this website is for sale type placeholders. The case that I always think of is toyota.com. So you're like, Toyota, the car company.
[00:09:11]
But the original owner of toyota.com was this small business owner who ran a car repair shop whose last name was Toyota, so a legitimate use of the domain. This person owned it first, we know under the very authoritative doctrine of finders keepers they got there first. But Toyota sued this person cuz they're saying we're Toyota, you work on cars and we sell cars, there's a chance consumers might be confused when they go to this domain so we're gonna sue you for ownership of it.
[00:09:45]
I forgot the resolution of what happened with that. But that was one of the more, I don't know, unpleasant cases where a corporation's trying to bully their way around the Internet when that's not how the Internet's built. The Internet's built of you got there first it's yours, whether or not you do anything with it that's nobody's business but your own.
[00:10:04]
That has changed over time, where corporations increasingly are pressuring people to buy out, or they'll force you off a domain, they'll arbitrate with ICANN. And ICANN's usually gonna side with the corporation cuz the corporation has 20 lawyers, you have one, so that can happen. Where it comes to cyber squatting, that's a little bit different these days.
[00:10:26]
So cybersquatting refers to the act of me buying microsoft.com and I either it's just a bunch of malware ads or something like that, I'm not making good use of that domain name. Then Microsoft could maybe sue me and say like, hey, ICANN, this person is not using this, this is our trademark and IP, we wanna own this domain, then that becomes a little bit different of a case.
[00:10:50]
But if you're making legitimate use, it's harder to make. Fun fact, and we keep bringing up Microsoft, but every time there's a new TLD that's released people immediately buy, or companies immediately buy all of the bad domain names associated with these sites. So I'll say .com for instance, Microsoft bought like microsoftsucks.com.
[00:11:12]
Or if there's like a .worst, Microsoft bought microsoft.theworst or something like that. Companies do this every time there's a new TLD just to make sure that people don't squat on those or use them for trolling or malicious purposes, things like that. And that's kind of the challenge that we talked about the explosion of TLDs in the past couple of years.
[00:11:35]
Is if you run a company that has an IP, you have to buy all these domain names every single time just to ensure that someone didn't squat on it or use it to direct people. I think a good example would be, it's not possible by like a .google domain name but if it were what if I bought help.google.com but I redirected it to some malware site.
[00:11:57]
And I'm like hey grandma, are you stuck on something, go to help.google.com. And you're like, that's a legitimate website, it has the .google in there, it must be legit. And everything looks legit, you download it, and it's a bunch of viruses. I'm joking about cybersquatting and things like that, but these have real consequences when you have a valid domain name.
[00:12:18]
Another one is domain names that are one off. So like netflix.com, but instead of an i it's a one. You can glance at that and go netflix.com, maybe they cloned the homepage and it looks legitimate, and they're just like stealing logins. That's another common case of kind of one-off, we see that a lot, microsoft.com with a zero instead of an o.
[00:12:42]
So the whole TLD domain, it's a lot more complex than it looks. So for our class we're gonna keep to the simple ones. I hope you keep it funny cuz that's the most important thing when you're buying a domain, keep it funny or interesting to yourself. Answering a few questions that were in the chat.
[00:13:01]
What does not authoritative mean on the nslookup, I had someone respond in the chat with the correct answer. When it says not authoritative, it just means we're a nameserver that's a nameserver that's related to the other nameserver, but we're not actually the ones that own the records for this.
[00:13:15]
So this is just what we're told from another nameserver who was probably told from another nameserver, but we're not the actual one that hold the actual records. So this may be incorrect, but this to the best of our knowledge is the correct answer.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops