CNE Lec4 Network layer - IP_Addressing updated
CNE Lec4 Network layer - IP_Addressing updated
Computer Networks
Faculty of Information Technology
Hanoi University
Content
1. Introduction
2. IPv4 Classful addressing
3. IPv4 CIDR
4. NAT
1. Introduction to IPv4
TCP/IP Model
Host A Host B
Application Application
username username
Transport Transport
username + port Router username + port
Network Network
username + port + IP username + port + IP username + port + IP
22Bytes20Bytes20Bytes 4Bytes
64 to 1500 Bytes
IPv4 header
Example
Envelope data length
To dst IP add
From src IP add
time to live
version
Stamp service type
Book protocol type
Header check sum
options
fragment
IPv4 Addresses
32-bit Address
Uniquely and universally identifies a host
Address space is the total number of
addresses used by the protocol
232 = 4,294,967,296 addresses
Notation
Binary
Dotted decimal
What is the IP address of
fit.hanu.vn?
What is my IP?
Which ISP my IP belongs to?
Internet Registry Structure
Internet Registry Structure
ICANN
IANA
ASO
NIR LIR LIR ISP ISP ISP ISP LIR LIR LIR LIR
LIR ISP ISP ISP ISP ISP ISP ISP ISP ISP ISP
How many IP address in
Vietnam?
Allocated IP address (VNNIC) (March 2020)
IPv4: ~16 million
IPv6: 408 billion/64
(
https://www.thongkeinternet.vn/jsp/trangchu/index.js
p
)
2. IPv4 classful
addressing
Classful Addressing
Five classes; A, B, C, D and E
Each class occupies some part of the address
space
Network Address & Default
Mask
Why do we need Mask?
Mask together with an IP defines the range of IP
block.
Example 1
IP: 192.168.5.7
Mask: 255.255.255.0 /24 – C 254
=> IP block: 192.168.5.0 – 192.168.5.255
IP range from 192.168.5.1 – 192.168.5.254
Example 2
IP 18.202.1.6
Mask: 255.0.0.0 /8 –A
What is the IP block? 18.0.0.0-18.255.255.255
Finding the class
Network address
Number of subnets = 23
Number of addresses per subnet = 213
Terminology
Prefix = netID
The common part of the address
Prefix Length = length (# of bits) of the prefix
denoted by /n
Suffix = hostID
Suffix length = length (# of bits) of the suffix
calculated by (32 - n)
Prefix Lengths
Subnet Masks
a class B network subnetted into 64 subnets
Address: 130.50.15.6/22
Subnet Mask: 255.255.252.0
CIDR/Subnetting
5-59
Finding the Address block
Solution
The prefix length is 20, which means that we must
keep the first 20 bits as is and change the remaining
bits (12) to 0’s. The following shows the process:
Address in binary: 10001100 01111000 01010100 00011000
Keep the left 20 bits: 10001100 01111000 01010000 00000000
Result in CIDR notation: 140.120.80.0/20
Finding the last address in
the block :
3 ways
1. Keep constant n first bits, change 32-n last
bits to all 1 (best way)
2. add the number of addresses to the 1st
address, minus one
3. Add the first address to the complement of
the mask
Remember:
We don’t use the first and the last address
for real host
Example 4
Find the number of addresses in the block if one of
the addresses is 140.120.84.24/20.
Solution 1:
The prefix length is 20, which means that we must
keep the first 20 bits as is and change the remaining
bits (12) to 0’s. The following shows the process:
Address in binary: 10001100 01111000 01010100 00011000
Keep the left 20 bits: 10001100 01111000 01011111 11111111
Result in CIDR notation: 140.120.95.255/20
Example 4
Find the number of addresses in the block if one of
the addresses is 140.120.84.24/20.
Solution 2:
The prefix length is 20. The number of addresses in
the block is 232−20 or 212 or 4096
Example 4
Solution 2
We found in the previous examples that the first
address is 140.120.80.0/20 and the number of
addresses is 4096. To find the last address, we need to
add 4095 (4096 − 1) to the first address (last one is the
broadcast address):
Example 4
Solution 2
To keep the format in dotted-decimal notation, we
write 4095 as 15.255. We then add the first address to
this number (in base 255) to obtain the last address as
shown below:
140 . 120 . 80 . 0
15 . 255
-------------------------
140 . 120 . 95 . 255
The last address is 140.120.95.255/20.
Example 4
Find the last address in the block if one of the
addresses is 140.120.84.24/20.
Solution 3:
The mask has twenty 1s and twelve 0s. The
complement of the mask has twenty 0s and twelve 1s.
In other words, the mask complement is
00000000 00000000 00001111 11111111
or 0.0.15.255. We add the mask complement to the
beginning address to find the last address.
Example 4
Find the last address in the block if one of the
addresses is 140.120.84.24/20.
Solution 3:
140 . 120 . 80 . 0
15 . 255
-------------------------
140 . 120 . 95 . 255
The last address is 140.120.95.255/20.
Example 5
Network formula
2x, where x is the number of 1s added to the
subnet mask from the previous or default subnet
mask
Hosts formula
2y - 2, where y is the number of 0s in the subnet
mask , y = 32-n
Example 6
Given the Class C network of 204.15.5.0/24, subnet the given network
Example 6
Solution 1:
A: 204.15.5.0/27 (mask 255.255.255.224)
IP range 204.15.5.0 to 204.15.5.31
host address range 204.15.5.1 to 204.15.5.30
B: 204.15.5.32/27 (mask 255.255.255.224)
IP range 204.15.5.32 to 204.15.5.63
host address range 204.15.5.33 to 204.15.5.62
C: 204.15.5.64/27 (mask 255.255.255.224)
IP range 204.15.5.64 to 204.15.5.95
host address range 204.15.5.65 to 204.15.5.94
D: 204.15.5.96/27 (mask 255.255.255.224)
IP range 204.15.5.96 to 204.15.5.127
host address range 204.15.5.97 to 204.15.5.126
E: 204.15.5.128/27 (mask 255.255.255.224)
IP range 204.15.5.128 to 204.15.5.159
host address range 204.15.5.129 to 204.15.5.158
Solution 1:
Class C (/24) Network (254 hosts) Split
Into 8 Subnets /27 (32 IPs - 30 hosts)
Another solution: VLSM
(Variable Length Subnet
VLSM allows using different masks for each
Masks)
subnet, thereby using address space
efficiently
Solution 2:
Example 6
Solution 3: The easiest way to assign the subnets
is to assign the largest first
B (28 hosts): 204.15.5.0/27 (255.255.255.224)
IP range 204.15.5.0 - 204.15.5.31
host address range 204.15.5.1 to 204.15.5.30
E (28 hosts): 204.15.5.32/27 (255.255.255.224)
IP range 204.15.5.32 - 204.15.5.63
host address range 204.15.5.33 to 204.15.5.62
A (14 hosts): 204.15.5.64/28 (255.255.255.240)
IP range 204.15.5.64 - 204.15.5.79
host address range 204.15.5.65 to 204.15.5.78
D (7 hosts): 204.15.5.80/28 (255.255.255.240)
IP range 204.15.5.80 - 204.15.5.95
host address range 204.15.5.81 to 204.15.5.94
C (2 hosts): 204.15.5.96/30 (255.255.255.252)
IP range 204.15.5.96 - 204.15.5.99
host address range 204.15.5.97 to 204.15.5.98
Example 6
Solution 3:
Example 6
Solution 1:
204.15.5.0-204.15.5.159 => good not the
best solution
Solution 2 & 3:
204.15.5.0-204.15.5.99 => better than
solution 1. IP address space can be used
economically.
The best way to solve this problem is to
assign IP addresses the largest network first
(Follow solution 3)
CIDR
D6 distribution switch
Access switches
Access switches Access switches
20 hosts 6 hosts
Guest house
distribution switch
Core switch
IP block 202.151.161.128/26
First:202.151.161.128/26 – last:
202.151.161.191/26
D6 (20 hosts): 255.255.255. 224
202.151.161.128/27 - 202.151.161.159/27
D4 (12 hosts): 255.255.255. 240
202.151.161.160/28 - 202.151.161.175/28
GH (6 hosts): 255.255.255. 248
202.151.161.176/29 - 202.151.161.183/29
4. NAT
(Network Address
Translation)
NAT – Network Address
Translation
Reserve a single IP address for local
networks that operate behind a special router
(which can also operate as a firewall), and
allow only outgoing connections
To make this scheme possible, 3 ranges of IP
addresses have been declared private
10.0.0.0 – 10.255.255.255/8 (16,777,216 hosts)
172.16.0.0 – 172.31.255.255/12 (1,048,576 hosts)
192.168.0.0 – 192.168.255.255/16 (65,536 hosts)
10.0.0.5 10.0.0.7
10.0.0.6 router
10.0.0.1
GW 198.60.42.12
10.0.0.2
10.0.0.4
10.0.0.3
NAT – Network Address
Translation
Placement and operation of a NAT box.
NAT – Network Address
Translation
Drawbacks and advantages of NAT:
What do you think?
5. Special IP addresses
Internet Multicasting
Ability to send IP datagram's to a large no. of
receivers simultaneously
Updating replicated databases
Transmitting stock quotes to multiple brokers
Multiparty video conferencing
Class D addresses
224.0.0.0 – 239.255.255.255
The 28 bits after the leading “1110” in the IP
address define the multicast group address (228
groups)
There is no specific concept of a network ID and
host ID as in classes A, B and C
Internet Multicasting
Two kinds of group addresses are supported
Permanent addresses
No need to set up permanent addresses
Range is from 224.0.0.0 – 224.0.0.255
224.0.0.0 Reserved; not used
224.0.0.1 All systems on a LAN
224.0.0.2 All routers on a LAN
224.0.0.3 Reserved
224.0.0.4 All routers using DVMRP
224.0.0.5 All OSPF routers on a LAN
224.0.0.6 Designated routers using OSPF
224.0.0.9 Designated routers using RIP-2
224.0.0.11 Mobile agents (for Mobile IP)
224.0.0.12 DHCP Server / Relay Agent
Internet Multicasting
Temporary addresses
Globally-scoped multicast addresses
Multicasting is implemented by special
multicast routers, using a special protocol
IGMP (Internet Group Management Protocol)
Special IP Addresses
Loopback address
Nmap
tracert
ICMP Echo
ICMP Echo Reply
ICMP Echo with TTL = 1
ICMP TTL Exceeded
ARP
ARP (Address Resolution
Protocol)
Problem: Logical-to-Physical address mapping
Static Solution: a mapping database
Dynamic Solution: ARP
Broadcast request/Unicast reply
ARP Broadcast Request
ARP Unicast Reply
DHCP
Dynamic Host Configuration
Protocol
DHCP allows both manual and automatic
address assignments
Dynamic Host Configuration
Protocol
DHCP may not be reachable by broadcasting, so