Ai-CompTech

AI Computing

Computer Science Fundamentals

TCP/IP Protocol Suite and Internet Fundamentals

Master TCP/IP protocols, IP addressing, subnetting, and internet infrastructure

Advanced 90 min read 0 examples 0 quiz questionsID: 6962f8e8
Lesson Content

TCP/IP Protocol Suite and Internet Fundamentals

TCP/IP Model

The TCP/IP model is a practical 4-layer framework that powers the Internet.

4 Layers

  1. Application Layer (HTTP, FTP, DNS, SMTP)
  2. Transport Layer (TCP, UDP)
  3. Internet Layer (IP, ICMP, ARP)
  4. Network Access Layer (Ethernet, Wi-Fi)

vs OSI: More practical, fewer layers, real-world protocols

IP Addressing

IPv4 Addressing

Format: Four octets (0-255) separated by dots

code
192.168.1.100

Binary Representation:

code
192 .168 .1 .100 11000000.10101000.00000001.01100100

Total Addresses: 2³² = 4,294,967,296

IP Address Classes

Class A (1.0.0.0 to 126.255.255.255)

  • First bit: 0
  • Network bits: 8
  • Host bits: 24
  • Networks: 126
  • Hosts per network: 16,777,214
  • Use: Very large organizations

Class B (128.0.0.0 to 191.255.255.255)

  • First bits: 10
  • Network bits: 16
  • Host bits: 16
  • Networks: 16,384
  • Hosts per network: 65,534
  • Use: Medium organizations

Class C (192.0.0.0 to 223.255.255.255)

  • First bits: 110
  • Network bits: 24
  • Host bits: 8
  • Networks: 2,097,152
  • Hosts per network: 254
  • Use: Small networks

Class D (224.0.0.0 to 239.255.255.255)

  • Use: Multicast

Class E (240.0.0.0 to 255.255.255.255)

  • Use: Reserved/Experimental

Private IP Addresses

RFC 1918 reserves these for internal use:

code
10.0.0.0 to 10.255.255.255 (Class A) 172.16.0.0 to 172.31.255.255 (Class B) 192.168.0.0 to 192.168.255.255 (Class C)

Use: Home networks, company LANs NAT: Translates private → public IP

Special IP Addresses

code
0.0.0.0 Default route 127.0.0.1 Localhost (loopback) 255.255.255.255 Broadcast 169.254.x.x APIPA (auto-config when DHCP fails)

Subnet Masks

What is a Subnet Mask?

Divides IP address into network and host portions.

Format: Same as IP (4 octets) Binary: Contiguous 1s (network), then 0s (host)

Default Masks

code
Class A: 255.0.0.0 = /8 = 11111111.00000000.00000000.00000000 Class B: 255.255.0.0 = /16 = 11111111.11111111.00000000.00000000 Class C: 255.255.255.0 = /24 = 11111111.11111111.11111111.00000000

CIDR Notation

CIDR: Classless Inter-Domain Routing

code
192.168.1.0/24 = 255.255.255.0 10.0.0.0/8 = 255.0.0.0 172.16.0.0/12 = 255.240.0.0

/24 means first 24 bits are network portion

Calculating Network Info

Example: 192.168.1.100/24

  1. Network Address: 192.168.1.0
  2. Broadcast Address: 192.168.1.255
  3. First Host: 192.168.1.1
  4. Last Host: 192.168.1.254
  5. Total Hosts: 254 (2⁸ - 2)

Why -2? Network address & broadcast address

Subnetting

Why Subnet?

  • Efficient IP usage
  • Better network organization
  • Improved security (isolate networks)
  • Reduced broadcast traffic

Subnetting Example

Problem: Divide 192.168.1.0/24 into 4 subnets

Solution:

  • Need 2² = 4 subnets
  • Borrow 2 bits from host portion
  • New mask: /26 (255.255.255.192)

Subnets:

code
1. 192.168.1.0/26 (Hosts: 1-62) 2. 192.168.1.64/26 (Hosts: 65-126) 3. 192.168.1.128/26 (Hosts: 129-190) 4. 192.168.1.192/26 (Hosts: 193-254)

