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

Vignesh JVignesh J
4 min read

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

ClassRange
Class A0.0.0.0 – 127.255.255.255
Class B128.0.0.0 – 191.255.255.255
Class C192.0.0.0 – 223.255.255.255
Class D224.0.0.0 – 239.255.255.255
Class E240.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

10
Subscribe to my newsletter

Read articles from Vignesh J directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vignesh J
Vignesh J

I am Vignesh. I build full-stack web applications using the MERN stack and Java full-stack. I am a technical writer who writes technical content on dev.to and Medium. I have around 5k followers on dev.to. I contribute to open-source projects and have also maintained an open-source project of my own. I have participated in a few open-source programs, both as a contributor and a maintainer: -> Secured 3rd place as a contributor among 100+ participants in Code Sapiens 2024. -> Secured 7th place as a Contributor team among 1650+ teams in DevFest AI 2024. -> Secured 14th place as a project admin among 415+ projects in GirlScript Summer of Code 2024 - Extd. -> Completed the 4 PR mark as a contributor in Hacktoberfest 2024. -> Participated as a maintainer in Hacktoberfest 2024. I am passionate about building impactful software solutions and fostering collaboration in the open-source community. I enjoy working in collaborative environments and mentoring contributors in open-source communities. Feel free to connect with me to discuss web development, open-source contributions, or technical writing. I'm always happy to collaborate and share ideas!