Из курса «How the internet and the web work (CS50 Shorts)»
1 просмотр · 6 ноября 2026
A beginner's tour of how the internet is built: IP addresses, DHCP, DNS and the routers that connect networks, for learners moving from command-line programs to web development. Source: CS50 Shorts, "Internet Primer" by CS50, Harvard University Original: https://cs50.harvard.edu/x/2024/shorts/internet_primer/ Licence: CC BY-NC-SA 4.0 (https://creativecommons.org/licenses/by-nc-sa/4.0/) Changes: Re-encoded; captions, summary and thumbnail generated by Upgram. Not endorsed by CS50 or Harvard University. Shared under the same licence.
You’ll learn how IP addresses identify devices, how DHCP assigns them, how DNS maps website names to addresses, and how routers connect local networks to the wider internet. This primer is for beginners moving from command-line programs to web development; it explains the internet as interconnected networks that communicate using shared rules. It also introduces IPv6, which provides far more addresses than IPv4.
Music If you've been watching these videos in the order which we recommend, we're about to undergo a bit of a culture shift, because now we're going to start talking about the internet and web technologies. So up until now, we've really been doing a lot of C, and when we've been writing our programs, we have been running them from the command line. That's pretty much how the users have been interacting with the programs that we write. They type something at the prompt, something happens in the terminal window, and then it's done. Sometimes you might have persistent data that remains afterwards, but that's pretty much it. It's at the command line. That's the only way the user can interact. From this point forward, we're going to start transitioning so that the users can interact with our websites. So we're going to be writing websites which aren't written in C, but are written in a variety of other programming languages, including PHP and its sort of helper languages, HTML, CSS, and the like. So we're going to start talking about those things. Before we get into web programming itself, I think it's probably a good idea to take a step back and talk about how computers and humans interact over the web. So this video is really sort of a primer, a basic guide to the internet. Now the caveat here is this CS50 is not a networking class. So what we're going to be talking about here is pretty high level. We're not going to get into any low level details of how all this stuff works. If you're interested in that, I'd strongly recommend taking a class on computer networking. And we might even tell a white lie or two just for the purposes of making the general understanding clear. So with that said, let's talk about how we interact with the internet. So here we are. Here's us. We're pretty looking forward to getting onto the internet, which as we all know is chock full of cats. Now do we just connect to the internet like this? Well, probably not. Intuitively you know that, say for example, when you change your Wi-Fi network on your computer, you don't see one called internet, unless that just so happens to be the name of your local Wi-Fi. Right? It's usually something like home. Or if you're at work, it might be the name of your company. There's not just one option called internet. And so something or some things exist in between when we want to connect to the internet. What are some of those things? Well, we're going to talk about that. But we're also going to talk about some of the important things we need in order to be able to connect to the internet. And the first of these things is an IP address. So you've probably heard the term IP address before. What does it mean? Well, an IP address is basically a unique identifier of your computer on a network. Just like every home or office has a unique address to which one could send mail, similarly does every computer, if it wants to receive data or send data, needs to have a unique address so that when information is sent or received, it's being sent from or received to the correct location. This addressing scheme, as I said, is called IP addressing. IP stands for internet protocol, which we'll talk about again shortly. Now, what does IP addressing look like? Well, the scheme basically was, when it was first implemented, to give every computer a unique 32-bit address. That's a lot of bits. That's four billion addresses. And generally, instead of using hexadecimal notation, which we've used previously in the context of pointers in C, to talk about addresses, we usually represent IP addresses in a little bit more of a human-friendly way, representing them as four clusters of eight bits, represented as decimal numbers, because humans don't frequently speak hexadecimal, unless you're programming. But IP, people who use the internet, aren't necessarily programmers. And so making it easy and accessible for them to be able to talk about what their IP address is, in case they maybe need to call up somebody to troubleshoot something, it's better to make it in the more common conventional decimal number format. And so an IP address just looks pretty much like this, w.x.y.z, where each one of those letters represents a non-negative value. in the range of 0 to 255. Recall that an 8-bit number can hold 256 distinct values, and so that's why our range is 0 to 255. And we have four clusters of 8 bits, or for a grand total of 32 bits. And so an IP address might look something like this. This is sort of a generic default IP address, 123.45.67.89. All of them are in the range of 0 to 255, so that's a valid IP address. Here at Harvard University, all of our IP addresses start with 140.247. That's just the way that the IP addresses in this geographic area have been assigned. And so this might be an IP address that might exist here at Harvard. So as I said, if every IP address is 32 bits, we have about 4 billion to give out, a little more than 4 billion. But we can kind of see a problem, right? What's the world population right now? Well, it's somewhere north of 7 billion people. And in the Western world, at least, most people have more than one device capable of internet connectivity. I have one right here, and I have another one in my pocket, and I have one back in my office. And so that's three. And that doesn't even count the ones that I have at home, too. And so that's kind of a problem, right? We have at least 7 billion people and only 4 billion addresses, and every device is supposed to be uniquely identified. We have developed some workarounds to deal with this problem, something called a private IP address, which we're not going to get into in this video. But basically allows for the web, the internet to kind of fake out a little bit that you have a unique address by having private addresses and then funneling them through one single address, which is shared by many different computers. But that's really not a long-term fix. Even that fix isn't going to last forever. And so we need to have a different way of dealing with this. So as I said, we had about 4 billion, but that's not going to be good enough, right? And so the way that it has been decided that we're going to deal with this is to make longer IP addresses. Instead of 32-bit addresses, we're going to have 128-bit addresses. So instead of 4 billion addresses, we're going to have that huge number of addresses, which is 340 billion, billion, billion, billion. So a lot of IP addresses. And this new scheme is called IPv6, is commonly how it's referred, the old scheme being IPv4. It's a bit of a problem in that this problem has been known about for a really long time. And we're really bad, apparently. And you'll see this a lot in the context of computers and computing. We're really bad at anticipating problems. We're good at anticipating problems, but we're bad at dealing with them even though we know about them. So IPv6 has been around for a while. And only in the last couple years have we actually started phasing in these IPv6 addresses to phase out the IPv4 addresses. But some places do have them. And they look similar to a regular IP address, but they're a lot longer. So instead of now having 4 clusters of 8 bytes for your address, we now have 8 clusters of 16 bytes. And 8 times 16 is 128. And we represent these in the less conventional hexadecimal form, because having 16-bit numbers means that instead of being a range of 0 to 255, we'd have a range of 0 to 65,535. And so having a bunch of those stuck together would be very difficult to read. And so we usually use hex just out of convenience. And so a typical IPv6 address might look something like this. It's certainly a lot longer than the IPv4 address we've seen before, but this would be a valid IPv6 address. This one is also a valid IPv6 address. This one happens to belong to Google. And notice there's a bunch of 0s there. Sometimes these addresses can get so long, and since we're still pretty early in IPv6, sometimes there can be big chunks of 0s in there that we don't need that, you know, if you're reading this out loud, it's 2001-4860-4860-0000-8845. . Thank you. It's kind of a lot, right? So if you see a bunch of zeros, you might sometimes see an IPv6 address like this, where they omit the zeros and use a double colon instead. This is OK, though, because we know that there are supposed to be eight distinct chunks. And so by implication, we see four. So we know that there must be four sets of zeros like this that fill it in. So sometimes you might see an IPv6 address not having eight separated chunks like we do here. You might see it looking like this. And that just means that everything you don't see in between, where that double colon is, is just zero separated. So OK, we know a little bit more about IP addresses now, but how do we get them? We can't just pick the one we want. If we did that, we might end up fighting somebody for the same IP address. Or somebody might have chosen it previously. If we try and take it, we're going to run into a bit of a problem. And so we can't just pick the IP address that we want. So the way that we get an IP address is somewhere between our computer and the internet, that big internet out there, there's something called a DHCP server, a dynamic host configuration protocol server. It's a big mouthful of text, but really all it does is it assigns you an IP address. Your DHCP server has a list of addresses that it can validly assign, and it gives you one. That's pretty much all there is to it. Now, before DHCP, this task of assigning addresses fell to a system administrator. So an actual person would have to manually assign your computer an address when you connected to a network. So DHCP just sort of automates this process of giving you an IP address. But that's how you get it. It's just a program running somewhere between you and the internet that has a bank of IP addresses that it can give out. And when you connect to the network, it gives you one. So let's revisit this diagram. Somewhere between you and the internet, there's a DHCP server. OK, so that's good. Now let's talk about DNS. So we've talked all about these IP addresses, and we know that if we're going to uniquely identify a device on the internet, it has to have a unique address. And we could visit that address if we wanted to. But you've probably never typed in something like 192.168.1.1 into your browser, right? You don't type in numbers into your browser. You usually type in human readable names, like google.com or cs50.harvard.edu, right? Those aren't IP addresses, though. So there exists this server, or service rather, called the Domain Name System, DNS, that translates IP addresses to human comprehensible words or phrases that are much more memorable than remembering a set of four numbers, or soon a set of eight hexadecimal numbers. That would be really challenging, right? Think about if you've ever been before the days of cell phones, you had to memorize your friends' phone numbers. That might have got tough after a little while. And similarly, if you want to visit a bunch of websites, you probably don't want to remember a bunch of numbers. You'd rather remember a bunch of words. So this mapping, this translating of sets of numbers to human readable names, kind of makes DNS the yellow pages of the web. And you can think about it as if it's just a huge list running from 0.0.0.0 all the way down to 255.255.255.255, which would be the highest possible, that's the full range from 0's to 255's of all 4 billion-ish IPv4 addresses. I made up the ones on the top and the bottom, but the one in the middle there is actually an IP address. So if we visited 74.125.202.138, apparently that translates to that site there? IO, what the heck is that? Well, not every name that maps is actually clear what it is, right? So sometimes somebody who owns an IP address might name their host something that they're actually not. For example, that IP address, if you went there, it's actually just google.com. But Google has a lot of different servers, and they can't call them all google.com, so they have their own internal system for . . . system for translating google.com to whatever server actually is connected to that IP address. And then there's another system that exists between to translate that gobbledygook here to google.com, but we won't get into that. And similarly for IPv6s, we're also going to have a yellow pages. It'll be a lot bigger. And similarly in the middle there, it was tough to find an IPv6 address that was legitimate, but I found one for Google. But it's Google's Irish website. But if you went to that IPv6 address, if your browser was IPv6 capable, that would bring you to Google's Irish home page. So there you go. But this isn't entirely true, right? This system seems cumbersome, right? If there's a huge list of four billion things to have to look up, that's pretty big. And there's no yellow pages of the world, right? You don't go to your, you don't get, if you still get the yellow pages delivered to you. I got mine the other day and I just recycled it. But if you do get the yellow pages delivered to you, you don't get a book that's every phone number that exists on the planet, right? You get a list of the local phone numbers, the ones that you're most likely to call. And that's actually what DNS is. If you think about it, DNS is really the local yellow pages. And large DNS servers like Google.coms, they're actually just more like libraries that have a copy of all of the local yellow pages, or all of the local DNS records. So there's really no one repository of the full DNS of the internet, just like there's no one yellow pages of the world. There are all these local, small scale DNS's that exist out there. And there are services that aggregate them together, but they depend on those smaller DNS systems updating their information so that they have the most accurate information. So again, this analogy is large aggregating DNS systems are like libraries that have a copy of every yellow pages of the world. They don't themselves update those books. They depend on the books coming in so they can update the information if they need it. So the DNS system is not a giant block. It's decentralized across many, many servers. So now we know that somewhere between us and the internet there exists a DNS server, as well as a DHCP server. Now, access points. What are access points? Well, access points you're probably pretty familiar with from actually connecting to the internet. That's the network that you choose, the home or your work network or what have you. And I'm generalizing the concept of an access point here for purposes of this video, but there are actually a lot of things that could be rolled up into access points. There are concepts of routers, which is sort of a general term that we use, but there are also switches and things actually called access points that are separate from this general concept of an access point. But basically what happens is with IPv4, I said we have this concept of private addresses, right? And instead of every machine having a unique IP address, which we have run out of because we're over 4 billion devices trying to connect to the internet, what we do is instead assign an IP address to a router, that router or access point that exists in your home, for example. And the router's job is to sort of act as a traffic cop, allowing everybody who's connected to that router to use the same IP address to get out. Does that make sense? And so everybody at your home has a private IP address. They can't connect to the internet, or the internet rather, can't speak to them through that private address. They can only speak to them through the address in the router, and it's the router's job to take information that you're sending the router and direct it to the correct place. And for information that's coming into the router, for the router to send it to you. So the routers are really the devices here, particularly a router in your home, the most common sort of usage case for most people. The router in your home is the device that has the public IP address. That's the device that's connected to. And you connect to the router to have information flow through it on your behalf. As I said, a modern home network, the router and switch and access point are all kind of bundled up into a single device. Sometimes a modem is bundled in there as well. That's usually just called a router, but it's really all of those things together. Large-scale business networks, or so-called wide area networks, WANs, actually keep these devices separate. They have a switch. They have routers. They have multiple access points. For example, at a university, you'll see things that look like so-called routers mounted all around campus. Those are all access points that flow into routers, switches, et cetera, to pass information along. Because these networks are so big that one single access point can't cover its large area. And so these large networks, business networks, et cetera, split these into separate devices so the network can scale and grow if needed. So again, somewhere between us and the internet, we have an access point. And that's what we connect to. And through there, we can get to the internet. As I said at the beginning of this video, this is not a course on networking. So this is not the entire story. And I've kind of glossed over it. And maybe I've left you even a little bit confused as to what some of these things are. But that's OK. We don't need the whole story. It's enough for us to know, moving forward, just basically, a little bit about how the internet works. So what we know is we have these private networks at our house. And we connect to a router. And that router is connected to the internet at large. We have these, so what is the internet at large? I keep saying this, but what is it? Well, it's really just all these individual networks at my house, and at your house, and at every other house, that are connected together. It's an interconnected network, an internet. So instead of thinking about the internet as this giant cloud, this ethereal thing that exists out there, it's really just a connection among all of these networks. So here we go. We have our local network. And we're not the only person, probably, on our local network trying to use the internet. There's probably several of us trying to get in. And we're not the only network that exists in the world, right? There are other networks, too, that are trying to connect to the internet. But the internet is not, again, a separate entity. It's just a set of rules that allow these networks, these small networks, the blue, the purple, and the red network here, to communicate with each other. So there's no thing they're all connecting to. They're all just connected to each other, right? And so somewhere on these networks exist the services that we actually want. So maybe in the blue network is where Google lives, and in the purple network is where Facebook lives, and in the red network, maybe that's where all those cats are. And so if we want to get information about cats, we just traverse this chain of networks to get the information we want. And it's not like the network, and here I've represented the networks as all being able to talk to each other, and we can only talk to the network, but the network can't talk back to us. But that's not true either, right? This is all a two-way street. Information can flow through networks back and forth. How does it do that? Well, the internet's really a system of protocols, and we're going to start talking about what those protocols are in future videos. But again, the internet is not a separate thing. It's a set of rules that defines how networks communicate. These small networks, these local networks that we're used to, the people in our house, the people at our school, the people at our job, all sharing a network, and how these networks interconnect and talk to each other, that's actually what the internet's all about. So let's, in a future video, talk about some of the protocols that comprise the internet to hopefully give you a bit more of a well-rounded understanding. I'm Doug Lloyd. This is CS50.
Чтобы продолжить, установите приложение
Ставьте «Нравится», комментируйте, подписывайтесь на авторов и следите за прогрессом в приложении Upgram.
Скачать Upgram
Комментарии