Skip to content

Latest commit

 

History

History
286 lines (215 loc) · 17 KB

IP Addressing.md

File metadata and controls

286 lines (215 loc) · 17 KB

IP Address

An IP address is an address used in order to uniquely identify a device on an IP network(more in depth: we identify a network card in a computer). The address is made up of 32 binary bits, which can be divisible into a network portion and host portion with the help of a subnet mask.

The 32 binary bits are broken into four octets (1 octet = 8 bits). Each octet is converted to decimal and separated by a period (dot). For this reason, an IP address is said to be expressed in dotted decimal format (for example, 172.16.81.100). The value in each octet ranges from 0 to 255 decimal, or 00000000 - 11111111 binary.

Dotted Decimal Notation:

Classful Addressing

The 32 bit IP address is divided into five sub-classes. These are:

  • Class A
  • Class B
  • Class C
  • Class D
  • Class E Each of these classes has a valid range of IP addresses. Classes D and E are reserved for multicast and experimental purposes respectively. The order of bits in the first octet determine the classes of IP address.

IPv4 address is divided into two parts:

  • Network ID
  • Host ID image

Class A

IP address belonging to class A are assigned to the networks that contain a large number of hosts.

  • The network ID is 8 bits long.
  • The host ID is 24 bits long.

The higher order bit of the first octet in class A is always set to 0. The remaining 7 bits in first octet are used to determine network ID. The 24 bits of host ID are used to determine the host in any network. The default subnet mask for class A is 255.x.x.x.

Therefore, class A has a total of:

  • 2^7-2= 126 network ID
    • 2^7 because from the 8bits for the network ID, the first one is 0, so only 7bits remain that can be 1 or 0
    • Here 2 address are subtracted because 0.0.0.0 and 127.x.y.z are special addresses.
  • 2^24 – 2 = 16,777,214 host ID
    • We subtract to because two are reserved: the broadcast address and the network address.

IP addresses belonging to class A ranges from 1.x.x.x – 126.x.x.x

Class B

IP address belonging to class B are assigned to the networks that ranges from medium-sized to large-sized networks.

  • The network ID is 16 bits long.
  • The host ID is 16 bits long.

The higher order bits of the first octet of IP addresses of class B are always set to 10. The remaining 14 bits are used to determine network ID. The 16 bits of host ID is used to determine the host in any network. The default sub-net mask for class B is 255.255.x.x.

Class B has a total of:

  • 2^14 = 16384 network address
  • 2^16 – 2 = 65534 host address

IP addresses belonging to class B ranges from 128.0.x.x – 191.255.x.x.

Class C

IP address belonging to class C are assigned to small-sized networks.

  • The network ID is 24 bits long.
  • The host ID is 8 bits long. The higher order bits of the first octet of IP addresses of class C are always set to 110. The remaining 21 bits are used to determine network ID. The 8 bits of host ID is used to determine the host in any network. The default sub-net mask for class C is 255.255.255.x.

Class C has a total of:

  • 2^21 = 2097152 network address
  • 2^8 – 2 = 254 host address

IP addresses belonging to class C ranges from 192.0.0.x – 223.255.255.x.

Class D

IP address belonging to class D are reserved for multi-casting. The higher order bits of the first octet of IP addresses belonging to class D are always set to 1110. The remaining bits are for the address that interested hosts recognize.

Class D does not posses any sub-net mask. IP addresses belonging to class D ranges from 224.0.0.0 – 239.255.255.255.

Class E:

IP addresses belonging to class E are reserved for experimental and research purposes. IP addresses of class E ranges from 240.0.0.0 – 255.255.255.254. This class doesn’t have any sub-net mask. The higher order bits of first octet of class E are always set to 1111.

Rules for assigning Host ID

Host ID’s are used to identify a host within a network. The host ID are assigned based on the following rules:

  • Within any network, the host ID must be unique to that network.
  • Host ID in which all bits are set to 0 cannot be assigned because this host ID is used to represent the network ID of the IP address.
  • Host ID in which all bits are set to 1 cannot be assigned because this host ID is reserved as a broadcast address to send packets to all the hosts present on that particular network.

