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:
- 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 todnsmasq
but this seems cumbersome. - 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 restartdnsmasq
. In context of the previous question, it would be preferable ifdnsmasq
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?