Skip to main content

Network Protocol

Network Protocol

Network protocols are the set of rules and conventions that govern how data is transmitted and received over a network. They define the format, structure, and order of messages exchanged between network devices. Think of them as the language that computers use to communicate with each other over a network.

Key Function of Network Protocol

  1. Addressing: Identifying and locating devices on the network (e.g., IP addresses, MAC addresses).
  2. Encapsulation: Packaging data into units suitable for transmission (e.g., adding headers and trailers).
  3. Routing: Determining the best path for data to travel across the network.
  4. Flow Control: Managing the rate of data transmission to prevent network congestion.
  5. Error Detection and Correction: Identifying and correcting errors that occur during transmission.
  6. Connection Management (for connection-oriented protocols): Establishing and terminating connections between devices.

Protocol Layering (OSI Model & TCP/IP Model)

Network protocols are often organized in layers, with each layer responsible for a specific set of functions. Two common models are the OSI model (7 layers) and the TCP/IP model (4 layers). While the OSI model is a theoretical framework, the TCP/IP model is more closely aligned with how the internet actually works.

TCP/IP Model
  1. Application Layer: Provides services to applications (e.g., HTTP, FTP, SMTP).
  2. Transport Layer: Handles end-to-end communication between applications (e.g., TCP, UDP).
  3. Internet Layer: Responsible for routing data packets across networks (e.g., IP).
  4. Network Access Layer: Deals with the physical transmission of data over the network medium (e.g., Ethernet, Wi-Fi).
Importance of network protocols

Network protocols are essential for enabling communication between diverse devices and networks. They provide a standardized way for data to be exchanged, regardless of the underlying hardware or operating system. Without network protocols, the internet and other networks would not function

TCP/UDP Connectinon

TCP (Transmission Control Protocol)

A connection-oriented, reliable transport layer protocol that provides guaranteed, ordered delivery of data between applications.

TCP Key Point
  1. Connection-oriented: Requires a three-way handshake to establish a connection before data transfer.
  2. Reliable: Uses acknowledgements (ACKs) and retransmissions to ensure data integrity and delivery.
  3. Ordered: Data arrives in the same sequence it was sent.
  4. Heavyweight: More overhead due to connection management and error handling.
  5. Suitable for: Applications requiring reliability and order, such as web browsing, file transfer, email.
TCP Connection Establishment (Three-way handshake)
  1. SYN (Synchronize): The client sends a SYN packet to the server, indicating its desire to establish a connection and suggesting an initial sequence number (ISN).
  2. SYN-ACK (Synchronize-Acknowledge): The server responds with a SYN-ACK packet. It acknowledges the client's SYN by incrementing the client's ISN and sending its own ISN.
  3. ACK (Acknowledge): The client sends an ACK packet back to the server, acknowledging the server's SYN-ACK by incrementing the server's ISN. The connection is now established, and data transfer can begin.
TCP Connection Termination (Four-way handshake)
  1. FIN (Finish): The client sends a FIN packet to the server, indicating that it has finished sending data.
  2. ACK: The server acknowledges the client's FIN with an ACK. The server may still have data to send.
  3. FIN: Once the server is also ready to close, it sends its own FIN to the client.
  4. ACK: The client acknowledges the server's FIN with an ACK. The connection is now fully closed.

UDP (User Datagram Protocol)

A connectionless, unreliable transport layer protocol that provides fast, low-latency data transfer without delivery guarantees.

UDP Key Point
  1. Connectionless: No connection setup is required before sending data.
  2. Unreliable: No guarantee of data delivery or order. Packets can be lost or arrive out of order.
  3. Unordered: Data may not arrive in the same sequence it was sent.
  4. Lightweight: Less overhead, making it faster and more efficient.
  5. Suitable for: Applications prioritizing speed and low latency over reliability, such as streaming video, online gaming, DNS.

Simulate Network Connectivity

alt text

Connectivity between server (simplified)

  1. Application Layer: An application on Server A initiates a request (e.g., a web browser requesting a page, an SSH client trying to connect). This request uses a specific protocol (HTTP, SSH, etc.).
  2. Transport Layer: The request is passed down to the transport layer, typically using TCP or UDP. If TCP is used, a connection is established with Server B using the three-way handshake.
  3. Network Layer: The transport layer segments the data into packets. The network layer (IP) adds IP addresses (source: Server A's IP, destination: Server B's IP) to each packet. Routing protocols determine the best path for the packets to reach Server B.
  4. Data Link Layer: At each hop (router or switch) along the path, the data link layer (Ethernet, Wi-Fi) adds MAC addresses to the packets to ensure they reach the next hop.
  5. Physical Layer: The physical layer transmits the raw bits over the network medium (cables, wireless signals).
  6. Reverse Process on Server B: Server B receives the packets, strips off the MAC and IP headers, reassembles the data, and passes it up to the appropriate application. The application processes the request and sends a response back to Server A through a similar process.

Troublshooting connectivity issue

Basic Checks
  1. Verify Network Configuration: Check the IP address, subnet mask, and default gateway on both servers. Use ip addr (Linux) or ipconfig (Windows). Ensure the servers are on the same network or can route to each other.
  2. Ping: ping server B from Server A. A successful ping indicates basic network connectivity. Traceroute: traceroute server B from Server A. This shows the path the packets take and can reveal network issues along the way.
Firewall
  1. Check Firewall Rules: Ensure firewalls on both servers (and any intervening firewalls) allow traffic on the necessary ports. Use iptables (Linux) or Windows Firewall rules.Temporarily Disable Firewalls (for testing only): If you suspect a firewall issue, temporarily disable it on both servers to see if connectivity is restored. Don't leave firewalls disabled in a production environment.
DNS
  1. DNS Resolution: If using hostnames, verify that Server A can resolve Server B's hostname to an IP address. Use nslookup server_B_hostname. /etc/hosts (Linux) or hosts file (Windows): Check if the hostname is correctly mapped to the IP address in the hosts file.
Network Devices
  1. Check Routers and Switches: Ensure routers and switches are functioning correctly and that there are no routing loops or other network issues.
Application-Specific Issues
  1. Check Application Logs: Examine the logs of the applications running on both servers for any error messages related to connectivity.
  2. Test with telnet or nc: Use telnet server B or port nc to test connectivity on a specific port. This can help isolate whether the problem is with the network or the application itself.
Advanced Troubleshooting:
  1. tcpdump or Wireshark: Use packet capture tools to analyze network traffic and identify the source of the problem.