DEV Community

Cover image for Understanding the Network Layer and IP: Routing, IPv4 vs IPv6, and Key Concepts Explained
Vignesh J
Vignesh J

Posted on

Understanding the Network Layer and IP: Routing, IPv4 vs IPv6, and Key Concepts Explained

This is the seventh part of the computer networking series. Check out the previous parts if you haven't. In this part, we'll explore the Network Layer and Internet Protocol (IP).

Table of Contents

  1. Network Layer
  2. Internet Protocol (IP)
  3. Middleboxes

Network Layer

In the Network Layer, we work with routers. If you're unfamiliar with routers, check out our earlier discussion here ↓

While the Transport Layer transfers data as segments, the Network Layer sends data as packets. Let’s look at an example:

Packet Routing and Hop-by-Hop Forwarding

When sending data from A to B, it passes through several routers. Each router:

  • Has its own network address.
  • Checks if the packet is meant for it.
  • Uses a forwarding table to send the packet towards the destination router. This process is called hop-by-hop forwarding.

In an IP address,

IP

Note: Routers here refer to Internet Service Provider (ISP) routers, not the ones in your home network.

Forwarding and Routing Tables

  • Routing Table: Contains the entire path (e.g., A → B → C → D → E).
  • Forwarding Table: Holds the next step (e.g., A → B).

These tables are maintained by each router.

Control Plane

The Control Plane builds routing tables. There are two types of routing:

  1. Static Routing:

    • Addresses are manually added to the routing table.
    • Time-consuming and requires manual updates for network changes.
  2. Dynamic Routing:

    • Automatically updates routing tables when the network changes.

Internet Protocol (IP)

The Internet Protocol (IP) identifies routers and servers uniquely in a network. It has two versions:

  1. IPv4 (32-bit)
  2. IPv6 (128-bit)

IPv4

Format

IPv4 addresses are in the format X.X.X.X, where each X is an 8-bit number.

Classes of IP Addresses

Class Range
Class A 0.0.0.0 – 127.255.255.255
Class B 128.0.0.0 – 191.255.255.255
Class C 192.0.0.0 – 223.255.255.255
Class D 224.0.0.0 – 239.255.255.255
Class E 240.0.0.0 – 255.255.255.255

Subnet Masking

Subnet masking divides an IP address into:

  1. Network Section: Represents the server/network.
  2. Host Section: Represents the client/device.

Example:

IP Address 192.168.2.30

  • Subnet ID: 192.168.2
  • Host ID: 30

Reserved Addresses

Some IPv4 addresses are reserved:

  • Loopback Address: 127.0.0.1 (used for testing where your device acts as both client and server).

Packets in IPv4

Packets contain headers of 20 bytes, which include:

  • IP version, total length, identification number, flags, protocols, checksums, addresses, and Time To Live (TTL).

The TTL ensures packets do not hop indefinitely by limiting their lifespan.You can check this by using the ping command.

TTL

IPv6

IPv6 provides a 128-bit address, significantly larger than IPv4’s 32-bit address. However, IPv6 adoption has been slow due to certain drawbacks.

Cons of IPv6

  • Not backward compatible: IPv4 devices cannot communicate with IPv6 networks.
  • High cost: ISPs require significant hardware upgrades to support IPv6.

IPv6 Format

IPv6 addresses are in the format X.X.X.X.X.X.X.X, where each X is a 16-bit hexadecimal number.

Middleboxes

Apart from end systems and routers, middleboxes also interact with IP packets. They can:

  • Allow or reject packets.
  • Modify packets.

Firewalls

Firewalls are middleboxes that act as filters:

  1. Global Internet Firewalls: Block untrusted IP packets.
  2. Local Network Firewalls: Protect internal networks and modify packets (e.g., changing port numbers).

Network Address Translation (NAT)

Network address translation (NAT) is a method of mapping an IP address space into another by modifying network address information in the IP header of packets while they are in transit across a traffic routing device.

NAT

That’s all for this part of the series. Stay tuned for the next part, where we’ll explore more exciting networking concepts!

Follow me on Linkedin | GitHub | Twitter

Top comments (0)