Each subnet: 62 usable hosts

Subnet Calculation Steps

  1. Determine requirements: How many subnets? Hosts per subnet?
  2. Borrow bits: n bits → 2ⁿ subnets
  3. New mask: Original + borrowed bits
  4. Block size: 256 - last octet of mask
  5. List subnets: Increment by block size

Common Subnet Masks

| CIDR | Mask | Hosts | |------|------|-------| | /30 | 255.255.255.252 | 2 | | /29 | 255.255.255.248 | 6 | | /28 | 255.255.255.240 | 14 | | /27 | 255.255.255.224 | 30 | | /26 | 255.255.255.192 | 62 | | /25 | 255.255.255.128 | 126 | | /24 | 255.255.255.0 | 254 |

IPv6

Why IPv6?

  • IPv4 exhaustion: Running out of addresses
  • More addresses: 340 undecillion (340 × 10³⁶)
  • Better security: IPsec built-in
  • Simpler header: Faster routing

IPv6 Address Format

128 bits in 8 groups of 16 bits (hexadecimal)

code
2001:0db8:85a3:0000:0000:8a2e:0370:7334

IPv6 Shortening Rules

1. Remove leading zeros:

code
2001:0db8:85a3:0000:0000:8a2e:0370:7334 ↓ 2001:db8:85a3:0:0:8a2e:370:7334

2. Replace consecutive zeros with :::

code
2001:db8:85a3:0:0:8a2e:370:7334 ↓ 2001:db8:85a3::8a2e:370:7334

Note: Use :: only once per address

IPv6 Address Types

Unicast: One device

code
2001:db8::1

Multicast: Group of devices

code
ff00::/8

Anycast: Nearest device in group

Link-Local: Same network segment

code
fe80::/10

Loopback: This device

code
::1 (equivalent to 127.0.0.1)

Key Protocols

TCP (Transmission Control Protocol)

Characteristics: ✅ Connection-oriented ✅ Reliable ✅ Ordered ✅ Error checking ✅ Flow control

Three-Way Handshake:

code
1. Client → Server: SYN 2. Server → Client: SYN-ACK 3. Client → Server: ACK → Connection established

TCP Header Fields:

  • Source/Destination Port (16 bits each)
  • Sequence Number (32 bits)
  • Acknowledgment Number (32 bits)
  • Flags (SYN, ACK, FIN, RST, PSH, URG)
  • Window Size (16 bits)
  • Checksum (16 bits)

Use Cases:

  • HTTP/HTTPS (web)
  • Email (SMTP, POP3, IMAP)
  • FTP (file transfer)
  • SSH (remote access)

UDP (User Datagram Protocol)

Characteristics: ✅ Connectionless ✅ Fast ✅ Low overhead ❌ No reliability ❌ No ordering ❌ No error recovery

UDP Header (8 bytes only!):

  • Source Port
  • Destination Port
  • Length
  • Checksum

Use Cases:

  • DNS queries
  • Video streaming (YouTube, Netflix)
  • Online gaming
  • VoIP (Zoom, Skype)
  • DHCP

When to use UDP? Speed > Reliability (can tolerate packet loss)

ICMP (Internet Control Message Protocol)

Purpose: Error reporting and diagnostics

Tools:

  • ping: Test connectivity
  • traceroute: Show network path

Message Types:

  • Echo Request/Reply (ping)
  • Destination Unreachable
  • Time Exceeded
  • Redirect
code
# Test connectivity ping google.com # Trace route traceroute google.com

ARP (Address Resolution Protocol)

Purpose: Map IP address → MAC address

Process:

  1. Device needs MAC for IP 192.168.1.5
  2. Broadcasts: "Who has 192.168.1.5?"
  3. Device with that IP replies: "I do! My MAC is XX:XX:XX"
  4. Sender caches the mapping
code
# View ARP cache arp -a

DNS (Domain Name System)

Purpose

Translate domain names → IP addresses

