Is there a way in Linux to make it so when the DNS client looks up information on a DNS name it would return an IP number, even if it does not exist?

I am creating a testing environment, and I want to be able to resolve domain names that do not exist.

I know I can do this in the host file however I do not want to edit this file for every domain name I try to lookup.

Further clarification on my question is this

Scenario 1: I ping google.com dns lookup google.com and get the real IP number.

Scenario 2: I ping nonexstiantdoamin.com it would return local IP number instead of lookup failing.

  • In essence you are asking if the Linux resolver can act as though it is broken and/or hacked. Short answer, no. Depending on what you are trying to accomplish and how you are using the resolver (dig, nslookup, C Library like resolver(3)) you can write a wrapper around the lookup and have it supply IPs when the real solution fails. Still, why would you want to have DNS behave as if broken?
    – Deathgrip
    Aug 7, 2017 at 15:24
  • 1
    You could use BIND+the RPZ functionality. unix.stackexchange.com/questions/253841/… Aug 7, 2017 at 17:40
  • Basically i am trying to make it so if a user on our network tries to go to invalid domain it will show a custom error page. Aug 8, 2017 at 15:34

1 Answer 1


Take a look at dnsmasq. It has an -H option that allows you to add hosts. From its man page:

-H, --addn-hosts=<file>
              Additional hosts file.  Read  the  specified  file  as  well  as
              /etc/hosts.  If  -h is given, read only the specified file. This
              option may be repeated for more than one additional hosts  file.
              If  a  directory  is given, then read all the files contained in
              that directory.

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.