Thursday 9 June 2022

Internet Protocol (IP) Addresses and Ranges

Internet Protocol (IP) is one of protocols from Network Layer.





Each node in IP network has IP address assigned so IP packets can be routed between them. 


IPv4 Addresses


image source: juniper.net

  • IPv4 - Internet Protocol v4 (1981)
  • each node has its identifier - IP address  
  • 32-bit number divided in octets
    • example: 56.122.17.4
  • dot-decimal notation
  • four octets, four sections of 8 bits
  • each octet (each section) is 8-bit number so in total 32-bits required to represent the full addres; there are 2^32 combinations in total
  • 0.0.0.0 to 255.255.255.255 
  • some addresses and ranges are reserved for e.g. private networks 


IPv6 Addresses

 
image source: juniper.net

  • Introduced in order to expand the range of IP addresses.
  • 128-bit address scheme 
    • 2^128 (undecillion) address combinations 
  • IPv6 as hexadecimal: 8 segments of 16 bits separated by colons
    • Example: 1e03:b32f:042d:0000:0000:0000:0436:4aef
  • How to shorten IPv6 address:
    • Leading zeros in each segment can be omitted.
    • Segments with all zeros can be replaced with single zero:
      • 1e03:b32f:42d:0:0:0:436:4aef
    • Furthermore, a single subset of consecutive zeros can be replaced with two colons: 
      • 1e03:b32f:42d::436:4aef
      • This can be done only once as if we had two occurrences of double-colons we wouldn't know how many zeros each represent. 

Classless Inter-Domain Routing (CIDR) Notation


  • A way of specifying a range of IP addresses, including the case of a single IP address. 
    • Example: 192.10.0.0/16
  • Number after slash denotes leading bits in a 32-bit number that get frozen. In this example, 192.10 (first two octets) stays the same and the rest two octets change so we get the range from 192.10.0.0 to 192.10.255.255. Two last octets are free to change which gives us 2^16 addresses in this range.
  • Examples:
    • 192.10.0.0/24 gives the range 192.10.0.0 to 192.10.0.255
    • 192.10.0.0/32 gives the single IP address: 192.10.0.0  
    • 192.10.0.0/31 gives two IP addresses: 192.10.0.0 and 192.10.0.1
    • 192.10.0.0/30 gives four IP addresses: 192.10.0.0 to 192.10.0.4 
    • 192.10.0.0/17 freezes first 17 bits which is first 2 octets and first bit of 3rd octet so we get the range 192.10.0.0 to 192.10.127.255 (0111111 = 127)
    • 192.10.0.0/28 freezes first 3 octets and first half (first 4 bits) of the 4th octet giving the range of 16 IP addresses: 192.10.0.0 to 192.10.0.15 (00001111 = 15)
  • AWS VPC allows leading bits between 16 (/16) and 28 (/28).
 

Private Network Ranges


  • Public IP range is routable to the Internet. These IP addresses can directly communicate to Internet. 
  • Private network ranges solve the problem of not having enough of IPv4 addresses for all devices connected to Internet.
  • Private Network Ranges (IETF specification RFC1918):
    • 10.0.0.0/8 => 10.0.0.0 to 10.255.255.255 (~16 million addresses)
    • 172.16.0.0/12 => 172.16.0.0 to 172.31.255.255 (~1 million addresses)
    • 192.168.0.0/16 => 192.168.0.0 to 192.168.255.255 (~65k addresses)
  • Private IP range is not routable to the Internet, they are not publicly available, can be used only in private networks. Devices with private network IPs can reach Internet via Network Address Translation or proxy service - something that translates private IP address to public IP address. 

 

ipcalc Tool

 
 
ipcalc is a useful tool which visualizes subnet calculations.
 
To install it on Ubuntu Linux:
 
$ sudo apt install ipcalc
 
To visualize CIDR:

$ ipcalc 192.168.0.0/24
Address:   192.168.0.0          11000000.10101000.00000000. 00000000
Netmask:   255.255.255.0 = 24   11111111.11111111.11111111. 00000000
Wildcard:  0.0.0.255            00000000.00000000.00000000. 11111111
=>
Network:   192.168.0.0/24       11000000.10101000.00000000. 00000000
HostMin:   192.168.0.1          11000000.10101000.00000000. 00000001
HostMax:   192.168.0.254        11000000.10101000.00000000. 11111110
Broadcast: 192.168.0.255        11000000.10101000.00000000. 11111111
Hosts/Net: 254                   Class C, Private Internet

---

No comments: