Networking Chp#3 IP Addressing
Networking Chp#3 IP Addressing
IP ADDRESSING
Izaz A Khan
McGraw-Hill
IP Address
Was invented by Robert E. Kahn (an American Engineer) in 1974. The IP Address is a unique number assigned to your computer connection by your home or office or employer's Internet Service Provider (ISP).
This unique number serves as the ID of your connection when it's accessing the Internet.
It functions like your street addressif someone wants to send you mail or you order a pizza, your address is needed for the postman or delivery person to find your home. The same process applies to your computer, your IP address is used to route information from the Internet to your computer.
Standards OF IP Addresses
Two Standards
1. IPv4: Each address is 32 bits. (Mostly used) 2. IPv6: Each address is 128 bits.
Dynamic vs static IP
Dynamic IP addresses can change each time you connect to the Internet, while static IP addresses are reserved for you statically and don't change over time. Residential Internet connections, whether broadband or dialup usually use dynamic IP addresses, while commercial leased lines and servers have static IPs, so they can always be reached at the same address.
Private vs Public IP
Public IP Address
A public (or external) IP address is the one that your ISP (Internet Service Provider) provides to identify your home network to the outside world. It is an IP address that is unique throughout the entire Internet.
Private IP Address
Just as your network's public IP address is issued by your ISP, your router issues private (or internal) IP addresses to each network device inside your network. This provides unique identification for devices that are within your home network, such as your computer, your mobile, and so on.
IPv4 ADDRESSES
An IPv4 address is a 32-bit address that uniquely and universally defines the connection of a device (for example, a computer or a router) to the Internet.
Note
IP addresses are unique in the sense that each address defines one, and only one, connection to the Internet. IP addresses are universal in the sense that the addressing system must be accepted by any host that wants to be connected to the Internet.
Address Space
A protocol such as IPv4 that define addresses has an address space. An address space is the total number of addresses used by the protocol.
RULE:
If a protocol uses N bits to define an address, N the address space is 2 because each bit can have two different values (0 and N1) and N bits can have 2 values.
Note
NOTATIONS
There are two notations to show an IPv4 address.
1. Binary Notation. 2. Dotted-Decimal Notation. (Mostly used)
1-Binary Notation
In binary notation, the IPv4 address is displayed as 32 bits.
The 32 bits are divided into 4 octets (means 8 bits each). Each octet is often referred to as a byte. So, it is common to hear an IPv4 address referred to as a 32-bit address or a 4-byte address.
Binary Notation
2- dotted-decimal notation
To make the IPv4 address more compact and easier to read, IP addresses are usually written in decimal form with a decimal point (dot) separating the bytes.
For each octet, the decimal equivalent of the 8 bits binary number is written and the decimal numbers are separated by dots.
Dotted-decimal notation
Example 1
Solution
129.11.11.239
Example 2
111.56.45.78
Solution
Example 3
Solution
Example 4
Solution
In dotted-decimal notation, each number is less than or equal to 255; 301 is outside this range. (As we know, there are 8 bits in each octet. Even if all the bits are 1 that is 11111111 still its decimal equivalent will be 255 that is why we say that In dotted-decimal notation, each number is less than or equal to 255).
Types of Addressing
Two types of addressing.
1. Classful Addressing 2. Classless Addressing
1- Classful Addressing
In classful addressing, the address space is divided into five classes: A, B, C, D, and E.
Example 6
Solution
Example 7
Solution
The first 2 bits are 1; the third bit is 0. This is a class C address.
Verification of ranges
We know that for class A in binary, the first bit from left of the address will always be 0, so 0 will stay 0 and the remaining 7 bits can change. Means the range will be from 00000000 (minimum) to 01111111 (maximum) which is from 0 to 127 in decimal. Similarly for class B, In binary the first 2 bits from the left will be 1 0 always, so these two bits will not change and remaining 6 bits can change. Means the range will be from 10000000 (minimum) to 10111111 (maximum) which is from 128 to 191 in decimal.
By similar approach we can verify the ranges for the remaining 3 classes.
Note
We see that the range of Class A is 0 to 127, but the available range is 1 to 126 (0 to 127 is the total range).
It means we cannot assign an ip address starting from 0 i.e (0.87.5.6) and starting from 127 i.e (127.1.5.60). This is because 0 is reserved for Default Route and 127 is reserved for Loopback. Explanation in the next slides.
Default route
A default route allows traffic to be forwarded, even without a specific route to a destination.
This route generally points to another router, which treats the packet the same way. If a route matches the packet is forwarded accordingly otherwise the packet is forwarded to the default route of the router. The process continues until packet is delivered.
LOoPbACK
Loopback is used to check whether TCP/IP protocol is installed or not.
The loopback address is 127.0.0.0. The command ping 127.0.0.0 is useful in situations when there is no LAN card in the computer. Means we cannot check from the properties of LAN card whether TCP/IP is installed or not. By typing the above command if we get a reply (means if the ping works) then it will be understood that TCP/IP protocol is installed.
Example 8
Solution
The first byte is 227 (between 224 and 239); the class is D.
Example 9
Solution
The first byte is 193 (between 192 and 223); the class is C.
CLASS D and E
The range of Class D is 224 239. It is used for multicasting and it is not for our use.
The range of Class E is 240 - 255. It is used for future experiment and it is not for our use.
2,097,152
256
A B C
FOR Class A
In class A, the number of networks are 128=27. This is because we know that in class A only the first byte represent the network (netid). And we also know that the first bit in class A address is 0 (see slide 21). The formula to find the number of networks for a class is given by
= 2number of bits in the netid after the first zero from left
In this case the first bit is zero from the left which means the number of networks will be = 27 , as we are left with 7 bits in the netid.
Note
In the previous slide we see that the number of networks in Class A are 128. And the range will be from 0 to 127.
But if we take out the Default route(0) and Loopback(127) then we are left with 128-2= 126. So the total number of networks in Class A are 128 but the available number of networks are 126. In Class B and C the total number of networks are available, means no reservations.
FOR class B
Similarly in class B, for netid we have 2 bytes and the address starts from 1 0 so the number of bits remaining in the netid after the first 0 from the left is 14 that is why the number of networks in class B is = 214 = 16384
FOR class C
For class C, for netid we have 3 bytes and the address starts from 1 1 0 so the number of bits remaining in the netid after the first 0 from the left is 21 that is why the number of networks in class B is = 221 = 2097152
mask
Although the length of the netid and hostid is predetermined in classful addressing, we can also use a mask (also called default mask), a 32-bit number made of 1s followed by 0s. The mask can help us to find the netid and the hostid. For example, the mask for a class A address has eight 1s, which means the first 8 bits of any address in class A define the netid; the next 24 bits define the hostid.
See the table in the next slide.
CIDR
The last column of the table in the last slide shows the mask in the form /n where n can be 8,16 or 24 in classful addressing.
This notation is also called slash notation or Classless Interdomain Routing (CIDR) notation. It is used mostly in classless addressing which will be discussed later. However it can also be used in classful addressing. For example, /8 means we have 8 bits for netid so the address is class A and /16 means we have 16 bits for netid so the address is class B.
Note
Classful addressing, which is almost obsolete (not generally in use), is replaced with classless addressing.
2- Classless Addressing
To overcome address depletion (the act of decreasing something) classless addressing was designed and implemented.
In this scheme, there are no classes, but the addresses are still granted in blocks.
Address blocks
In classless addressing, when an entity, small or large, needs to be connected to the Internet, it is granted a block (range) of addresses. The size of the block (the number of addresses) varies based on the nature and size of the entity.
For example, a household may be given only two addresses; a large organization may be given thousands of addresses.
Restrictions
To simplify the handling of addresses, the internet authorities impose three restrictions on classless address blocks.
1. The addresses in a block must be contiguous, one after another. 2. The number of addresses in a block must be a power of 2 (1,2,4,8,16,32,64,128,).
Example 10
The figure in the next slide shows a block of addresses, in both binary and dotted-decimal notation, granted to a small business that needs 16 addresses. We can see that the restrictions are applied to this block. The addresses are contiguous. The number of addresses is a power of 2 (16 = 24), and the first address is divisible by 16. The first address, when converted to a decimal number, is 3,440,387,360, which when divided by 16 results in 215,024,210.
= 3,440,387,360.
Mask
A better way to define a block of addresses is to select any address in the block and the mask.
As we discussed before, a mask is a 32-bit number in which the n left most bits are 1s and the 32 n rightmost bits are 0s. However, in classless addressing the mask for a block can take any value from 0 to 32.
It is very convenient to give just the value of n preceded by a slash (CIDR notation).
Note
In IPv4 addressing, a block of addresses can be defined as x.y.z.t /n in which x.y.z.t defines one of the addresses and the /n defines the mask.
Note
The first address in the block can be found by setting the rightmost 32 n bits to 0s.
Example 11
A block of addresses is granted to a small organization. We know that one of the addresses is 205.16.37.39/28. What is the first address in the block? Solution The binary representation of the given address is 11001101 00010000 00100101 00100111 If we set 3228 rightmost bits to 0, we get 11001101 00010000 00100101 00100000 or 205.16.37.32. This is actually the block shown in Example 10.
Note
The last address in the block can be found by setting the rightmost 32 n bits to 1s.
Example 12
Find the last address for the block in Example 11.
Solution The binary representation of the given address is 11001101 00010000 00100101 00100111 If we set 32 28 rightmost bits to 1, we get 11001101 00010000 00100101 00101111 or 205.16.37.47 This is actually the block shown in Example 10.
Note
The number of addresses in the block can be found by using the formula 232n.
Example 13
Find the number of addresses in Example 11, where one of the address was given as 205.16.37.39/28 Solution The value of n is 28, which means that number of addresses is 2 3228 or 16.
Example 14
Another way to find the first address, the last address, and the number of addresses is to represent the mask as a 32bit binary number.. In Example 13 the /28 can be represented as 11111111 11111111 11111111 11110000 (twenty-eight 1s and four 0s). Find a. The first address b. The last address c. The number of addresses.
Example 14 (continued)
Solution The first address can be found by ANDing the given addresses (205.16.37.39) with the mask. ANDing here is done bit by bit. The result of ANDing 2 bits is 1 if both bits are 1s; the result is 0 otherwise.
Example 14 (continued)
The last address can be found by ORing the given addresses (205.16.37.39 with the complement of the mask. Oring here is done bit by bit. The result of ORing 2 bits is 0 if both bits are 0s; the result is 1 otherwise. The complement of a number is found by changing each 1 to 0 and each 0 to 1.
Example 14 (continued)
The number of addresses can be found by complementing the mask, converting it as a decimal number, and adding 1 to it.
When an organization is given a block of addresses, the organization is free to allocate the addresses to the devices that need to be connected to the Internet. The first and last address of the block however is treated specially.
The first address is called the Network address and the last address is called Broadcast address.
Note
The first address in a block is normally not assigned to any device; it is used as the network address that represents the organization to the rest of the world.
Network Addresses
The network address is the first address.
The network address defines the network to the rest of the Internet. Given the network address, we can find the class of the address, the block, and the range of the addresses in the block
Broadcast Addresses
A special type of networking address that is reserved for sending messages to all machines on a given network segment.
For example, if a server wants to send a message to all clients it will broadcast the message. The last address in a block will be always reserved for broadcasting, means through that address a message can be broadcasted to all the devices in the network.
Hierarchy
Hierarchy means any system of persons or things ranked one above another.
IP addresses have levels of hierarchy. For example, a telephone network in North America has three levels of hierarchy. The leftmost three digits define the are code, the next three digits define the exchange, the last four digits define the connection of the local loop to the central office.
The local loop (also referred to as a subscriber line) is the physical link or circuit that connects the customer premises to the Telecommunications service provider's network.
An IP address can define only two levels of hierarchy when not subnetted.
The n left most bits of the address x.y.z.t/n define the network (organization network). The 32-n right most bits define the particular host (computer or router) to the network. The part of the address that defines the network is called the prefix and the part of the address that defines the host is called the suffix.
Note
Each address in the block can be considered as a two-level hierarchical structure: the leftmost n bits (prefix) define the network; the rightmost 32 n bits define the host (suffix).
The rest of the world still sees the organization as one entity; however, internally there are several subnets.
SUBNetting
All messages are sent to the router address that connects the organization to the rest of the Internet; the router routes the message to the appropriate subnets. The organization, however, needs to create small sub blocks of addresses, each assigned to specific subnets.
The organization has its own mask; each subnet must also have its own.
SUBNetting
As an example, suppose an organization is given the block 17.12.40.0/26, which contain 64 addresses (232-n). The organization has three offices and needs to divide the addresses into three sub blocks of 32,16 and 16 addresses. We can find the new masks by using the following arguments.
1. Suppose the mask for the first subnet is n1, then 232-n1 must be 32 (because we need 32 addresses in the first sub block), which means that n1=27.
SUBNetting
2. Suppose the mask for the second subnet is n2, then
232-n2 must be 16, which means that n2=28.
3. Suppose the mask for the third subnet is n3, then 232-n3 must be 16, which means that n3=28. This means that we have the masks 27,28,28 for subnets and 26 for the organization. The figure in the next slide shows the whole
NOTE
The diagram in the last page is taken from the book Data Communications and Networking by Behrouz 4th edition.
In the diagram, in every subnet the last address is assigned to devices which is not correct. Because generally the last address in a network or sub network is used for broadcasting.
The same formula will be applied to all the subnets for finding the Broadcast Address.
NAT enables a user to have a large set of addresses internally and one address externally.
The traffic inside can use the large set; the traffic outside the small set. To separate the addresses used inside the home or business and the ones used for the Internet, the Internet authorities have reserved three sets of addresses as private addresses shown in the next slide.
Any organization can use an address out of the set of addresses for private networks without permission from the Internet authorities.
Everyone knows that these reserved addresses are for private networks. They are unique inside the organization, but they are not unique globally.
No router will forward a packet that has one of these addresses as the destination address.
Implementation of NAT
The site must have only one single connection to the global Internet through the router (using NAT).
The figure in the slide shows a simple implementation of NAT. In the figure, the private network uses private address. The router that connects the network to the global address uses one private address and one global address. The private network is not visible to the rest of the internet; the rest of the Internet sees only the NAT router with the address 200.24.5.8.
A NAT implementation
Address translation
All the outgoing packets go through the NAT router, which replaces the source address in the packet with the global NAT address.
All incoming packets also pass through the NAT router, which replaces the destination address in the packet (the NAT router global address) with the appropriate private address. The figure in the next slide shows an example of address translation.
Addresses in a NAT
Question
The reader may have noticed that translating the source addresses for outgoing packets is straightforward. But how does the NAT router know the destination address for a packet coming from the Internet? There may be tens or hundreds of private IP addresses, each belonging to one specific host.
The problem is solved if the NAT router has a Translation Table.
Translation table
A translation table has only two columns: the private address and the external address (destination address of the packet).
When the router translates the source address of the outgoing packet, it also makes note of the destination address (where the packet is going). When the response comes back from the destination, the router uses the source address of the packet (as the external address) to find the private address of the packet. The figure in the next slide shows the idea.
IPv6 ADDRESSES
Despite all short-term solutions, address depletion is still a long-term problem for the Internet. This and other problems in the IP protocol itself have been the motivation for IPv6.
Note
Note
IPv6
Consists of 8 Quarteds separated by colons.
1:2:3:4:5:6:7:8 Hexadecimals values are used in each quardet.
IPv6 vs IPV4
IPv6
Quarted Hexadecimal Colon format 16 bits/quarted 16 = 4 hexadecimal values Octet Decimal Dot format 8 bits/octet
IPv4
Example 15
Expand the address 0:15::1:12:1213 to its original. Solution We first need to align the left side of the double colon to the left of the original pattern and the right side of the double colon to the right of the original pattern to find how many 0s we need to replace the double colon.