# Explain IPv4 Addressing Schemes
How does layer 3 prepare a packet to go through layer 2
## IPv4 Datagram Header
(layer 3) & routing
![[Pasted image 20230518081856.png]]
- version
- length
- Protocol
- Protocol type in datagram payload
- Transmission Control Protocol (TCP)
- User data gram protocol (UDP)
- Internet Control message protocol (ICMP)
- TCP - tranmission control protocol
- each packet is checked and then reciever tells sender it has been received and verified
- retransmits corrupt packets
- file transfers
- UDP
- no handshakes
- used for broadcasting
- no retransmit
## IPv4 Address Format
the <u>network ID</u> is the first 3 octets **192.168.1**.3
The <u>host ID</u> is the last number 192.168.1.**3**
- 32-bit IPv4
- `11000110001010010001000000001001` (32 numbers)
- Divide into octets (8 bits)
- `11000110 00101001 00010000 00001001`
- Convert each octet to dotted decimal notation
- 192.51.100.1
for example for the IP 192.168.1.3
- `11000000 10101000 00000001 00000011` - convert each octet to binary decimal
- `11000110001010010001000000001001` - 32 bit IP encoded
https://www.browserling.com/tools/ip-to-bin
| __ | __ | __ | __ | __ | __ | __ | __ |
| --- | --- | --- | --- | --- | --- | --- | --- |
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
## Subnet Mask
the subnet mask represents the network ID (255) . The host ID is represented by a 0
- accompanies IP address to reveal the network ID part
- Binary 1 in the mask indicates corresponding bit is part of the network ID
- Dotted Decimal mask or network prefix (slash notation)
- Default masks align to octet boundaries
- divide an IP network into multiple IP subnets
- Designate some host bits as subnet ID bits
- Subnet masks only used within the IP network
## Host address ranges
The number of host bits determins available addresses
- The first address is reserved for the network
- the last address is reserved for broadcast
**192.168.1**.10 /24
- the network ID
- the /24 says on the last octet (.10) there are 254 possible addresses (different hosts)
- /24 also denotes that the first 24 bits are the subnet mask
The subnet design fits requirements for number of subnets and hosts per subnet
![[IPv4CIDR.png]]
# Explain IPv4 Forwarding
## Layer 2 vs Layer 3 addressing and Forwarding
![[Pasted image 20230518085243.png]]
## IPv4 Default Gateways
- Compare destination and source address against mask
- Local delivery over ethernet uses Address Resolution Protocol (ARP)
- Remote delivery sent to the default gaetway for forwarding
- configured as entry in host's local routing table
- host uses ARP to locate gateway host on local network
- Default gateway is a router
- routers hold paths to multiple networks
- paths configured statically or learned using a dynamic routing protocol
## Address resolution protocol
works at layer 2. it works with switches. Finds / locates DHCP server.
- when 2 hosts communicate over ethernet using TCP/IP an IP is used at the network layer to identify each interface.
- if the destination address is on a remote network, then the local host must use the default gateway to forward the packet
## Unicast and Broadcast addressing
- unicast is when packets are directed to a single destination IP address 1-1
- Broadcast packet is directed to all interfaces in the local IP network. it will fill all the ports on the switch
- layer 3 broadcast domain
- each broadcast domain is isolated to its own port on a switch
- Delivered at layer 2 by broadcast MAC
- Map layer 3 broadcast domains to layer 2 broadcast domains
- routers do not typically for ward broadcasts
## Multicast and Anycast Addressing
- Multicast (almost like broadcast, but instead of going everywhere it goes to the group)
- hosts join a multicast group
- Internet group management protocol (IGMP)
- IPv4 multicast delivery uses special address ranges
- Delivery at layer 2
- Anycast (almost like a unicast)
- Group of hosts configured with the same IP address
- Router forwards to one node only based on prioritization algorithm
- used for load balancing and service failover
- randomizes who that one person its sent to is
examples of where each of these are used
# Configure IP Networks and Subnets
## Virtual LANs and Subnets
- they limit the number of hosts within broadcast domain to improve performance.
- In its default config every port on a switch is on the same local segment. (you can see each other)
- any host within the same local segment (same network ID, subnet etc...) can see/talk to each other
if too many hosts attached are attached to the same switch, broadcast traffic can become excessive and reduce performance.
- VLANs at layer 2 are a means of addressing this issue...
- each VLAN is a separate broadcast domain
apart from breaking up broadcast domains, subnets can be used to achieve other network design goals:
- many organizations have more then 1 site with WAN links between them. The WAN link normally forms a separate subnet
- useful to divide a network into logically distinct zones for security and admin control
- networks that use different physical and data link technologies, such as Token ring and ethernet, should be logically separated as different subnets.
## Classful addressing
IP network and subnet IDs using masks or network prefixes -- this is classless addressing.... (what we have been previously talking about)
**CLASSFUL** addressing scheme allocates a network ID based on the first octet of the IP address. This is the old way. Classless is the better way.
![[Pasted image 20230518095429.png]]
<u>FIRST OCTET</u> <u>CLASS</u> <u>CIDR</u>
1–126 Class A /8
128–191 Class B /16
192–223 Class C /24
## Public Vs Private Addressing
**These below are private ranges and cannot route over the internet**
- 10.0.0.0 to 10.255.255.255 (Class A private address range).
- 172.16.0.0 to 172.31.255.255 (Class B private address range).
- 192.168.0.0 to 192.168.255.255 (Class C private address range).
This is governed by IANA and assigned by regional registries and ISPs
Hosts on the private network use NAT to access the internet
- **Automatic private IP addressing (APIPA)**
- means for clients that could not connect to a DHCP server to commuinicate on the local network anyway.
- If a windows host does not receive a response from DHCP within a specific amount of time it selects an IP from the below range
- **169.254.1.1 thru 169.254.254.254**
## Other reserved address ranges
- Class D multicast range
- 224.0.0.0 through 239.255.255.255
- Class E experimental range
- 240.0.0.0 through 255.255.255.255
- Loopback range
- 127.0.0.0 to 127.255.255.255
- Other
- 0.0.0.0/8 (address unknown)
- 100.64.0.0/10, 192.0.0.0/24, 192.88.99.0/24, 198.18.0.0/15 (special usage)
- 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24 (documentation and examples)
- 255.255.255.255 (subnets, CANT USE AS IP)
## IPv4 Address Scheme Design
- Consider
- Whether you need a public or private addressing scheme
- how many networks and subnets you need
- how many hosts per subnet
- Addressing rules
- network ID must be from valid range
- network and/or host IDs cannot be all 1s or 0s
- Host ID must be unique in the subnet
- Network ID must be unique
- on the internet (in a public addressing scheme)
- on your internal system of networks (in a private addressing scheme)
- Calculate how many subnets are needed
- Round up to nearest power of 2
- Exponent (the value of n in 2n) is how many bits to add to the default network prefix
- Check subnets allow sufficient hosts (2n-2 where n is host bits)
- Calculate the subnets
- For the first subnet ID, deduct the least significant octet in the mask from 256
- For the next subnet ID, find the lowest subnet value higher than the previous one
- Calculate the host ranges for each subnet
- For the first host, add a binary 1 to the subnet address
- For the last host, deduct two binary digits from the next subnet’s ID
## Math problem to find the subnet
2<sup>n</sup>-2