High Availability with VRRP
High Availability with VRRP
Section titled “High Availability with VRRP”RouterOS Version: 7.x+ Difficulty: Intermediate Estimated Time: 30 minutes
TL;DR (Quick Start)
Section titled “TL;DR (Quick Start)”For the impatient: here’s the 30-second version.
# Router A (Master): priority 254/interface vrrp add name=vrrp1 interface=ether2 vrid=1 priority=254/ip address add address=10.0.0.1/32 interface=vrrp1
# Router B (Backup): priority 100/interface vrrp add name=vrrp1 interface=ether2 vrid=1 priority=100/ip address add address=10.0.0.1/32 interface=vrrp1Overview
Section titled “Overview”Virtual Router Redundancy Protocol (VRRP) eliminates the single point of failure inherent in static default gateway configurations. Instead of relying on a single router, VRRP creates a virtual router that can seamlessly fail over between multiple physical devices, ensuring continuous network connectivity even when individual routers fail.
This guide explains VRRP concepts, implementation strategies, and the critical design decisions that determine whether your high availability setup provides genuine redundancy or becomes a source of network instability.
The Gateway Problem
Section titled “The Gateway Problem”In traditional networks, hosts are configured with a static default gateway:
The problem: If the router fails, all hosts lose internet connectivity, even if backup routers exist on the network.
Traditional solutions and their limitations:
- Multiple static routes: Requires manual intervention during failures
- Dynamic routing protocols: Too complex for simple LANs, adds overhead
- Router redundancy without VRRP: Requires host reconfiguration during failures
VRRP: The Virtual Router Solution
Section titled “VRRP: The Virtual Router Solution”VRRP solves this by creating a virtual router with its own IP and MAC address. Multiple physical routers participate in this virtual router, but only one is active (Master) at any time:
Key benefits:
- Transparent failover: Hosts never need reconfiguration
- Sub-second detection: Failure detection within 3 seconds
- Automatic recovery: Higher priority routers automatically resume Master role
- Load balancing: Multiple virtual routers can distribute traffic
VRRP Protocol Fundamentals
Section titled “VRRP Protocol Fundamentals”Virtual Router Anatomy
Section titled “Virtual Router Anatomy”A Virtual Router (VR) consists of:
- Virtual Router ID (VRID): Unique identifier (1-255) for the virtual router
- Virtual IP Address: The gateway IP that hosts use
- Virtual MAC Address: Automatically generated as
00:00:5E:00:01:XX(where XX is VRID in hex) - Master Router: The currently active router handling traffic
- Backup Routers: Standby routers monitoring the Master
State Machine
Section titled “State Machine”Each VRRP router operates in one of three states:
INIT State:
- Initial state during startup
- Router determines its role based on priority
- Transitions to BACKUP or MASTER
BACKUP State:
- Monitors Master’s advertisement packets
- Does not respond to ARP requests for virtual IP
- Does not forward traffic for virtual IP
- Becomes Master if advertisements stop or higher priority
MASTER State:
- Sends periodic advertisement packets (default: 1 second)
- Responds to ARP requests with virtual MAC
- Forwards traffic for virtual IP addresses
- Steps down if higher priority router appears (unless preemption disabled)
Advertisement Protocol
Section titled “Advertisement Protocol”VRRP uses IP protocol 112 with these characteristics:
- IPv4 Multicast: 224.0.0.18
- IPv6 Multicast: FF02::12
- TTL: Always 255 (prevents forwarding)
- Source: Router’s primary interface IP
- Authentication: Optional (deprecated in VRRPv3)
Advertisement packet contains:
- VRID and priority
- Advertisement interval
- List of associated IP addresses
- Authentication data (if enabled)
Master Election Process
Section titled “Master Election Process”Priority-Based Election
Section titled “Priority-Based Election”The router with the highest priority becomes Master:
- Priority range: 1-254 (255 reserved for IP address owner)
- Default priority: 100
- Owner priority: 255 (router that owns the virtual IP)
Election scenarios:
- Initial startup: Highest priority router becomes Master
- Master failure: Highest priority Backup becomes Master
- Higher priority appears: Master steps down (if preemption enabled)
- Equal priority: Router with highest IP address wins
Preemption Behavior
Section titled “Preemption Behavior”Preemption enabled (default):
Time: 0s 10s 20s 30sR1: M → B → M (Priority 254)R2: B → M → B (Priority 100) ↑ ↑ ↑ Start R1 fails R1 returnsPreemption disabled:
Time: 0s 10s 20s 30sR1: M → B → B (Priority 254)R2: B → M → M (Priority 100) ↑ ↑ ↑ Start R1 fails R1 returns (stays Backup)When to disable preemption:
- Prevent unnecessary failovers during maintenance
- Avoid disruption from flapping routers
- Maintain stable Master during brief outages
IPv4 vs IPv6 Implementation
Section titled “IPv4 vs IPv6 Implementation”IPv4 VRRP (VRRPv2/v3)
Section titled “IPv4 VRRP (VRRPv2/v3)”Address Resolution:
- Master responds to ARP requests with virtual MAC
- Backup routers ignore ARP requests for virtual IP
- Gratuitous ARP sent during Master transition
Configuration example:
/interface vrrp add interface=ether2 vrid=1 priority=254/ip address add address=10.0.0.1/32 interface=vrrp1IPv6 VRRP (VRRPv3 only)
Section titled “IPv6 VRRP (VRRPv3 only)”Neighbor Discovery:
- Uses link-local addresses for communication
- Master sends unsolicited Neighbor Advertisements
- Router Advertisement messages for virtual addresses
Configuration example:
/interface vrrp add interface=ether2 vrid=1 version=3 v3-protocol=ipv6/ipv6 address add address=2001:db8::1/64 interface=vrrp1 advertise=yesKey differences:
- IPv6 requires VRRPv3 (
version=3 v3-protocol=ipv6) - No additional IPv6 address needed on physical interface
- Automatic link-local address handling
Connection Tracking Synchronization
Section titled “Connection Tracking Synchronization”RouterOS v7 supports connection tracking synchronization between VRRP routers, ensuring stateful connections survive failovers.
How It Works
Section titled “How It Works”Synchronization behavior:
- Only Master → Backup synchronization
- Connections synchronized before priority changes
- UDP port 8275 used for sync traffic
- Requires connection tracking enabled
Configuration:
/ip firewall connection tracking set enabled=yes/interface vrrp set vrrp1 sync-connection-tracking=yesActive-Active Mode
Section titled “Active-Active Mode”For load balancing scenarios with multiple VRRP groups:
# Router 1 - Master for VRID 1, Backup for VRID 2/interface vrrp add name=vrrp1 vrid=1 priority=254 connection-tracking-mode=active-active connection-tracking-port=8275/interface vrrp add name=vrrp2 vrid=2 priority=100 connection-tracking-mode=active-active connection-tracking-port=8276
# Router 2 - Backup for VRID 1, Master for VRID 2/interface vrrp add name=vrrp1 vrid=1 priority=100 connection-tracking-mode=active-active connection-tracking-port=8275/interface vrrp add name=vrrp2 vrid=2 priority=254 connection-tracking-mode=active-active connection-tracking-port=8276Important: Each VRRP group must use a unique connection-tracking-port.
Load Balancing with Multiple Virtual Routers
Section titled “Load Balancing with Multiple Virtual Routers”Instead of having one router idle, create multiple virtual routers to distribute load:
Virtual Router Configuration:
- VR1: 10.0.0.1 (Router A=Master, Router B=Backup)
- VR2: 10.0.0.4 (Router B=Master, Router A=Backup)
Client Configuration:
- 50% of clients use 10.0.0.1 as gateway
- 50% of clients use 10.0.0.4 as gateway
Benefits:
- Both routers actively handle traffic
- Automatic failover for both groups
- Better resource utilization
- Scalable to more routers/groups
Router A configuration:
/interface vrrp add name=vrrp1 interface=ether2 vrid=1 priority=254/interface vrrp add name=vrrp2 interface=ether2 vrid=2 priority=100/ip address add address=10.0.0.1/32 interface=vrrp1/ip address add address=10.0.0.4/32 interface=vrrp2Router B configuration:
/interface vrrp add name=vrrp1 interface=ether2 vrid=1 priority=100/interface vrrp add name=vrrp2 interface=ether2 vrid=2 priority=254/ip address add address=10.0.0.1/32 interface=vrrp1/ip address add address=10.0.0.4/32 interface=vrrp2Group Authority (Multi-Interface VRRP)
Section titled “Group Authority (Multi-Interface VRRP)”When running VRRP on multiple interfaces (e.g., LAN and WAN), use group authority to ensure consistent state:
Problem without group authority:
- Router A: WAN=Master, LAN=Backup
- Router B: WAN=Backup, LAN=Master
- Result: Broken routing, NAT failures
Solution with group authority:
/interface vrrp add name=vrrp-wan interface=ether1 vrid=1 priority=254/interface vrrp add name=vrrp-lan interface=ether2 vrid=2 priority=254 group-authority=vrrp-lan/interface vrrp set vrrp-wan group-authority=vrrp-lanGroup authority ensures:
- All VRRP instances in group have same state
- Only group authority sends control traffic
- Consistent Master/Backup across interfaces
Security Considerations
Section titled “Security Considerations”Authentication Methods
Section titled “Authentication Methods”VRRPv2 supports:
none: No authentication (default)simple: Plain-text passwordah: HMAC-MD5 authentication
VRRPv3:
- Authentication deprecated per RFC 5798
- Rely on network-level security (IPsec, VLANs)
Configuration example:
/interface vrrp add interface=ether2 vrid=1 authentication=ah password=SecurePassword123Network Isolation
Section titled “Network Isolation”Best practices:
- Dedicated VLAN: Run VRRP on management VLAN
- Access control: Restrict VRRP multicast traffic
- Monitoring: Log VRRP state changes
- Physical security: Secure router console access
Preventing Attacks
Section titled “Preventing Attacks”VRRP vulnerabilities:
- Priority manipulation: Attacker claims Master role
- Advertisement flooding: DoS via excessive packets
- MAC spoofing: Impersonate virtual MAC
Mitigation strategies:
# Enable authentication/interface vrrp set [find] authentication=ah password=StrongPassword
# Monitor state changes/system logging add topics=vrrp action=memory
# Restrict multicast access/ip firewall filter add chain=input protocol=vrrp src-address=!10.0.0.0/24 action=dropConfiguration Steps
Section titled “Configuration Steps”This section provides a minimal testable configuration demonstrating basic VRRP failover.
Step 1: Create VRRP Interface
Section titled “Step 1: Create VRRP Interface”Create a VRRP interface on the LAN-facing port:
/interface vrrp add name=vrrp1 interface=ether2 vrid=1 priority=254Step 2: Assign Virtual IP Address
Section titled “Step 2: Assign Virtual IP Address”Configure the virtual IP that clients will use as their gateway:
/ip address add address=10.0.0.1/32 interface=vrrp1Note: Use /32 netmask for virtual IP when the physical interface has an IP in the same subnet.
Verification
Section titled “Verification”Confirm VRRP interface is created and in Master state:
/interface vrrp print detail where name=vrrp1Expected Output:
0 RM name="vrrp1" mtu=1500 mac-address=00:00:5E:00:01:01 arp=enabled interface=ether2 vrid=1 priority=254 interval=1 preemption-mode=yes authentication=none version=3 v3-protocol=ipv4Check that the virtual IP is assigned:
/ip address print where interface=vrrp1Expected Output:
0 10.0.0.1/32 vrrp1Troubleshooting
Section titled “Troubleshooting””VRRP interface shows ‘B’ flag instead of ‘M’”
Section titled “”VRRP interface shows ‘B’ flag instead of ‘M’””The router is in Backup state instead of Master. Check:
- Priority configuration: Ensure this router has highest priority
- Network connectivity: Verify another Master isn’t already active
- VRID conflicts: Confirm VRID is unique on the network segment
- Advertisement reception: Check if receiving advertisements from higher priority router
# Check for other VRRP routers/tool sniffer quick interface=ether2 protocol=vrrp duration=10”Clients can’t reach virtual IP”
Section titled “”Clients can’t reach virtual IP””Verify ARP resolution:
# From client, check ARP tablearp -a | grep 10.0.0.1
# Should show virtual MAC: 00:00:5e:00:01:XXCheck VRRP state:
/interface vrrp monitor vrrp1Common causes:
- VRRP interface not in Master state
- Virtual IP not properly assigned
- Firewall blocking VRRP traffic
- Physical interface down
”Failover takes too long”
Section titled “”Failover takes too long””Adjust advertisement interval:
/interface vrrp set vrrp1 interval=100msEnable fast failure detection:
- Use shorter intervals (minimum 10ms)
- Monitor physical link state
- Implement BFD for faster detection
”Split-brain scenario”
Section titled “”Split-brain scenario””Two routers both think they’re Master:
Causes:
- Network partition between routers
- Firewall blocking VRRP multicast
- Different advertisement intervals
Diagnosis:
# Check VRRP logs/log print where topics~"vrrp"
# Monitor VRRP traffic/tool sniffer quick interface=ether2 protocol=vrrpResolution:
- Verify network connectivity between routers
- Check firewall rules for protocol 112
- Ensure identical advertisement intervals
- Verify multicast routing if routers on different subnets
”Connection tracking sync not working”
Section titled “”Connection tracking sync not working””Prerequisites check:
# Verify connection tracking is enabled/ip firewall connection tracking print
# Check sync configuration/interface vrrp print detail where sync-connection-tracking=yesCommon issues:
- Connection tracking disabled
- UDP port 8275 blocked by firewall
- Incorrect remote-address configuration
- Version mismatch between routers
Advanced Scenarios
Section titled “Advanced Scenarios”VRRP with NAT
Section titled “VRRP with NAT”When using VRRP on WAN interfaces with NAT:
# WAN VRRP interface/interface vrrp add name=vrrp-wan interface=ether1 vrid=10 priority=254
# Virtual WAN IP/ip address add address=203.0.113.1/32 interface=vrrp-wan
# NAT rule using virtual interface/ip firewall nat add chain=srcnat out-interface=vrrp-wan action=masqueradeVRRP with DHCP
Section titled “VRRP with DHCP”Ensure DHCP server binds to virtual interface:
# DHCP server on VRRP interface/ip dhcp-server add name=dhcp-vrrp interface=vrrp1 address-pool=lan-pool
# DHCP network with virtual gateway/ip dhcp-server network add address=10.0.0.0/24 gateway=10.0.0.1 dns-server=10.0.0.1Monitoring and Alerting
Section titled “Monitoring and Alerting”Script for VRRP state monitoring:
# Create script to check VRRP state/system script add name=vrrp-monitor source={ :local vrrpState [/interface vrrp get vrrp1 running] :if ($vrrpState = false) do={ /log warning "VRRP interface vrrp1 is down" # Add notification logic here }}
# Schedule regular checks/system scheduler add name=vrrp-check interval=30s on-event=vrrp-monitorSNMP monitoring:
- OID 1.3.6.1.2.1.68.1.3.1.4 (vrrpOperState)
- Values: 1=initialize, 2=backup, 3=master
Related Topics
Section titled “Related Topics”Prerequisites
Section titled “Prerequisites”- IP Address Configuration - VRRP requires virtual IP addresses
- Static Routes - clients use VRRP VIP as gateway
Related High Availability
Section titled “Related High Availability”- Bonding/LACP - link-level redundancy
- OSPF - dynamic routing with redundant paths
- BGP - multi-homed redundancy
Monitoring
Section titled “Monitoring”- Netwatch - monitor VRRP peer health
- Scheduler - VRRP state monitoring scripts
- Logging - VRRP state change alerts
Security
Section titled “Security”- Firewall Basics - allow VRRP protocol (112)