{"id":13587751,"url":"https://github.com/kvz/nsfailover","last_synced_at":"2025-04-15T01:42:41.213Z","repository":{"id":7688987,"uuid":"9052656","full_name":"kvz/nsfailover","owner":"kvz","description":"Let's Make DNS Outage Suck Less","archived":false,"fork":false,"pushed_at":"2021-10-06T11:51:16.000Z","size":20,"stargazers_count":103,"open_issues_count":2,"forks_count":17,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-13T08:47:18.010Z","etag":null,"topics":["bash","failover","high-availability","nameserver","reliability"],"latest_commit_sha":null,"homepage":"http://kvz.io/blog/2013/03/27/poormans-way-to-decent-dns-failover/","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kvz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-27T11:47:17.000Z","updated_at":"2024-11-05T11:22:34.000Z","dependencies_parsed_at":"2022-09-17T12:20:15.750Z","dependency_job_id":null,"html_url":"https://github.com/kvz/nsfailover","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kvz%2Fnsfailover","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kvz%2Fnsfailover/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kvz%2Fnsfailover/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kvz%2Fnsfailover/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kvz","download_url":"https://codeload.github.com/kvz/nsfailover/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248991511,"owners_count":21194893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","failover","high-availability","nameserver","reliability"],"created_at":"2024-08-01T15:06:20.790Z","updated_at":"2025-04-15T01:42:41.192Z","avatar_url":"https://github.com/kvz.png","language":"Shell","funding_links":["https://www.paypal.com/cgi-bin/webscr?cmd=_donations\u0026business=kevin%40vanzonneveld%2enet\u0026lc=NL\u0026item_name=Open%20source%20donation%20to%20Kevin%20van%20Zonneveld\u0026currency_code=USD\u0026bn=PP-DonationsBF%3abtn_donate_SM%2egif%3aNonHosted"],"categories":["Shell"],"sub_categories":[],"readme":"# nsfailover\n\n\u003c!-- badges/ --\u003e\n[![Build Status](https://secure.travis-ci.org/kvz/nsfailover.png?branch=master)](http://travis-ci.org/kvz/nsfailover \"Check this project's build status on TravisCI\")\n[![Gittip donate button](http://img.shields.io/gittip/kvz.png)](https://www.gittip.com/kvz/ \"Sponsor the development of nsfailover via Gittip\")\n[![Flattr donate button](http://img.shields.io/flattr/donate.png?color=yellow)](https://flattr.com/submit/auto?user_id=kvz\u0026url=https://github.com/kvz/nsfailover\u0026title=nsfailover\u0026language=\u0026tags=github\u0026category=software \"Sponsor the development of nsfailover via Flattr\")\n[![PayPayl donate button](http://img.shields.io/paypal/donate.png?color=yellow)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations\u0026business=kevin%40vanzonneveld%2enet\u0026lc=NL\u0026item_name=Open%20source%20donation%20to%20Kevin%20van%20Zonneveld\u0026currency_code=USD\u0026bn=PP-DonationsBF%3abtn_donate_SM%2egif%3aNonHosted \"Sponsor the development of nsfailover via Paypal\")\n[![BitCoin donate button](http://img.shields.io/bitcoin/donate.png?color=yellow)](https://coinbase.com/checkouts/19BtCjLCboRgTAXiaEvnvkdoRyjd843Dg2 \"Sponsor the development of nsfailover via BitCoin\")\n\u003c!-- /badges --\u003e\n\nTogether with EC2 Premium support I've established that:\n\n\u003e \"Unfortunately the Linux DNS resolver doesn't seem to have direct\nsupport for detecting and doing failovers for DNS servers so you \nmay need to write your own solution as you mentioned. \" - Amazon Web Services Jan 22, 2013 01:13 AM PST\n\nRead a [longer introduction on my blog](http://kvz.io/blog/2013/03/27/poormans-way-to-decent-dns-failover/)\nwhich was [featured on Hacker News](https://news.ycombinator.com/item?id=5450140). \n\nThis simple program makes DNS outages suck less.\n\n## nsfailover\n\nEvery minute (or whatever), `nsfailover.sh` checks to see if the primary configured nameserver\ncan resolve `google.com`.\nIf it cannot, it writes the secondary, or even tertary server to \nfunction as the primary server in `/etc/resolv.conf`.\n\nThis way, requests are stalled for max a minute, and then all following requests\nare fast, even if the primary stays down.\n\n## Install\n\n```bash\nsudo curl -q https://raw.github.com/kvz/nsfailover/master/nsfailover.sh -o /usr/bin/nsfailover.sh \u0026\u0026 sudo chmod +x $_\n```\n\n## Example\n\n```bash\ncrontab -e\n* * * * * NS_1=172.16.0.23 nsfailover.sh 2\u003e\u00261 |logger -t cron-nsfailover\n```\n\n## Config\n\n**nsfailover** is configured through environment variables.\nHere they are with their defaults:\n\n\n```bash\nLOG_LEVEL=\"6\" # 7 = debug, 0 = emergency\nNS_1=\"\" # Primary Nameserver (172.16.0.23 for Amazon EC2). You need to set this yourself\nNS_2=\"8.8.8.8\" # Secundary Nameserver: Google\nNS_3=\"4.2.2.2\" # Tertiary Nameserver: Level3\nNS_ATTEMPTS=\"1\" # http://linux.die.net/man/5/resolv.conf\nNS_ENABLE=\"no\" # Set to no to disable\nNS_FILE=\"/etc/resolv.conf\" # Where to write resolving conf\nNS_SEARCH=\"\" # Domain to search hosts in (compute-1.internal for Amazon EC2)\nNS_TESTDOMAIN=\"google.com\" # Use this to determine if NS is healthy\nNS_TIMEOUT=\"3\" # http://linux.die.net/man/5/resolv.conf\nNS_WRITEPROTECT=\"no\" # Use this to write-protect /etc/resolv.conf\n```\n\nYou can use environment variables in many ways: at the top of a script or crontab, \n`export` from another script, or pass them straight to the program:\n\n```bash\nNS_ENABLE=\"no\" ./nsfailover.sh # \u003c-- silly, but works :)\n```\n\n## Notes\n\n**nsfailover**\n\n- only rewrites `/etc/resolv.conf` if it has changes\n- makes a backup to e.g. `/etc/resolv.conf.bak-20130327114321`\n- needs to run as `root`\n\n## Tips\n\n- Prefix your cronjob with `timeout -s 9 50s` so there can never be an overlap. \nMore tips in my [Lock your Cronjobs](http://kvz.io/blog/2012/12/31/lock-your-cronjobs/) article.\n\n## Versioning\n\nThis project implements the Semantic Versioning guidelines.\n\nReleases will be numbered with the following format:\n\n`\u003cmajor\u003e.\u003cminor\u003e.\u003cpatch\u003e`\n\nAnd constructed with the following guidelines:\n\n* Breaking backward compatibility bumps the major (and resets the minor and patch)\n* New additions without breaking backward compatibility bumps the minor (and resets the patch)\n* Bug fixes and misc changes bumps the patch\n\n\nFor more information on SemVer, please visit [http://semver.org](http://semver.org).\n\n## License\n\nCopyright (c) 2013 Kevin van Zonneveld, [http://kvz.io](http://kvz.io)  \nLicensed under MIT: [http://kvz.io/licenses/LICENSE-MIT](http://kvz.io/licenses/LICENSE-MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkvz%2Fnsfailover","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkvz%2Fnsfailover","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkvz%2Fnsfailover/lists"}