Rules for assigning Network ID

Hosts that are located on the same physical network are identified by the network ID, as all host on the same physical network is assigned the same network ID. The network ID is assigned based on the following rules:

  • The network ID cannot start with 127 because 127 belongs to class A address and is reserved for internal loop-back functions.
  • All bits of network ID set to 1 are reserved for use as an IP broadcast address and therefore, cannot be used.
  • All bits of network ID set to 0 are used to denote a specific host on the local network and are not routed and therefore, aren’t used.

Problems with Classful Addressing

The problem with this classful addressing method is that millions of class A address are wasted, many of the class B address are wasted, whereas, number of addresses available in class C is so small that it cannot cater the needs of organizations. Class D addresses are used for multicast routing and are therefore available as a single block only. Class E addresses are reserved.

CIDR (Classless Inter-Domain Routing or supernetting)

CIDR (Classless Inter-Domain Routing) -- also known as supernetting -- is a method of assigning Internet Protocol (IP) addresses that improves the efficiency of address distribution and replaces the previous system based on Class A, Class B and Class C networks. The initial goal of CIDR was to slow the increase of routing tables on routers across the internet and decrease the rapid exhaustion of IPv4 addresses. As a result, the number of available internet addresses has greatly increased.

An IP address is represented by a prefix, which is the IP address of the network. It is followed by a slash, followed by a number M. M: number of leftmost contiguous bits to be used for the network mask.

  • Example: 144.16.192.57 / 18

Rules

  • The number of addresses in each block must be a power of 2.(4,8,16,.... IP addresses)
  • The beginning address in each block must be divisible by the number of addresses in the block.
    • Example: A block that contains 16 addresses cannot have beginning address as 193.226.40.36. because 36 % 16 is not equal to 0, but the address 193.226.40.64 is possible, because 64 % 16 = 0.

Other example:

  • 209.220.186.8/255.255.255.252 (=30) => i only have 2 bits for the hosts, so from 209.220.186.8 - 209.220.186.11. And .8 is for network address and .11 is for broadcasting. 8 % 4 = 0, so it's correct

Masks

Class A, B and C addresses have a fixed division of network and host portions and can be expressed as masks.

Natural Masks

  • Class A: 255.0.0.0
  • Class B: 255.255.0.0
  • Class C: 255.255.255.0

Masks are very flexible. Using masks, networks can be divided into smaller subnets, by extending the network portion of the address into the host portion. Advantage gained:

  • We can create a large number of subnets from one network.
  • Can have less number of hosts per network. (the amount of bits from the mask is reserved for the network, only the bits left are for the hosts => less number than just 255.255.255.0 for example)

How does one get IP Addresses ?!

It gets allocated from the portion of its ISP’s address space(ISP = Internet Service Provider)


ISP's block 11001000 00010111 0001 0000 00000000 200.23.16.0/20 2^12 IPs
Organization 0 11001000 00010111 00010000 00000000 200.23.16.0/23 asking for 512IPs
Organization 1 11001000 00010111 00010010 00000000 200.23.18.0/23 asking for 512IPs
Organization 2 11001000 00010111 00010100 00000000 200.23.20.0/23 asking for 512IPs
... ...... ... .....
Organization 7 11001000 00010111 00011110 00000000 200.23.30.0/23 asking for 512IPs

8 organizations * 512 each = 2^1 => i have used all addresses.

Public vs Private addresses

Routing tables

PROBLEMS

pb1

Suppose we are assigned a class C network 193.226.40.0 (basically has mask /24)
Divide it into three subnets:

  • corresponding to three departments
  • with 110, 45 and 50 hosts respectively

We know that the size of Networks in CIDR are powers of 2.

  • D1(departament 1) -> 110 hosts + 1 router + network address + broadcast = 113 IPs => 128 IPs (the closest power of 2)
  • D2(departament 2) -> 45 hosts + 1 router + network address + broadcast = 48 IPs => 64 IPs
  • D3(departament 3) -> 50 hosts + 1 router + network address + broadcast = 53 IPs => 64 IPs

