Operations 14 min read

Mastering Load Balancing: From HTTP Redirects to LVS Direct Routing

This article explains the concept of load balancing, compares HTTP redirection, DNS‑based balancing, reverse‑proxy solutions, and Linux Virtual Server techniques (LVS‑NAT, LVS‑DR, LVS‑TUN), detailing their mechanisms, advantages, limitations, and practical configuration commands for building scalable, high‑performance server farms.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Mastering Load Balancing: From HTTP Redirects to LVS Direct Routing
Load balancing overview
Load balancing overview

1. HTTP Redirection

When an HTTP client requests a URL, the web server can respond with a Location header pointing to a new URL, causing the client to issue a second request. This method suffers from throughput limits because the main server must handle all redirected traffic, and the depth of redirects varies, making load distribution unpredictable.

2. DNS Load Balancing

DNS resolves domain names to IP addresses and can return multiple A records, effectively distributing client requests across several servers. For example, using dig baidu shows three A records. DNS‑based balancing avoids the throughput bottleneck of HTTP redirects, but administrators cannot directly see which server handles a request, and DNS cannot incorporate HTTP‑level context.

dig output
dig output

3. Reverse Proxy Load Balancing

Reverse proxies forward HTTP requests to backend servers, waiting for responses before returning them to clients. They support weighted scheduling, health monitoring, and sticky sessions, but introduce additional processing overhead (thread creation, TCP connections, kernel‑user space switches). For static content, DNS‑based balancing may be more efficient.

4. IP Load Balancing (LVS‑NAT)

Linux Virtual Server (LVS) with NAT operates at the transport layer, rewriting destination IP addresses. The ipvsadm tool configures virtual services and real servers. Example commands:

echo 1 > /proc/sys/net/ipv4/ip_forward
route add default gw xx.xx.xx.xx
ipvsadm -A -t 111.11.11.11:80 -s rr

Adding two real servers with NAT:

ipvsadm -a -t 111.11.11.11:80 -r 10.10.120.210:8000 -m

Running ipvsadm -L -n displays server status. NAT‑based LVS can achieve higher throughput than reverse proxies because packet forwarding occurs in the kernel.

LVS NAT configuration
LVS NAT configuration

5. Direct Routing (LVS‑DR)

LVS‑DR works at the data‑link layer, changing only the destination MAC address. Real servers send responses directly to clients, bypassing the load balancer, which removes the balancer’s bandwidth limitation. Configuration steps include adding an IP alias on the loopback interface and adjusting ARP settings:

echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce

After setting up the alias (e.g., 10.10.120.193), use ipvsadm to create a virtual service and real servers with the -g flag for direct routing:

ipvsadm -A -t 10.10.120.193:80 -s rr
ipvsadm -a -t 10.10.120.193:80 -r 10.10.120.210:8000 -g

Direct routing is ideal for high‑throughput services where response traffic far exceeds request traffic.

IP alias configuration
IP alias configuration

6. IP Tunnel (LVS‑TUN)

LVS‑TUN encapsulates incoming IP packets in a new IP header and forwards them through an IP tunnel to backend servers, which can reside in different network segments. This method also requires legitimate IP addresses for the real servers and is suitable when servers need to be geographically dispersed.

Both LVS‑DR and LVS‑TUN are appropriate for asymmetric web services; the choice depends on network topology and deployment requirements.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

load balancingLinuxreverse proxyNetworkingDNSLVS
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.