2021/September 2021

How is IP address allocated to a host/router? What is a subnet?

hajinny 2021. 9. 25. 23:59

Network layer deals with transmission of network-level packets called IP datagrams. Network layer is present on every router and end systems (hosts). Network layer is not concerned with the abstracted, end-to-end communication between two hosts (as in transport layer). It's concerned with the communication that happens between every pair of routers and hosts.

 

That was abstract enough. Here's where we should start with to make the discussion more concrete.

 

Router, Host, Subnet

Router is a device with incoming links and outgoing links. Router has its IP address for each of those links (so the IP address that outer world sees is different depending on which link the outer world device is connected to). Here's the picture that shows what I mean, where there are three IP addresses for one router, depending on which link you are looking at it from.

We can see that there are hosts (end systems) connected to the router. Host is an end system, which by definition is the leaf node - has only one link, and therefore only has one IP address assigned to it.

 

Subnet is a collection of devices that can be addressed by a subnet address. Subnet address is an address that refers to a group of IP addresses - how? 223.1.3.xxx would be referring to all the IP addresses that start with 223.1.3. This is notated by 223.1.3.0/24, where '/24' is a subnet mask - the number of significant prefix bytes that matter. Here, 223.1.3 is 24 bytes, so 223.1.3.0/24 is just the same as 223.1.3.xxx.

 

So if I say I refer to a subnet that's addressed by 223.1.3.0/24, then I'd be referring to the following 3 devices (one router, two hosts):

Figure 1

This subnet is referred to as IP Network or Network sometimes, and are connected through lower layer called link layer, through ethernet switches. 

 

IP addresses assignment of subnet's devices

The IP addresses must have come from somewhere.

It starts with the Router. The router is allocated a block of addresses (say 223.1.3.xxx) by the ISP. The router uses one IP address from that batch for its own (223.1.3.27 in Figure 1). 

 

When some device tries to connect to that router, that device doesn't have an IP address yet. It can only attain an IP address only after a process of IP address allocation through DHCP (dynamic host something protocol) protocol. It happens in 4 stages: 

 

1. The device sends an IP packet to 255.255.255.255 (broadcast, unspecified destination) port 67 (was it 68?) to discover a router that can provide it an IP address

2. Available router (say 223.1.3.27) sends a broadcast message (255.255.255.255) saying yes it can allocate an IP address.

3. The device requests that IP address

4. The device gets that IP address.

 

In doing so, the device (host) also gets information about subnet mask, first hop router (default gateway).