128 + 64 + 64 = 256 IPs needed.

  • D1

    • 128 IPs = 2^7 and that means we need 7 bits for the hosts, so 32-7=25bits for the network so we have a mask /25
    • 193.226.40.0|25(where 25 = 255.255.255.128) => from 193.226.40.0 to 193.226.40.127
    • 193.226.40.0 is the network address
    • 193.226.40.127 is the broadcast address
  • D2

    • 64 IPs = 2^6 and that means we need 6 bits for the hosts, so 32-6=26bits for the network so we have a mask /26
    • 193.226.40.128|26(where 26 = 255.255.255.192) => from 193.226.40.128 to 193.226.40.191
    • 193.226.40.128 is the network address
    • 193.226.40.191 is the broadcast address
    • The beginning address in each block must be divisible by the number of addresses in the block. 128 % 64 = 0 => It is correct
  • D3

    • 64 IPs = 2^6 and that means we need 6 bits for the hosts, so 32-6=26bits for the network so we have a mask /26
    • 193.226.40.192|26(where 26 = 255.255.255.192) => from 193.226.40.192 to 193.226.40.255
    • 193.226.40.192 is the network address
    • 193.226.40.255 is the broadcast address
    • It also respects the divisible rule. 192 % 64 = 0.

pb2

Suppose we have a network like this:

image

We need to split this network(194.254.160.0) into subnetworks.


To find the networks we take out the routers => 3 networks from the hosts(N1, N2, N3) and 4 others.

image

How many IPs we need for each network?

  • N1: 8 hosts + 1 router + 1 network addr + 1 broadcast addr = 11 => 16 is the smaller power
  • N2: 11 hosts + 1 router + 1 network addr + 1 broadcast addr = 14 => 16 is the smaller power
  • N3: 8 hosts + 1 router + 1 network addr + 1 broadcast addr = 11 => 16 is the smaller power
  • N4, N5, N6, N7: 2 routers + 1 network addr + 1 broadcast addr = 4

194.254.160.0 | 25 => 128 IPs
16 + 16 + 16 + 4 + 4 + 4 + 4 = 64 IPs.

Now we have to check if the problem is solvable... can I assign all the required IP subnetworks by using that 128? When we add them up together, we have 64. 64<128 => problem solvable.

YOU SHOULD ALWAYS START WITH THE LARGEST SUBNETWORK AND GO TOWARDS TO THE SMALLEST SUBNETWORK WHEN YOU ALLOCATE

  • N1 (we need 16 ips)
    • 16 = 2^4. from 32 bits, we subtract 4 => the network mask is 28 => 194.254.160.0/28.
    • from 194.254.160.0(network addr) to 194.254.160.15(broadcast)
  • N2 (we need 16 ips). Same thing but we begin from .16 => 194.254.160.16/28
    • from 194.254.160.16(network addr) to 194.254.160.31(broadcast)
  • N3 (we need 16 ips). Same thing but we begin from .32 => 194.254.160.32/28
    • from 194.254.160.32(network addr) to 194.254.160.47(broadcast)
  • N4 (we need 4 ips).
    • 4 = 2^2. from 32 bits, we subtract 2 => the network mask is 30 => 194.254.160.48/30
    • from 194.254.160.48(network addr) to 194.254.160.51(broadcast)
  • N5 (we need 4 ips). Same thing but we begin from .52 => 194.54.160.52/30
    • from 194.254.160.52(network addr) to 194.254.160.55(broadcast)
  • N6 (we need 4 ips). Same thing but we begin from .56 => 194.54.160.56/30
    • from 194.254.160.56(network addr) to 194.254.160.59(broadcast)
  • N7 (we need 4 ips). Same thing but we begin from .60 => 194.54.160.60/30
    • from 194.254.160.60(network addr) to 194.254.160.63(broadcast)

!!! We are left with 128-64 = 64 IPs. 64 = 2^6 => the mask is 32-6=26. So the last one, 194.254.160.64/26, remains free.

