I would like to set up a basic DNS forwarder that does two things.
First, it simply forwards DNS queries upstream. Second, if the upstream DNS servers can not resolve a hostname then this DNS forwarder should return a garbage IP address like 127.255.255.255
or 100::
.
The result of this could be that all hostnames should always resolve but hostnames that normally wouldn't resolve are resolved to a garbage IP address.
For example, if I had two hostnames: resolvable
which the upstream DNS server knows is at 1.2.3.4
; and notresolvable
which the upstream DNS server does not know the IP address for. If I then query the DNS forwarded with these two hostnames, resolvable
would return 1.2.3.4
and notresolvable
would return 127.255.255.255
(rather than not found).
Hostname: resolvable notresolvable
| / \ | / \
| | | |_________
\ / | \ / |
DNS Forwarder: forward found forward not __\ use garbage ip
upstream ip=1.2.3.4 upstream found / ip=127.255.255.255
| / \ | / \
| | | |
\ / | \ / |
Upstream DNS found ip=1.2.3.4 not found
server:
The closest I have got to making this system happen is with dnsmasq. dnsmasq by default sends dns queries upstream so it works for my first requirement.
I can also add address=/#/127.255.255.255
to the end of /etc/dnsmasq.conf
which then resolves all hostnames to the garbage IP address. However, this also resolves hostnames that the upstream DNS server can resolve which is not what I want.
After reading the dnsmasq man page I found this in the address section:
Queries in the domains are never forwarded
which suggests to me that what I need is not possible with dnsmasq.
So my question is, what program is best suited to make this setup possible and how would I go about it?
Edit: Context
I have an application which is running inside a docker container which uses docker networking to connect with other docker containers using hostnames.
The problem I am trying to solve is said application won't start or continue running if a hostname doesn't resolve (which occurs if the container it is referencing is not running).
So the dns server I reference above would be a server which runs along side the application inside the docker container.
I have also removed reference to resolv.conf
as it doesn't seem necessary to get this to work. The dns server just has to forward on to docker's internal dns server which just happens to be listed in resolv.conf
.