DEV Community


Posted on

How Networks Work: Exploring the Fundamentals of Switches, Routers, DNS, DHCP, NAT, VPN, and More

Image description

The world of networking may not always be considered the most exciting topic, particularly for those outside the IT field. However, the technologies, protocols, and best practices that underpin our interconnected world have been in place for quite some time, silently facilitating communication between countless devices. Even for many programmers, terms like IP and DNS are used daily without a clear understanding of how they operate.

This lack of understanding can be detrimental to anyone pursuing a career in IT. Regardless of how many programming languages or frameworks you master, a strong grasp of networking is essential. No part of the IT infrastructure should remain a black box, whether you're a developer, administrator, or aspiring DevOps engineer.

The objective of this article is not to provide an exhaustive guide to networking. Throughout this text, and in the resources provided at the end, you'll find numerous links to sources that can help deepen your understanding. Don't hesitate to explore these references and expand your knowledge.

In this article, we'll focus on network structure, its basic components, and practical applications using virtual machines.

Understanding the OSI Model

To comprehend networking fundamentals, it's essential to become familiar with the OSI (Open Systems Interconnection) model. This model standardizes communication between network protocols, dividing it into seven layers, each with its own set of protocols. You'll often hear references to specific layers like "it operates at the third layer." Here are the seven layers of the OSI model:

  1. Physical Layer: This layer deals with hardware-level communication, including the actual transmission of data over wired or wireless mediums. Examples of protocols at this layer include Wi-Fi, Bluetooth, and DSL.

  2. Data Link Layer: Responsible for transmitting data between two devices within the same network. Data is encapsulated in frames, which contain the physical addresses of both the sender and receiver, known as MAC (Media Access Control) addresses. Every device, including your laptop, has a NIC (Network Interface Controller) responsible for sending and receiving frames. Each NIC has a unique MAC address, typically embedded in hardware or generated by a virtualization system. Devices may have multiple NICs for various purposes.

  3. Network Layer: At this layer, IP addresses are used instead of MAC addresses. IP addressing enables communication between devices across different networks. To view your device's IP addresses, you can use the ip addr show command. IP addresses are represented in CIDR notation, indicating the number of bits in the network mask. This notation helps determine the size of address blocks and the number of addresses within them.

  4. Transport Layer: Responsible for end-to-end communication and data segmentation. Key protocols at this layer include TCP (Transmission Control Protocol) and UDP (User Datagram Protocol).

  5. Session Layer: Manages sessions or connections between devices, ensuring data exchange in an organized manner.

  6. Presentation Layer: Responsible for data formatting, encryption, and compression, ensuring data is in a suitable format for transmission.

  7. Application Layer: The top layer that interacts directly with users or applications. It includes protocols like HTTP, FTP, and SMTP.

Exploring Network Devices


A switch is a fundamental networking device used to connect multiple machines within a local area network (LAN). It operates at the data link layer (Layer 2) and forwards data frames from one MAC address to another, effectively building the network. Switches play a crucial role in creating LANs by connecting devices through their ports.


Routers operate at the network layer (Layer 3) and connect different networks together. For example, a Wi-Fi router connects devices within your local area network (LAN) to the broader internet. Routers use IP addresses for routing data packets between networks.

VLANs (Virtual Local Area Networks)

VLANs (Virtual Local Area Networks) are used to logically separate devices within a single LAN, either for organizational purposes or to establish networks across physically distant locations. VLANs are implemented using switches, which add an additional header with a VLAN tag to frames, determining which network they belong to.


Bridges operate at Layer 2 and are used to connect two separate networks formed using switches. They enable communication between devices in different network segments.


Hubs are basic network devices that operate at Layer 1, essentially broadcasting data to all connected devices without distinguishing between them. They are less common today due to their inefficiency compared to switches.

L3 Switches

Layer 3 switches, also known as L3 switches, go beyond basic switching capabilities. They can not only forward frames between devices but also perform routing functions. The key difference between a router and an L3 switch lies in the complexity of their operations.

WAN (Wide Area Network)

Wide Area Networks (WANs) are networks that extend beyond local areas, such as the internet. WANs connect devices across geographical boundaries, enabling global communication.

Understanding IP Addressing and CIDR

IP addresses are essential for

devices to communicate across networks. They come in two main versions: IPv4 and IPv6. IPv4, the older version, uses 32-bit addresses, while IPv6 uses 128-bit addresses to accommodate the growing number of devices connected to the internet.

CIDR (Classless Inter-Domain Routing) notation is used to represent IP address ranges. It consists of the IP address followed by a slash and a number, indicating the number of bits in the network mask. For example:

  • represents a network with a 24-bit subnet mask, allowing for 256 addresses (2^8).
  • represents a network with a 16-bit subnet mask, allowing for 65,536 addresses (2^16).

Understanding CIDR notation is crucial for subnetting and routing configurations.

