Geo DNS used to divide the traffic of a website to multiple server easily manage more network traffic. 

Redirect visitors dynamically to specific server based on country of origin . Assume that we have multiple servers located in different countries and onserver located in US which has configured Geo DNS. Users requesting from different countries all other requests forward onto a server, due to all request being served by the nearest server.

Simple Geo DNS Structure,




The below steps to install and configure Geo DNS, don’t confuse to below installation steps because I have explained errors and solutions which has faced while installation.

Step 1 : 

Install Bind with GeoDNS Patch: 


Download the GeoIP-1.4.8.tar.gz and extarct it
# cd /root/

# wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.8.tar.gz

# tar xf GeoIP-1.4.8.tar.gz

# cd GeoIP-1.4.8

# ./configure --prefix=/usr/local/geoip 

checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/root/download/GeoIP-1.4.8':
configure: error: no acceptable C compiler found in $PATH

Solution:

Install GCC packages and try to configure again
 
# yum install gcc  

Try Again,
 
# ./configure --prefix=/usr/local/geoip

configure: error: Zlib header (zlib.h) not found. Tor requires zlib to build.
You may need to install a zlib development package.


To resolved this error install zlib development package using yum command
 
# yum install zlib-devel.x86_64

# yum install gd

Try Again,
 
# ./configure --prefix=/usr/local/geoip

# make && make install

Step 2 :

Next, download GeoDNS patch file for Bind using wget command and extract archive file
 
# wget http://www.caraytech.com/geodns/bind-9.4.1-geodns-patch.tar.gz

# tar xf bind-9.4.1-geodns-patch.tar.gz

Download the Bind 9.4.1-P1 because we have downloaded same patch version,
 
# wget http://ftp.isc.org/isc/bind9/9.4.1-P1/bind-9.4.1-P1.tar.gz

# tar xf bind-9.4.1-P1.tar.gz
 

Step 3:

Next, configure patch file, 
 
# patch -p0 < bind-9.4.1-geodns-patch/patch.diff
-bash: patch: command not found


If the “patch” command was not found install patch using yum command,
 
# yum install patch

Try Again,
 
# patch -p0 < bind-9.4.1-geodns-patch/patch.diff

patching file bind-9.4.1-P1/lib/dns/acl.c
patching file bind-9.4.1-P1/lib/dns/include/dns/acl.h
patching file bind-9.4.1-P1/lib/isccfg/aclconf.c


Step 4 :

Configure GeoIP installation in /usr/local/geoip/,
 
# cd bind-9.4.1-P1

# CFLAGS="-I/usr/local/geoip/include" LDFLAGS="-L/usr/local/geoip/lib -lGeoIP" ./configure --prefix=/usr/local/bind

​checking for C compiler default output file name... a.out
checking whether the C compiler works... configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details.


To fix this error:

Open ld.so.conf file add the below line and save it
 
# vim /etc/ld.so.conf
 /usr/local/geoip/lib
# ldconfig 

Try again,
 
# CFLAGS="-I/usr/local/geoip/include" LDFLAGS="-L/usr/local/geoip/lib -lGeoIP" ./configure --prefix=/usr/local/bind

# make  &&  make install

. . . 
/bin/sh ./mkinstalldirs /usr/local/bind/bin \
/usr/local/bind/var/run /usr/local/bind/etc
mkdir /usr/local/bind/var
mkdir /usr/local/bind/var/run
mkdir /usr/local/bind/etc
/usr/bin/install -c isc-config.sh /usr/local/bind/bin

Finally Geo DNS installation completed.

 

How to configure Geo DNS,

Step 1 :

create a key file "/etc/rndc.key" and add below line

key "rndc-key" {
        algorithm       hmac-md5;
        secret          "LYjlqvJ,h9m6Gf9ZK1g3w6tQJ9j6H$9j,gMlpYPeGUm";
};

Step 2 :

We need to configure  through the named.conf file, so  create a file named.conf within /usr/local/bind/etc/ and add below config lines,
# cd /usr/local/bind/etc/

# vim  named.conf

