As pointed out, DNS isn’t your huckaberry here–its too slow to properly update, so that in most cases users would end up in the wrong place.
For times when the server is up and recieving requests, but the app is down, you can use a special file called app_offline.htm to effectively intercept all requests with a friendly error message.
For times when you are taking the box down, the best bet is to toss up another box at the same IP address with some sort of catchall “we are down” site. That said, the risks of doing this generally outweigh the benefits.
To handle the data center being down you are looking at alot of engineering and hosting costs. You really need a second data center, some sort of failover, and some sort of data mirroring. Or you can just pick a really high quality hosting provider who generally doesn’t go down. There are reasons you don’t host things in your basement . . . .
And the other way around. If your server is down, and I don’t have anything for your domain in my DNS cache, and I get directed to the second server, it would take some time for my DNS cache that points to the second server to clear out, so that when the first server goes back online again I’ll still see the maintanance page for a while.
Kind of, with DNS. Run the primary name server for the domain on the first server, the secondary name server for the domain on the second server. When the primary server goes down, so does its DNS server, so requests to resolve your domain to an IP will hit the secondary server, which can reply with the IP of that secondary server. Anyone who has the DNS response of the primary name server cached from before it went down will not be able to access the site for a while, still.
is there any other way of getting around this?
what if I had a maintenance page running on another site´not hosted in the same data centre with the liver server and this had another ip address. in case the live server did not respond … then the traffic would be directed to the maintenance page. But how would the traffic be directed back to the live server again?
The only solution that would allow that would be two servers with a failover configuration from one to the other.
Wit that configuration the maintenance page would the unnecessary since people would be able to access the site on the one server while you are doing maintenance on the other.
If the data center is down or you’re rebooting, your server cannot serve a maintenance page or anything else.
You can move the DNS server somewhere else, and use that to point the domain to the IP address of a second server that shows a maintenance page, but:
It will take time for DNS caches to flush the cached IP, so for potentially hours or days, people will still hit the offline server instead of seeing the new maintenance page
If the data center where this DNS server is down, your site is completely down again