Loading video player…

Understanding IP Addresses

00:00 In the previous lesson, I started your network journey by revealing the layers of the Internet Protocol Suite. In this lesson, I’ll be covering more details on the addressing part of IP addresses.

00:11 There are actually multiple versions of the IP protocol, but for this course, I’ll be sticking with the most common one, version 4. An address in IP version 4 consists of four numbers, each number ranges from zero to 255.

00:26 That’s an eight-bit byte, and the convention is to show them as separated by periods. You saw this in an earlier lesson where one of the IP addresses for python.org is 151, .101.0.223.

00:41 An IP address is hierarchical, meaning blocks of them can be owned. For example, a company could own the entire 151 parent block and then be in control over all the addresses made up of the combinations of the other three numbers.

00:55 This isn’t the case, they’re typically spread out more than that, but that’s the idea.

01:01 An IP address only specifies a machine. In order to support multiple applications on a machine, a machine uses ports. Port numbers range from zero to 65,535.

01:14 That’s 16 bits or two eight-bit bytes. The ports are grouped into three chunks. The first chunk, called the “well-known ports”, are reserved by the Internet Assigned Numbers Authority, and correspond to the services and protocols you know and love.

01:28 Port 80 is the web, port 25 is mail, and the list goes on.

01:33 On most operating systems, you need special permissions to use these ports. The second chunk of ports are called the registered ports, and these are semi-reserved. Semi-reserved for what, you ask?

01:46 I didn’t really know. In fact, before writing this slide, I had no idea these things were a thing. On most operating systems, any port of 1024 or more is yours to use and abuse.

01:56 I didn’t realize there was a subset I wasn’t supposed to. Evidently, I’ve been a bad boy. If you’re running the Network File System protocol, for example, that’s port 2049, but if you’re not running it, your OS won’t stop you from using that port.

02:11 Hence, the semi in semi-reserved. And finally, the last chunk, called ephemeral ports, are a free-for-all. Ports don’t only determine the service you’re talking to, you also need a port on the source side of a connection.

02:25 Thankfully, your OS does this for you, giving you a free port for your use when you establish a connection to the server. These free ports are always from the ephemeral group.

02:37 Four numbers from zero to 255 give you a total of over 4 billion combinations. You might think that’s enough, but there are blocks of these numbers that are reserved for specific uses and while there are 8 billion of us on the planet, and although not everyone has a device yet, lots of us greedy folks have several. To get around this problem, you can proxy multiple addresses behind a router.

03:01 In fact, some of those reserved blocks I was talking about are specifically for this. For example, my home internet router has a single IP address facing the world, granted to me by my hosting provider.

03:14 But behind that router, I currently have 15 devices. That number seems low. I suspect something’s been turned off. The 192.168 block is one of several that are reserved for private networks.

03:27 This gives me loads of addresses to use on my own, all of which get mapped to the single outward-facing address my router gives me.

03:34 This is why the world hasn’t run out of addresses yet.

03:39 Your computer might have multiple ways of talking to the internet, and as such, your operating system needs to provide a way of getting at each of these.

03:46 This abstraction is known as an interface. Unless you’re trying to use a specific device, you often don’t have to worry about it. For example, my machine has both a network cable and WiFi, but the OS decides which to use when I open a socket.

04:01 These interfaces are in fact virtual and don’t have to correspond to hardware. They might, like my network card, or they might be abstract like a VPN. In fact, on my Mac, there are currently 28 of these suckers.

04:14 I know what maybe four of them are. A little Googling tells me that Windows isn’t much better in this situation. One of those four that I know about is the loopback interface.

04:25 This one is specific for your computer talking to your computer. The neat thing about this being its own interface is that packets over this interface never make it to your network card, which makes them quite efficient.

04:37 The IP address 127.0.0.1 is reserved for the loopback interface. So if some script kiddie ever asks you your IP address, tell them 127.0.0.1. There’s no place like home. On most machines, the name localhost is mapped to this IP address as well.

04:58 On a Unix-based system, the ifconfig command lists all of the interfaces configured. I’ve edited the lengthy response here, and I’m showing only the loopback interface and en0, which is what my machine is using for my network card.

05:12 That card has an address of 192.168.123.118, which you can see in the inet line below en0.

05:23 So to revisit that diagram from the previous lesson, your machine uses a network interface,

05:29 opens a destination socket, the source address of that is your local IP address and an automatically assigned ephemeral port, which might be masked behind a router, which is actually connected to the destination address and port for a specific service, which then uses a network interface on the destination machine to talk to, in this case, an encrypted web server.

05:54 In the next lesson, I’ll put this into practice by writing a small page-fetching program and watching what it does over the network.

Become a Member to join the conversation.