include "/etc/rndc.key";
#listen-on-v6 { none; };
#controls {
#        inet 127.0.0.1 allow { localhost; } keys { "rndc-key"; };
#};
options {
        directory                "/var/named"; // the default
        pid-file                 "/var/run/named.pid";
        dump-file                "data/cache_dump.db";
        statistics-file          "data/named_stats.txt";
        allow-transfer {"none";};
};
logging {

    channel default_debug {
            file "data/named.run";
            severity dynamic;

    };
};
view "INDIA" {
                match-clients { country_IN; };
                recursion no;
                zone "thelinuxfaq.com" {
                type master;
                file "/var/named/ thelinuxfaq.com.india.db ";
                };
            };

view "US" {
                match-clients { country_US; };
                recursion no;
                zone " thelinuxfaq.com" {
                type master;
                file "/var/named/ thelinuxfaq.com.us.db";
                };
            };

view "other" {
                match-clients { any; };
                recursion no;
                zone " thelinuxfaq.com" {
                type master;
                file "/var/named/thelinuxfaq.com.db";
                };
            };

Step 3:

We need to create dns zone for specific domain name this example configure INDIA, US  and others, Assume that the ip addresses are,

India  - 192.168.1.1
US     – 192.168.2.2

 
# cd /var/named

# touch thelinuxfaq.com.india.db

# vim  /var/named/ thelinuxfaq.com.india.db

; Zone file for thelinuxfaq.com
$TTL 14400
thelinuxfaq.com.   86400   IN      SOA     ns1.nameserver.com.     config.thelinuxfaq.com.    (
  2014021700 ;Serial Number
  86400 ;refresh
  7200 ;retry
  3600000 ;expire
  86400   )
@                  14400     IN  NS ns1.nameserver.com.
@                  14400    IN  NS ns2.nameserver.com.

thelinuxfaq.com.           14400     IN      A       192.168.1.1
www                 14400     IN      CNAME   thelinuxfaq.com.
mail        14400   IN      A       192.168.1.1
thelinuxfaq.com.    14400   IN      MX      0       mail.thelinuxfaq.com.

Also configure for US,
#  touch thelinuxfaq.com.india.db

#  vim  /var/named/ thelinuxfaq.com.us.db

; Zone file for thelinuxfaq.com
$TTL 14400
thelinuxfaq.com.   86400   IN      SOA     ns1.nameserver.com.     config.thelinuxfaq.com.    (
  2014021700 ;Serial Number
  86400 ;refresh
  7200 ;retry
  3600000 ;expire
  86400   )
@                  14400     IN  NS ns1.nameserver.com.
@                  14400    IN  NS ns2.nameserver.com.

thelinuxfaq.com.           14400     IN      A       192.168.2.2
www                 14400     IN      CNAME   thelinuxfaq.com.
mail        14400   IN      A       192.168.2.2
thelinuxfaq.com.    14400   IN      MX      0       mail.thelinuxfaq.com.

Finally configure to others countries and both IP Address add in A Record 

After completed installation and configuration can start named service,

Step 4 : 

Start:
 
#  /usr/local/bind/sbin/named -s

Check the named service Status:
 
# pgrep -f named
3743
 
# ps aux | grep named

root      3743  0.0  1.3  16284 14240 ?        Ss   Oct28   0:08 /usr/local/bind/sbin/named -s
root     21908  0.0  0.0   4040   704 pts/0    R+   11:00   0:00 grep named


Do you want to stop dns service,
 
# pkill -9 named

Check the logs status:
 
# tail -f /var/log/messages 

Nov  5 11:00:55 namedserver named[21911]: client 192.168.0.1#38959: view US: received notify for zone 'thelinuxfaq.com'
Nov  5 11:00:55 namedserver named[21911]: client 192.168.0.1#38959: view US: received notify for zone 'thelinuxfaq.com'
Nov  5 11:00:55 namedserver named[21911]: client 192.168.0.1#38959: view US: received notify for zone 'thelinuxfaq.com'


I hope, you have understood all the steps, If you will face any issue just drop a comments.