Marcio Cunha

Configuring the VRRP Protocol without Proprietary Hardware Using Keepalived

Learn how to implement network high availability with the VRRP protocol and Keepalived on commodity servers, eliminating dependence on expensive routers.

Marcio Cunha5 min
Also available in:EspañolPortuguês
Summary
  • The VRRP protocol creates a shared IP address among multiple computers to ensure automatic redundancy during failures.
  • Keepalived implements VRRP in free software, turning standard servers into high-availability nodes without licensing costs.
  • The configured priority defines which machine takes control of the virtual IP address during normal operation.
  • Custom monitoring scripts allow Keepalived to give up the IP if essential services like Nginx or databases crash.
  • Failure tests simulating the disconnection of network cables validate the architecture resilience before production.

The Challenge of High Availability in Modern Networks

Ensuring that a digital service remains online 24 hours a day requires eliminating any single point of failure in the infrastructure. In practice, this means that if the primary server hosting a website or database suffers a physical outage, another machine must take over immediately without users noticing any interruption. Historically, this task was assigned to routers and load balancers from traditional and extremely expensive brands, known in the market as proprietary hardware. However, the evolution of free software makes it possible to achieve the same level of resilience using commodity computers and open-source operating systems.

The key to solving this problem without spending a fortune lies in standardized routing redundancy protocols. The most famous of them is VRRP, an acronym for Virtual Router Redundancy Protocol. In essence, VRRP allows two or more physical computers to share a single virtual IP address, which acts as the public facade for network clients. While backstage tasks are being alternated, the outside world sees only a single stable and reliable destination, drastically simplifying corporate network architecture of any size.

How the VRRP Protocol Works in Practice

Imagine VRRP as a building where multiple superintendents take turns managing operations, but the office phone number remains always the same for the residents. In network architecture, the protocol elects one machine to act as the master router, while the others remain on standby as backup copies. The master constantly sends life signals known as advertisement messages to peers on the local network, notifying them that it continues operating normally and handling data traffic.

If the master server suffers an electrical outage or loses its network connection, it stops emitting these advertisement messages. After a brief pre-established time interval, the backup servers notice the silence and initiate a new election based on priority criteria defined by the administrator. The machine with the highest priority takes control of the virtual IP address, updates clients' ARP tables, and starts responding to data packets. This entire process happens within seconds, shielding the application against prolonged downtime.

Implementing Keepalived on Linux Servers

Keepalived is the standard market software that implements the VRRP protocol on Linux-based operating systems. In practice, it works as a background service that monitors system health and manages the addition and removal of the virtual IP address on network interfaces. To get it running, the first step is to install the package through the chosen distribution's package manager.

  1. Install Keepalived on the primary server and backup server by running the system package manager command.
    sudo apt-get update && sudo apt-get install keepalived -y
  2. Edit the main configuration file located in the system service directory to define network parameters.
    sudo nano /etc/keepalived/keepalived.conf
  3. Restart the service to apply the new high-availability rules and verify execution status.
    sudo systemctl restart keepalived && sudo systemctl status keepalived

The Keepalived configuration file requires meticulous attention to detail to avoid conflicts on the local network. Inside it, we define blocks known as VRRP instances, where we specify the connected network interface, the numeric instance identifier that must be identical across all machines in the group, and the numeric priority. The primary server receives a higher priority, such as 101, while the backup server receives a lower value, such as 100. The shared authentication password ensures that only authorized servers participate in that IP election.

Advanced Service Monitoring with Scripts

One of the most common mistakes when configuring high availability is believing it is enough to monitor whether the operating system is powered on. In practice, a server might have the operating system running perfectly, but with the web server frozen or the database corrupted, making the site inaccessible to users. To close this gap, Keepalived accepts custom check scripts that actively test the health of software running on the node.

These scripts execute simple check commands at regular intervals, such as trying to open a local HTTP connection or querying the database. If the check fails repeatedly, the script returns an error code instructing Keepalived to immediately lower that machine's priority. As a direct consequence of losing priority, the backup server notices the peer's weakness and immediately takes control of the virtual IP address, isolating the problematic machine for corrective maintenance without manual human intervention.

Validation, Resilience Testing, and Best Practices

Configuring Keepalived is only half of the engineering work; the other half consists of rigorously validating system behavior under adverse conditions. In practice, stress tests and real failure simulations are essential to ensure that transitions occur without packet loss or data corruption. The simplest and most revealing test consists of physically disconnecting the primary server's network cable while monitoring network traffic with diagnostic tools.

Another critical point of attention concerns the response time of advertisement messages, known as advertisement parameters and time intervals. Adjusting these values requires balancing failure detection speed with local network bandwidth consumption. Excessively aggressive values can generate false positives due to momentary network congestion, while overly slow values leave the system vulnerable to prolonged outages. Documenting the topology and keeping configuration files version-controlled ensures long-term operational sanity.

Final Considerations on Decoupled Infrastructure

Adopting the VRRP protocol via Keepalived represents a significant mindset shift in building resilient architectures. Instead of relying on expensive support contracts and hardware vendor black boxes, engineering teams regain total control over their local network behavior. The combination of free software with standard market servers democratizes access to high availability, allowing companies of any size to achieve reliability levels comparable to major tech giants.

Understanding theoretical foundations and mastering practical Keepalived implementation paves the way for more flexible, scalable, and economical infrastructure projects. By eliminating commercial middlemen and investing in smart automation, the technical team ensures solid operational stability prepared for future business challenges.