code
www.google.com → 142.250.185.78

DNS Hierarchy

code
. (root) | com org net edu | google | www mail drive

DNS Record Types

A Record: IPv4 address

code
www.example.com → 93.184.216.34

AAAA Record: IPv6 address

code
www.example.com → 2606:2800:220:1:248:1893:25c8:1946

CNAME: Alias

code
www.example.com → example.com

MX: Mail server

code
example.com → mail.example.com (priority 10)

NS: Name server TXT: Text data (SPF, DKIM) PTR: Reverse DNS (IP → domain)

DNS Query Process

  1. Type www.google.com
  2. Check local cache
  3. Query DNS resolver (ISP)
  4. Resolver queries root server
  5. Root refers to .com server
  6. .com refers to google.com server
  7. google.com server returns IP
  8. IP cached and returned
code
# DNS lookup nslookup google.com dig google.com

DHCP (Dynamic Host Configuration Protocol)

Purpose

Automatically assign IP addresses and network config

DORA Process

  1. Discover: Client broadcasts "I need an IP!"
  2. Offer: DHCP server offers IP address
  3. Request: Client requests offered IP
  4. Acknowledge: Server confirms assignment

DHCP Provides:

  • IP address
  • Subnet mask
  • Default gateway
  • DNS servers
  • Lease time

Lease: How long you can use the IP

Static vs DHCP

Static IP:

  • Manually configured
  • Never changes
  • Use for servers

DHCP:

  • Automatically assigned
  • Can change
  • Use for clients (laptops, phones)

NAT (Network Address Translation)

Purpose

Translate private IPs → public IP

Why? IPv4 address shortage

How NAT Works

code
[Home Network - Private IPs] ├─ PC1: 192.168.1.10 ├─ PC2: 192.168.1.11 └─ Phone: 192.168.1.12 | [Router/NAT] | Public IP: 203.0.113.5 | [Internet]

Outbound:

  1. PC1 (192.168.1.10) requests website
  2. Router changes source IP to 203.0.113.5
  3. Tracks connection in NAT table
  4. Sends to internet

Inbound:

  1. Reply comes to 203.0.113.5
  2. Router checks NAT table
  3. Forwards to 192.168.1.10

NAT Types

Static NAT: 1 private ↔ 1 public Dynamic NAT: Pool of public IPs PAT: Port Address Translation (most common)

Port Numbers

Well-Known Ports (0-1023)

| Port | Protocol | Service | |------|----------|----------| | 20/21 | TCP | FTP | | 22 | TCP | SSH | | 23 | TCP | Telnet | | 25 | TCP | SMTP | | 53 | TCP/UDP | DNS | | 67/68 | UDP | DHCP | | 80 | TCP | HTTP | | 110 | TCP | POP3 | | 143 | TCP | IMAP | | 443 | TCP | HTTPS | | 3389 | TCP | RDP |

Registered Ports (1024-49151)

Assigned by IANA for specific apps:

  • 3306: MySQL
  • 5432: PostgreSQL
  • 27017: MongoDB
  • 6379: Redis

Dynamic/Private (49152-65535)

Temporary client ports

Network Tools

ping

Test connectivity

code
ping 8.8.8.8 ping google.com

traceroute/tracert

Show network path

code
traceroute google.com # Linux/Mac tracert google.com # Windows

nslookup/dig

DNS queries

code
nslookup google.com dig google.com

netstat

Network connections

code
netstat -an # All connections netstat -r # Routing table

ipconfig/ifconfig

View IP configuration

code
ipconfig /all # Windows ifconfig # Linux/Mac ip addr # Modern Linux

Practice Problems

  1. What's the network address of 192.168.50.100/26?
  2. How many usable hosts in a /28 subnet?
  3. Subnet 10.0.0.0/8 into 4 equal networks
  4. Convert 172.16.0.0/12 to subnet mask
  5. What's the broadcast address of 192.168.1.64/27?
  6. Which ports does HTTPS use?
  7. Explain the DNS resolution process
  8. What's the difference between TCP and UDP?