4

I've set up a machine running dnsmasq, essentially serving its /etc/hosts file. However, there are specific entries which I want in that machine's /etc/hosts, but I don't want served. How can I make dnsmasq not serve them?

einpoklum
  • 1,622
  • 3
  • 19
  • 30

2 Answers2

3

If you don't want your system to use those entries in your host file, why can't you simply remove them?

Do you have other enteries in your host file that you do need to be served? You could just have DNSMasq skip the system-wide host file --no-hosts, and you can point DNSMasq at an alternate hosts file that has the entries you want --addn-hosts.

-h, --no-hosts
  Don't read the hostnames in /etc/hosts.

-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.
Zoredache
  • 128,755
  • 40
  • 271
  • 413
  • I guess I can do that, although it simply means duplicating all-but-one-line of `/etc/hosts`... hmm. – einpoklum Dec 16 '13 at 23:40
  • Simple. Say I use [StevenBlack/hosts](https://github.com/StevenBlack/hosts), and I have my `dnsmasq` machine fetch it daily. It blocks the ad and tracking sites, but I need *some* of them for my work. So I would have to somehow override the hosts entry without touching the actual hosts file – because my changes will be overwritten – mehov Nov 03 '21 at 20:36
2

I dont know whether dnsmasq supports this or not, but from the description of what you are trying to achieve, it sounds like setting up bind would be a more elegant solution. That way, you can keep your hosts file and DNS forwarding / resolution completely separate.

GeoSword
  • 1,647
  • 12
  • 16
  • Setting up and configuring bind, as well as a separate DHCP server, and having the DHCP server and bind communicate, and synchronizing things with `/etc/hosts`, does not sound like a better solution. Is it more elegant? I dunno. – einpoklum Dec 16 '13 at 17:05
  • I'm treading carefully since I dont know the full extent of dnsmasq's functionality, and I don't know if you are using dnsmasq over bind for some reason that you haven't stated. However having DNS and DHCP talk to each other is something that's well documented and commonly used. So its "Better" in the sense that lots of other people have similar configurations, and therefore is easier to get answers for problems that arise. – GeoSword Dec 16 '13 at 17:30