David
David

Reputation: 6162

Is there a way to use DNSMasq and BIND on the same computer?

I like the idea of running my own nameserver (BIND) but if I do that, I can't get the benefit of blocking nasty websites by putting them in /etc/hosts

DNSMasq is able to refer to /etc/hosts but rather than specifying an "upstream" dnsserver, I'd like it to be able to use BIND on the same machine. However, they both need to use the same port.

Is this possible? I couldn't find anything about this in regular searching.

I suppose an alternative would be to run another Linux instance in a VM and run DNSMasq there (say) but I'd like to not have to do this.

Upvotes: 2

Views: 2730

Answers (2)

sjohn
sjohn

Reputation: 1

I had the same problem because I really like dnsmasq handling of /etc/hosts and appending a local domain but don't want to use a specific upstream nameserver which I would guess at least google would count who gets the most hits and I'd like to cache replies. I had good results setting up caching bind with root nameservers on one machine and then pointing my other machines with dnsmasq there. At home I only have one machine so got the idea to add an alias and bind bind9 to that.

So the tricky part is that dnsmasq by default binds to all interfaces when it starts so to fix this.

  1. Add an alias in /etc/network/interfaces

auto enp2s0

allow-hotplug enp2s0

iface enp2s0 inet static

address 192.168.12.7

network 192.168.12.0

netmask 255.255.255.0

broadcast 192.168.12.255

gateway 192.168.12.1

dns-nameservers 1.1.1.1,9.9.9.9

auto enp2s0:0

allow-hotplug enp2s0:0

iface enp2s0:0 inet static

address 192.168.12.53/24

  1. Configure /etc/bind/named.conf.options

listen-on { 192.168.12.53; };

  1. Configure DNSMasq file /etc/dnsmasq.conf

except-interface=enp2s0:0

bind-interfaces

Just change interface names and IP's where appropriate.

Upvotes: 0

Deleted User
Deleted User

Reputation: 2541

you could assign multiple ip addresses to the same interface, either with

ip addr add <address>/32 dev eth0

or using

ifconfig eth0:1 <address>

then bind one server to one address, the other server to the second address. Which server is queried depends now on the ip address your queries are sent to.

The examples assume that your eth interface is eth0.

Upvotes: 2

Related Questions