Setup dnsmasq to resolve host name to local machine's IP

1

I'm running dnsmasq as a simple DNS for resolving myserver.local.example.com to the local IP address of the server where dnsmasq is running on. Everything else is forwarded to public DNS.

Assuming the server's IP address is 192.168.1.12 then my command looks like this:

dnsmasq --no-hosts --no-resolv --localise-queries \
  --server=1.1.1.1 --server=8.8.8.8 --server=8.8.4.4 \
  --host-record=myserver,myserver.local.example.com,192.168.1.12

In case multiple network interfaces are attached I set multiple --host-record entries, one for each IP address:

dnsmasq --no-hosts --no-resolv --localise-queries \
  --server=1.1.1.1 --server=8.8.8.8 --server=8.8.4.4 \
  --host-record=myserver,myserver.local.example.com,192.168.1.12 \
  --host-record=myserver,myserver.local.example.com,192.168.99.57

This works as expected. The hostname is resolved to the IP address I configure. However, I have two questions on how to improve this:

  1. Is there a way of configuring this without knowing the IP address of the server? I'm using a bash script that parses the IP address from ifconfig output and passes it to dnsmasq but this seems cumbersome.
  2. If the IP address of the server changes for whatever reason, e.g. the network gets connected after dnsmasq is already started, I have to manually restart dnsmasq. In context of the previous question, it would be preferable if dnsmasq could automatically detect that and update without manual restart.

Any thoughts or suggestions? Or maybe there's even an alternative to dnsmasq that's more suitable for me?

André

Posted 2019-05-01T15:03:33.947

Reputation: 113

Answers

1

You can use

--interface-name=<name>,<interface>

e.g

--interface-name=myserver.local.example.com,enp2s0

See http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html fore more details

With the default configuration, Dnsmasq is able to see interface link and ip address events, and should not need to be restarted to publish "interface" DNS names when interfaces go down and up.

Strangelovian

Posted 2019-05-01T15:03:33.947

Reputation: 371