0

I know that you can edit /etc/hosts to make certain hostnames resolve to specific IPs, but is there a way I can force my machine to use a certain nameserver for a domain?

For instance, if I own mysite.com and running dig mysite.com ns shows CloudFlare as the nameservers, I'd like to override that locally so it uses AWS Route 53.

The goal is to make sure moving my whole domain from CloudFlare to AWS will work ok, before I actually change the nameservers.

1

Run your own local lightweight DNS server like MaraDNS or Dnsmasq.

Whenever any software on your computer tries to reach out to internet with DNS name, it resolves to a corresponding IP addresses by querying a DNS server. This setup is usually done via /etc/resolv.conf. But Unix systems before querying on network try to look it up locally on /etc/hosts. If your destination IP address doesn't change, it is best you just put an entry in /etc/hosts.

If you don't want to do that, other way is to run a DNS server yourself. When you run a DNS server locally, you have to mention an upstream server. An upstream DNS server is basically a go-to DNS server (typically your ISP's or Google DNS or OpenDNS) which your local DNS can query.

If you are running Ubuntu/Debian follow this: dnsmasq

Once you have your Dnsmasq up and running, you should configure your dnsmasq to query your choice of NS for specific domain/s with server=/example.com/208.67.222.222. example.com is the domain and the IP address is the Nameserver you want Dnsmasq to query.

Don't forget to update the resolv.conf or other tools which controls resolv.conf so that your computer queries locally.

That way for all requests, your computer queries your ISP provided DNS server and for a specific domain it queries IP address of your choice. HTH.

Ref: Dnsmasq Man page

  • 1
    I know zilch about DNS servers, you'll have to elaborate a bit, please. – ffxsam Jan 16 at 1:18
  • @ffxsam This is basically setting up your local computer to be a DNS server. Then its DNS server software is configured to be a DNS forwarder. For your mysite.com domain it is set up to forward DNS queries to the specified nameservers, in this case AWS. For other domains it will forward the DNS queries to your regular DNS servers, ie your ISP DNS servers. In words you may be more familiar with you are setting up a stub zone or a forward zone on your local PC's DNS server. – BeowulfNode42 Jan 16 at 2:26
  • Don’t forget to mention the resolv.conf or the DNS settings on any device have to be updated to use the newly installed DNS server. – Appleoddity Jan 16 at 3:49
  • @Appleoddity right.. will update the answer to reflect your point – Ram Jan 16 at 4:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.