Nginx Free DNS Load Balance + HA



Nginx DNS Load Balancer 

Running Nginx with this snippet at /etc/nginx/nginx.conf will balance both DNS Servers to get HA

 stream {
        upstream dns_servers {
            server 127.0.0.1:5353 fail_timeout=5s;
            server 192.168.122.39:5353 fail_timeout=10s;
        }
       server {
            listen 53  udp;
            listen 53; #tcp
            proxy_pass dns_servers;
            proxy_responses 1;
            proxy_timeout   2s;
            error_log  /var/log/nginx/dns.log info;
       }
}


Keepalived

In keepalived the floating ip is defined with the file /etc/keepalived/keepalived.conf

vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 254
advert_int 1
authentication {
auth_type PASS
auth_pass 12345
}
virtual_ipaddress {
192.168.122.2/24
}
}



Tags VRRP, Nginx, keepalived, DNS, HA, Loadbalance, Loadbalancer


References:

https://www.nginx.com/blog/load-balancing-dns-traffic-nginx-plus/

https://www.redhat.com/sysadmin/keepalived-basics