VRRP router on ubuntu 14.04 for redundancy

Enable packet forwarding on both device

sudo echo 1 > /proc/sys/net/ipv4/ip_forward
sudo nano /etc/sysctl.conf

Enable net.ipv4.ip_forward=1 on /etc/sysctl.conf

sudo vim -c '%s/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/gc' -c 'wq' /etc/sysctl.conf
sysctl -p

Masquerade traffic

sudo iptables -t nat -I POSTROUTING -o wan -j MASQUERADE

More secure way to Masquerade traffi
You may add to /etc/rc.local to survive reboot

sudo iptables -t nat -I POSTROUTING -o wan -s 192.168.1.0/24 -j MASQUERADE

 

Install keepalived

sudo apt-get install keepalived

Make conf as follows

sudo nano /etc/keepalived/keepalived.conf

 

On MASTER router

vrrp_instance KimR {
  interface eth0 #change if yours is on another interface
  state MASTER #MASTER will always kick backup
  virtual_router_id 245 #This must be the same as backup router
  priority 100 #Higher for MASTER

authentication {
auth_type PASS
auth_pass monkey
}
virtual_ipaddress {
192.168.1.245 #Put your virtual floating IP
}
}

 

For BACKUP router

vrrp_instance KimR {
  interface eth0 #change if yours is on another interface
  state BACKUP #BACKUP will always give way to MASTER when MASTER is back
  virtual_router_id 245 #This must be the same as backup router
  priority 90 #Higher for MASTER

authentication {
auth_type PASS
auth_pass monkey
}
virtual_ipaddress {
192.168.1.245 #Put your virtual floating IP
}
}

Start keepalived service

sudo service keepalived start

Test your MASTER & BACKUP router

tail -f /var/log/syslog

Leave a Comment

Your email address will not be published. Required fields are marked *