METHOD 2 - using a binary tree that will provide all the allocations

What we know:

  • N1, N2, N3 -> we need 16ips
  • N4, N5, N6, N7 -> we need 4ips

image

STEP 1: We take the original IP space , in this case 194.254.160.0. Do we have a requirement for a network this large? (We know that 194.254.160.0 has mask 25, so 128ips). No, we don't need a network that contains 128ips => we split the network in 2.
STEP 2: We will get 194.254.160.0/26 and 194.254.160.64/26. Do we need now any /26 subnetwork? No, because we don't have any need to have 64 IPs, only 16IPs and 4IPs. So we split again.
STEP 3: We will get 194.254.160.0/27, 194.254.160.32/27 and 194.254.160.64/27, 194.254.160.96/27. We don't need the size 32, so we divide it again. We will only work on the left side until we manage to allocate it.
STEP 4: We will get 194.254.160.0/28 and 194.254.160.16/28. WE NEED NOW /28. We need 3 of them. So, N1 will be 194.254.160.0/28 and N2 will be 194.254.160.16/28. STEP 5: We still need a network of 16, so we move to the right. 194.254.160.32/27 can be split into 194.254.160.32/28 and 194.254.160.48/28. N3 will be 194.254.160.32/28. STEP 6: We solved the networks that required 16IPs, we have left 4networks that need 4IPs. We split 194.254.160.48/28. We need to split twice (16->8->4) to have what we need(/30). See the image.

Advanatges:

  • you will never get an invalid combination with the mask. The mask will always be correct.

Let's write some routing tables.

Recall this image image

For R2: The connected networks are: N2, N4, N6
Remember the IP for the routers:

  • R1 has IP:
    • 194.254.160.50 in N4
    • 194.254.160.53 in N5 P.S: 0.0.0.0 means it's directly connected to the network (default entry)
Destination Network Mask Next Router(Gateaway) Interface
194.254.160.16 (N2) /28 0.0.0.0 0
194.254.160.48 (N4) /30 0.0.0.0 2
194.254.160.56 (N6) /30 0.0.0.0 1
194.254.160.0 (N1) /28 194.254.160.50 (R1 from N4) 2
194.254.160.52 (N5) /30 194.254.160.50 (R1 from N4) 2
194.254.160.32 (N3) /28 194.254.160.50 (R1 from N4) 2
OR 0.0.0.0(use R4 for N3) /30 194.254.160.58 (R4 from N6) 1

pb3

Extract first IP and broadcast for 172.17.89.200/19.


Is this a network address or an IP from a network? 200 % 19 != 0 so it's an IP.

1. HOW DO WE OBTAIN THE NETWORK ADDRESS? With the operation ip AND mask:
172.17.89.200 AND
244.255.224.0
= = = = = = =
172.17.64.0 => Network address => first IP is 172.17.64.1

2. HOW DO WE OBTAIN THE BROADCAST ADDRESS?
With the operation network addr OR complementary of mask:
The mask is /19 which is equivalent to 255.255.224.0 => the complementary is 0.0.31.255

172.17.64.0 OR
0.0.31.255
= = = = = = =
172.17.95.255 => Broadcast address

pb4

Subnet 203.10.93.0/24 in 30 subnets. Is 203.10.93.30 a valid host IP?


Can we split that IP address base into 30 equally sized subnets? No, because 256 % 30 != 0.

1. Can 203.10.93.30 be a network address?
To be 203.10.93.30 a network address, 30 needs to be a sum of powers of 2 or a power of 2. 16+8+4+2=30 => it can be a network address. But if it would be a subnetwork address, you'll have the mask 31 (You can write 30 as 00011110 => mask /31) which is unusable so IT CAN'T BE A NETORK ADDRESS. Also, 30 is only divisible with 2 so the mask is /31.

2. Can 203.10.93.30 be a broadcast address?
If it's a broadcast that would mean that the next subnetwork should start at 203.10.93.31, which is impossible (it's not a sum of powers of 2, and it should be divisible by 4 at least).

From (1) and (2) => 203.10.93.30 is always a host IP.