DHCP (Dynamic Host Configuration Protocol)

DHCP is used to dynamically assign IP addresses to devices on a network. It simplifies the process of IP address management by automatically providing devices with IP addresses, subnet masks, gateways, and DNS server information.

DNS (Domain Name System)

DNS translates human-readable domain names into IP addresses. It acts as the internet's phone book, allowing users to access websites and services by name instead of remembering IP addresses.

NAT (Network Address Translation)

NAT allows multiple devices within a private network to share a single public IP address. It modifies the source or destination IP address in data packets, enabling devices within a private network to communicate with the internet using a single public IP.

VPN (Virtual Private Network)

VPNs are used to create secure, encrypted connections over the internet. They enable remote users to access private networks as if they were directly connected to the local network. VPNs are essential for secure remote work and protecting data during transmission.


Firewalls are network security devices that control incoming and outgoing network traffic based on predefined security rules. They help protect networks and devices from unauthorized access and cyber threats.

Load Balancers

Load balancers distribute network traffic across multiple servers to ensure high availability and performance. They are commonly used in web applications to prevent server overload and maintain responsiveness.

Exploring Network Protocols

Understanding network protocols is crucial for troubleshooting and configuring network devices. Here are some essential network protocols:

  • TCP/IP: The foundational suite of protocols for the internet, consisting of the Transmission Control Protocol (TCP) and the Internet Protocol (IP). TCP ensures reliable data delivery, while IP is responsible for addressing and routing.

  • ARP (Address Resolution Protocol): Used to map IP addresses to MAC addresses within a local network.

  • ICMP (Internet Control Message Protocol): Used for network diagnostics, including ping requests and error messages.

  • BGP (Border Gateway Protocol): The protocol that governs routing on the internet, used by routers to determine the best path for data transmission.

  • SSH (Secure Shell): A secure protocol for remote access to network devices and servers.

  • HTTP (Hypertext Transfer Protocol) and HTTPS (HTTP Secure): Protocols used for web communication.

  • FTP (File Transfer Protocol): Used for transferring files over a network.

  • SMTP (Simple Mail Transfer Protocol): Used for sending email messages.

  • POP3 (Post Office Protocol 3) and IMAP (Internet Message Access Protocol): Protocols used for retrieving email from servers.

Practical Networking with Virtual Machines

To gain practical experience with networking concepts, you can set up virtual machines (VMs) on your local system using tools like libvirt/KVM. Here's a basic example of how to create and network VMs:

  1. Install libvirt/KVM: If you haven't already, install libvirt/KVM on your system. You can use tools like virt-manager or the virsh command-line interface to manage VMs.

  2. Create VMs: Create one or more VMs, specifying parameters like CPU, memory, and storage.

  3. Network Configuration: Configure the network for your VMs. You can use bridged networking to connect VMs directly to your LAN, or you can set up a private virtual network for isolated communication between VMs.

  4. Assign IP Addresses: Depending on your network configuration, you can use DHCP to automatically assign IP addresses to VMs or manually configure static IP addresses.

  5. Install Networking Services: Inside your VMs, you can install and configure networking services like DHCP, DNS, or a web server to gain hands-on experience.

  6. Test Connectivity: Verify that your VMs can communicate with each other and with external networks. Use tools like ping, nslookup, and curl to test network connectivity and resolve domain names.

  7. Firewall Rules: Implement firewall rules to control incoming and outgoing traffic to and from your VMs.

  8. VPN Setup: Experiment with setting up VPN connections between VMs or between a VM and an external VPN server.

  9. Load Balancing: Explore load balancing by creating multiple VMs and distributing traffic among them.

  10. Security: Practice network security by implementing access controls, intrusion detection systems, and security policies within your VMs.

Additional Resources

To further your understanding of networking, consider exploring the following resources:

  1. Books: Books like "TCP/IP Illustrated" by Richard Stevens and "Computer Networking: Principles, Protocols, and Practice" by Olivier Bonaventure provide in-depth coverage of networking concepts.

  2. Online Courses: Platforms like Coursera, edX, and Udemy offer networking courses that cover topics from the basics to advanced routing and switching.

  3. Network Simulators: Tools like GNS3 and Packet Tracer allow you to create virtual networks for hands-on practice.

  4. Certifications: Pursuing networking certifications such as CompTIA Network+ or Cisco CCNA can provide structured learning and validation of your networking skills.

  5. Networking Forums: Participate in online forums like Stack Overflow and Reddit's r/networking to ask questions and learn from experienced network professionals.

  6. Vendor Documentation: If you work with specific networking hardware or software, refer to the official documentation provided by the vendor for detailed configuration guides and troubleshooting tips.

Remember that networking is a vast field, and mastery comes with practice and continuous learning. Whether you're pursuing a career in IT or simply want to enhance your technical knowledge, a strong foundation in networking is an invaluable asset in today's interconnected world.

Top comments (0)