Usually we say that a domain name is uniquely corresponded to an IP address, we enter a domain name in the browser, then the request is passed to the DNS server, the DNS server resolves this corresponding IP and returns it to the browser. However, in some cases, a domain name can correspond to multiple IP addresses, and this is called DNS polling. Through DNS polling, we can achieve some goals that are difficult to achieve under normal circumstances. First, let’s introduce the basic concept of DNS polling.
We know that when setting up a domain name resolution, generally a domain name corresponds to a CNAME or A record to only one IP. This way, if we access the domain name, it will be converted to this IP for access. However, if we set up the same domain name with A records to two or more different IPs in the DNS zone file, what happens when we access it? In fact, the DNS server resolves it as usual. This creates a paradox - which IP we are actually accessing. this has to do with geographic location, access speed, and many other factors, but using this IP selection mechanism, we can accomplish many meaningful things. The specific resolution process works like this: first, the client sends a request to the recursive server (local broadband carrier server), which sends a request to the resolution server; then, the resolution server returns all the polling host server IPs set by the domain name to the recursive server, which returns those IPs to the client; finally, the client’s browser will randomly make a access. So, using this access to different IPs from the same domain name, we can do many things.
-
The first is to achieve a balanced load with guaranteed access in case of failure. For large websites, it is almost certain that balanced load will be used. If DNS polling technology is used to resolve a domain name to the respective IP addresses of multiple servers and share the traffic using random browser access, the pressure on each server is reduced and a balanced load is achieved. Guaranteed access in case of failure is another important application. As we can see from the previous brief description of the principle, the DNS server will return all IPs to the browser during polling, and the browser’s own mechanism will allow it to continue connecting to the next IP in case of connection errors until all IPs are unreachable or until the connection is successful. Thus, as long as both servers are not down at the same time, we can have almost 100% of the site online. Similarly, when changing server addresses, using another server to do DNS polling for the transition is a good way to go.
-
The second important role is CDN acceleration. dns polling is the basis of CDN, through the different resolution of different access lines to achieve the fastest access speed, which is a very useful function, of course, provided that you have many servers. dnspod provides a similar function, you can try it yourself.
-
The third important role is to realize the different access contents of internal and external networks with the accelerated access of contents. All wired and wireless networks in our school form a large-scale LAN, and all computers in the LAN are interoperable. I previously had a site on a foreign VPS, and the speed of on-campus access was still very unsatisfactory. Recently, I wanted to increase the speed of on-campus access and provide a query function for intranet visitors (I didn’t want to let off-campus visitors use it), so I built a server on my own computer, and all the corners of the campus logged in at a fast speed and were able to use the query function. At this point, then do DNS polling, respectively, to resolve to the off-campus server address and the campus local IP address within the LAN, so that the on-campus client access is a high-speed server on my computer; and off-campus access can not connect to the campus LAN IP, it will poll access to external servers, and will not access the content that can not be accessed, the effect is very good.
There are not many domestic resolvers that support DNS polling, DNSPOD currently supports DNS polling configuration.
DNS load balancing principle
DNS load balancing is implemented through cyclic multiplexing, which is used to cycle through the host resource records included in query responses if multiple address resource records for a host name are found. By default, the DNS server’s service uses recursive multiplexing to sort the resource records that are returned in the hostname answer that resolves to multiple mappings. This feature provides a very easy way to load balance multiple host computers for client use of web servers and other frequent queries.
For recurring multiplexing to work properly, multiple host resource records for the queried name must first be registered in the zone and DNS server recurring multiplexing must be enabled. If the DNS server disables cyclic multiplexing, the order of responses to these queries is based on the static ordering of the resource records in the answer list as they are stored in the zone.
Let’s say you add three records, 1, 2, and 3
- The first user request, the record returns 1, 2, 3
- The second user request, the record returns 2, 3, 1
- The third user request, the record returns 3, 1, 2
- The fourth user request, the record returns 1, 2, 3
All records are returned evenly to each requesting user, but sometimes users may exit your site as soon as they open it (for example, by closing their browser), and some users may keep browsing your site. Because DNS cannot know which other users are still accessing which of your servers, it will cause some servers to be accessed by more users and some servers to be accessed by fewer users (because this server has more users with short access times). Eventually there will be uneven access to users.
The following example is: there are 3 Unicom servers and 3 telecom servers, to achieve the effect of “Unicom user traffic is distributed to 3 Unicom servers and other user traffic is distributed to telecom servers”.
DNS is generally used more often in smaller sites because of its lower cost. But large websites will also generally use it in combination with other load balancing methods. The IP address provided by DNS polling method is often a cluster address in large websites, which may be a balanced switch or a balanced server. For small sites, there is no problem to hook up multiple servers. For example.
DNS load balancing pros and cons
Advantages of DNS polling.
- Zero cost: it’s just binding a few A records on the DNS servers, and domain name registrars generally provide resolution services for free.
- Simple deployment: It’s all about device augmentation in the network topology and then adding records to the DNS servers.
Disadvantages of DNS polling.
- Health check, if a server is down, the DNS server is not aware of it and will still assign access to this server. It takes at least 3-4 hours, if not more, for all changes to DNS records to take effect.
- Uneven distribution, if several web servers are configured differently from each other, the pressure they can withstand is different, but the access assigned by DNS resolution is evenly distributed. In fact, DNS also has an allocation algorithm, which can be based on the current connection less allocation, can set Rate weight allocation, etc., just that the vast majority of DNS servers currently do not support.
- Session hold, in the case of sites that require authentication, without modifying the software architecture, this point is rather fatal, because DNS resolution cannot persistently assign access from authenticated users to the same server. Although there is a certain local DNS cache, but it is difficult to ensure that the local DNS does not expire during the user’s visit, and re-query the server and point to the new server, then the original server to save the user information can not be brought to the new server, and may require being re-authentication identity, switching back and forth for a long time each server has different information about the user is saved, the server resources are also a waste It is also a waste of server resources.
DNS Intelligent Resolution
Traditional DNS resolution does not determine the source of the visitor and will randomly select one of the IP addresses to return to the visitor. Intelligent DNS resolution, on the other hand, determines the source of visitors and intelligently returns different IP addresses for different visitors, enabling visitors to obtain user-specified IP addresses when accessing the website, which can reduce resolution latency and improve the effectiveness of website access speed.
Traditional DNS resolution example
For example, the domain name www.example.com has three servers, Unicom IP, Mobile IP, and Telecom IP, and the DNS resolution configuration is as follows.
- Point the domain name to the Unicom IP address (0.2.0)
- Point the domain name to the mobile IP address (0.2.1)
- Point the domain name to the Telecom IP address (0.2.2)
Achievable resolution effect: Traditional DNS resolution does not determine the source of the visitor, it will return all three addresses 192.0.2.0, 192.0.2.1, 192.0.2.2 to the visitor’s LocalDNS, and the visitor’s LocalDNS will return one of the IP addresses to the visitor by random or preferential selection, traditional DNS resolution has the potential to cause visitors to access across networks.
Example of intelligent DNS resolution
For example, the domain name www.example.com has three servers, Unicom IP, Mobile IP, and Telecom IP, and the DNS resolution configuration is as follows.
- Resolving line configuration default line pointing to Unicom IP address (0.2.0)
- Resolving line configuration mobile line pointing to mobile IP address (0.2.1)
- Resolution line configuration telecom line pointing to telecom IP address (0.2.2)
The resolution effect can be achieved: cloud resolution will determine the source of visitors, for visitors from mobile operators cloud resolution returns 192.0.2.1 resolution address, for visitors from telecom operators cloud resolution returns 192.0.2.2 resolution address, other sources of visitors cloud resolution returns 192.0.2.0 resolution address.
Implementation Principle
Cloud resolution is used to determine the source of visitors by identifying the exit IP of LOCALDNS. If client-side LOCALDNS supports EDNS (Google submitted a DNS extension protocol that allows DNS resolver to pass user’s ip address to authoritative DNS server.), so when getting the visitor’s source IP, priority is given to getting the IP carried in the edns-client-subnet extension If the IP exists in the edns-client-subnet extension, Cloud DNS resolver will use that IP to determine the visitor’s geographic location; if not, it will use the LocalDNS exit IP to determine the visitor’s geographic location.
-
If client LocalDNS does not support EDNS: LocalDNS will iterate the request to Cloud Resolution DNS, and Cloud Resolution DNS will determine the visitor’s address location based on the visitor’s LocalDNS exit IP to achieve intelligent resolution.
-
If the client LocalDNS disguisedly supports EDNS: the user initiates a DNS request and recurses to LocalDNS, then LocalDNS sends this request to the secondary node, which initiates a request to Cloud Resolution DNS through the secondary node, at which point Cloud Resolution DNS returns specific subdivision line resolution results based on the geographical location of the LocalDNS secondary node.