Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ or unix shell script for DNS redundancy

Status
Not open for further replies.

menace212

Programmer
Jul 11, 2003
144
US
Hey everyone...I have a question...I know I can do this other ways, but I have a primary root DNS and another secondary DNS. The secondary DNS will server as the resolver for users while the primary is backing it up.. What I want to do create a program to ping the secondary to verify that's it's still up mainly using a cron job for various times. If the pings are unsuccessfuly, then the program will switch the primary DNS ip to what the secondary ip addrress and take over as a resolver. Once the secondary comes back online...The secondary will take back over as the primary resolver...Any ideas or examples on the type of program I should write....
 
Any samples I refer to to attempt to script this..I started using the shell script..But it looks like I going to need to write this in C++.Due to the functionality of what I want the program to do.

Example:
Test to see when the primary DNS is down.
Then if it then reconfigure the the server to take over using the ip address of the primary DNS
Then a test to verify if the primary DNS has came back online and if it has change back to it's original ip..

Any sample scripts I can refer to for this...
 
I got the program to test to change the ip and domain name now I need to test if the primary server comes up, what can I test to verify the primary is up...What kind of conflicts can I test for is the question now...Basically we will have conflicting ip's..And I can only see that on the switch level...
 
I think it would be a lot easier and safer to use a virtual IP address which the two servers can swap. That way there's no IP conflict and the servers aren't trying to swap their real addresses.
 
Doesn't every good resolv.conf - file contain two dns-server, to handle failures, or is this a linux-only solution?

If not, the 1. DNS could send 'alive' - messages in regular intervals (using cron) and a missing new 'alive' package could indicate problems.

seeking a job as java-programmer in Berlin:
 
That's pretty universal, at least as far as Windows, Unix, Linux and NetWare, and it would be my suggestion. I figured that this fell into the "other ways" that the OP mentioned.

Myself, I have the clients set up to use at least 2 nameservers so it doesn't really matter if one is down. A monitoring system (Nagios) alerts me to a problem and can take corrective action, but the loss of a server isn't a real issue.

When I do use failover systems (for MySQL), I use heartbeat from linux-ha.org. I don't know how easily that could be adapted to Unix, but it could be an option.

 
Not quite sure about how you would setup the virtual ip's though???...But here is the program below....What can I use to test the if condition..Because right now I'm stumped on what condition to test against...Any ideas...

#!/bin/sh
#
# This script is intended for the use of failover. Incase the secondary(Primary)# fails this script will change the ip's to take over resolving duties

change_ip="ifconfig eri0 100.1.1.1 netmask 255.255.255.224 up"
change_ip2="ifconfig eri0 100.1.1.8 netmask 255.555.255.224 up"
change_ip_down="ifconfig eri0 down"
ping_ip="ping -s 100.1.1.1"
move_hosts="cp /export/home/DNS_Programs/DNS_hosts /etc/hosts"
move_hosts2="cp /export/home/DNS_Programs/DNS_hosts2 /etc/hosts"
move_resolv="cp /export/home/DNS_Programs/DNS_resolv /etc/resolv.conf"
move_resolv2="cp /export/home/DNS_Programs/DNS_resolv2 /etc/resolv.conf"
snoop_ip="snoop"
arp_snoop="arping -q -c 3 -U -I eth0 100.1.1.1"
export move_hosts arp_snoop snoop_ip move_hosts2 move_resolv move_resolv2 chang_ip change_ip_down dig_lookup ping_ip


if [ -n "$(ping -c 1 100.1.1.1 | grep 100%)" ]
then
$change_addr_down
$change_ip
$move_hosts
$move_resolv
else
echo "Primary DNS has been operational for the last hour"

fi


if [ -n "$snoop_ip | grep 100.1.1.11" = 0 ]
then

$change_addr_down
#$chang_ip2
$move_hosts2
$move_resolv2

else
echo "Primary has been detected as down"
fi
 
I think it would be a lot easier and safer to use a virtual IP address which the two servers can swap. That way there's no IP conflict and the servers aren't trying to swap their real addresses."

How would I address the virtual ip address for the DNS program/server
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top