DEV Community

Cover image for The Best Brief Introduction to L4 and L7 Proxies and Their Setup
mpoiiii
mpoiiii

Posted on

The Best Brief Introduction to L4 and L7 Proxies and Their Setup

This article will provide a detailed introduction to the basics of network proxy services, including the principles and functions of L4 (Layer 4 proxy) and L7 (Layer 7 proxy). Finally, the article will give a brief overview of proxy service solutions based on different network scales.

Basic Concepts and Functions of Network Proxy

Image description

A network proxy service is an intermediary service through which clients can indirectly communicate with other network resources. The proxy server transmits requests and responses between clients and target servers, providing the following main functions:

  1. Anonymity: Hides the client's IP address, enhancing privacy and security.
  2. Access Control: Allows or denies access to specific websites or resources based on policies.
  3. Content Filtering: Blocks inappropriate content or malware.
  4. Caching: Stores frequently used resources to speed up access.
  5. Load Balancing: Distributes traffic to optimize resource usage and improve performance.

While network proxy services offer various advantages, the primary benefit remains in load balancing. Through strategies, network traffic is scientifically planned by forwarding.

Load balancing is achieved through various algorithms and strategies, such as round-robin, least connections, and source IP hash, to ensure the scientific and reasonable distribution of traffic.

What are L4 and L7 Level Proxies?

L4 and L7 refer to the layers in the OSI model. L4 and L7 level proxies refer to proxy servers operating at the 4th layer (transport layer) and the 7th layer (application layer) of the OSI model, respectively.

So, what is the OSI Seven-Layer Model? The OSI seven-layer model is a layered architecture used to understand and design network communication, divided into the following seven layers:

  1. Physical Layer: Responsible for transmitting raw bit streams.
  2. Data Link Layer: Provides node-to-node data transfer, responsible for framing, transmission, and error detection.
  3. Network Layer: Manages packet routing and forwarding, handling logical addresses (e.g., IP addresses).
  4. Transport Layer: Manages end-to-end data transfer, providing transport services (e.g., TCP/UDP).
  5. Session Layer: Manages sessions and connections, responsible for establishing, maintaining, and terminating communication sessions.
  6. Presentation Layer: Handles data formatting, encryption, and decryption.
  7. Application Layer: Provides network services and application interfaces, such as HTTP, FTP, SMTP, etc.

Image description

L4 proxy operates at the transport layer, primarily handling transport layer protocols such as TCP and UDP. Therefore, L4 proxies determine forwarding rules based on the IP address and port of the third layer.

For example, the HTTP protocol uses port 80 by default, while the HTTPS protocol uses port 443 by default. L4 proxy servers can determine the type of access based on these ports and forward requests to the appropriate server for processing.

Clients (IP:Port)          L4 Proxy Server    Target Servers
  |                             |                   |
  |                             |                   |
  V                             V                   V
[Client 1 (IP1:Port1)] --->  [IP:Port]      ---> [Server 1]
[Client 2 (IP2:Port2)] --->                 ---> [Server 2]
[Client 3 (IP3:Port3)] --->                 ---> [Server 3]
Enter fullscreen mode Exit fullscreen mode

L7 proxy operates at the application layer, setting forwarding rules based on application layer protocols. Thus, L4 proxy is the foundation for L7 proxy.

Clients (Request)    L7 Proxy Server        Target Servers
  |                       |                       |
  |                       |                       |
  V                       V                       V
[Client 1 (URL1)]  --->[URL/Cookie etc.]--->  [Server 1]
[Client 2 (URL2)]  --->                 --->  [Server 2]
[Client 3 (URL3)]  --->                 --->  [Server 3]
Enter fullscreen mode Exit fullscreen mode

Since application layer protocols contain more information, forwarding rules can be more precise. For example, requests can be forwarded to different servers based on device types. Requests from more powerful devices can be forwarded to high-performance image and video servers, while requests from older devices can be forwarded to servers with lower resource consumption.

L7 proxy can handle more content, such as different language types, device types, and regional information to set forwarding rules.

Additionally, besides the commonly used L4 and L7 proxies, there are also L2 and L3 proxies. L2 proxy sets a virtual MAC address to receive requests and then assigns the actual MAC address. L3 proxy sets a virtual IP address to receive requests and then assigns the actual IP address.

Advantages and Disadvantages of L4 and L7 Proxies

Since application layer information is richer than network layer information, L7 proxies can utilize more information, making them more flexible than L4 proxies. L7 proxies can perform more granular traffic distribution based on specific request content (e.g., URL path, Cookie).

Because L7 proxies have more information, they can handle network security tasks on the proxy server, such as preventing SQL injection and cross-site scripting attacks.

On the other hand, L4 proxies have the advantage of simplicity. Since L4 proxies do not need to parse a lot of information, their processing speed is very fast. When dealing with a large amount of traffic, if only simple forwarding strategies are needed, L4 proxies will be significantly faster.

Additionally, since L4 proxies obtain less information, they are less intrusive to user privacy. L4 proxies only analyze transport layer header information for traffic forwarding, without involving specific application layer data content.

Implementation of Proxy Technology

The implementation of load balancing solutions varies with different network scales. If you are just transitioning from a single server, setting up a dedicated load server network is impractical.

  • Small-scale network service stage: At this stage, you can directly use Nginx. Nginx is easy to get started with and configure, and it operates on the application layer protocol (HTTP). You can directly place it on the load balancing gateway using many integrated functions.

  • Medium-scale network service stage: When your data processing servers exceed ten, you can consider using LVS (Linux Virtual Server) or commercial Array Networks devices. At this point, Nginx can act as a node for LVS or Array, depending on the company's scale and budget. Array Networks devices have very powerful application delivery functions.

  • Large-scale network service stage: When your product has gained a certain reputation in the market, you need customized load balancing strategies. A specialized team is required to develop the solution, and options will become more diverse.

Additionally, there is a most convenient solution that can be used at any scale, which is to use third-party proxy services, such as the EdgeOne platform, starting at just a few dollars per month.

The benefits of this solution are clear: it requires minimal development work and no need to purchase and set up proxy servers. Furthermore, such services usually come with built-in network security protection, solving one of the biggest headaches for startup personnel.

Top comments (0)