NOTE on DNS A Names with Round Robin (multiple A names)
################################################

If you have DNS items like so: Multiple A names point to different IPs. This will give you round robin IPs per connection (not high availability). Its a way to load balance the requests. If one of these servers crashes, that request still goes out, it will just fail. So with 4 Ips tied to the A name infotinks.com, if 1 of the IPs fail, then 3 out 4 requests are good, but 1 request will fail.

SIDENOTE ABOUT ANAME AND @ HOST MEANING NAKED DOMAIN: since im talking about “infotinks.com” and not “something.infotinks.com”, thus its not prefixed with www (or any subdomain, the “something.” part). The A name has 3 items to configure: the host, the target which is the IP it points to – where as Cname points to an Aname or a full on Domain Name, and the TTL (Time to live in the DNS cache). Now The IP and the TTL make sense. The Host though in an Aname has to be either the @ symbol (which means the naked domain – and this is what I had to pick so that I didnt have to select the “something.” part), or it has to be a subdomain of choosing (for example the host: “ram”, points to IP 192.249.61.185, thus “www.infotinks.com” points to that 192.249.61.185). So how do I just get an Aname to point at a naked domain, without the subdomain part? So that just “infotinks.com” is told to go to some IP. Well I just answered it in the Parenthesis, you use the @ symbol. So you would configure, Host: “@”, points to IP 216.239.32.21.

From a client doing an nslookup or a host command you can see this behaviour (the roundrobin configuration):

# host infotinks.com
infotinks.com has address 216.239.32.21
infotinks.com has address 216.239.34.21
infotinks.com has address 216.239.36.21
infotinks.com has address 216.239.38.21
infotinks.com mail is handled by 10 ASPMX3.GOOGLEMAIL.com.
infotinks.com mail is handled by 1 ASPMX.L.GOOGLE.com.
infotinks.com mail is handled by 5 ALT1.ASPMX.L.GOOGLE.com.
infotinks.com mail is handled by 5 ALT2.ASPMX.L.GOOGLE.com.
infotinks.com mail is handled by 10 ASPMX2.GOOGLEMAIL.com.
# nslookup infotinks.com
Server: 10.11.12.55
Address: 10.11.12.55#53

Non-authoritative answer:
Name: infotinks.com
Address: 216.239.34.21
Name: infotinks.com
Address: 216.239.36.21
Name: infotinks.com
Address: 216.239.38.21
Name: infotinks.com
Address: 216.239.32.21
# nslookup
> set q=A
> infotinks.com
Server: 10.11.12.55
Address: 10.11.12.55#53
Non-authoritative answer:
Name: infotinks.com
Address: 216.239.36.21
Name: infotinks.com
Address: 216.239.38.21
Name: infotinks.com
Address: 216.239.32.21
Name: infotinks.com
Address: 216.239.34.21

To test the round robin property do this:

FROM WINDOWS:
=============

Step1) ping infotinks.com
Step2) And cancel it
Step3) Repeat step 1 thru 2

You will see that it picks a different IP each time.

FROM LINUX:
===========

Repeat the following command:

# ping infotinks.com -c 1

Notice that its picking different IPs

Or you can run this mini script (find the IP address in the ping output, it spits it out twice, so just select the top one with head):

# ping infotinks.com -c 1 | grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" | head -n 1

Or Generic:

# HOST2PING="google.com"; ping $HOST2PING -c 1 | grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" | head -n 1

SIDENOTE: interesting way to select out the IPs in a piece of text or command output:

text:

# cat somefile.txt | grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"

or:

# grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" somefile.txt

command output:

# command | | grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"

Now you can repeat it like so:

1 ping per 10th of second:

# while true; do ping infotinks.com -c 1 | grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" | head -n 1; sleep 0.1; done | tee pingys1

1 ping as fast as it can (just remove the sleep)

# while true; do ping infotinks.com -c 1 | grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" | head -n 1; done | tee pingys1

You can now sort this output (sort for the purpose of uniq squishing the similar stuff together, and giving you a count with -c):

# cat pingys1 | sort | uniq -c

OUTPUT:

# cat pingys | sort | uniq -c
37 216.239.32.21
36 216.239.34.21
35 216.239.36.21
37 216.239.38.21
...continues to alternate...

So we see that every IP got used about 35 to 37 times equally round robin balanced!

NOTE: if one or more of those IPs would fail, then the Ping would of failed for that IP

SCRIPT:

# HOST2PING=google.com; while true; do ping $HOST2PING -c 1 | grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" | head -n 1; sleep 0.1; done

SCRIPT AND STATS:

First do this:

# HOST2PING=google.com; while true; do ping $HOST2PING -c 1 | grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" | head -n 1; sleep 0.1; done

Then do this:

# cat pingys1 | sort | uniq -c

IF WINDOWS OR LINUX ARE REPORTING THE SAME IP EVERYTIME?==================================================

This could be due to your DNS server caching the IP address. So it saved the entry for example to infotinks.com as 216.239.32.21 (For 1 Hour). So maybe next hour it will be different.
You could counter this by using the 8.8.8.8 or 4.2.2.2 (or any other DNS server). If that doesnt work, then maybe the problem is in your PC (The client) storing the value in cache. You can always flush the DNS cache.

How to flush DNS cache in windows:

# ipconfig /flushdns

How to flush DNS cache in Linux:

You will need to research whats holding the DNS in your system.

# sudo /etc/init.d/nscd restart
# sudo /etc/init.d/dnsmasq restart
# service dnsmasq restart

 

Leave a Reply

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