Dnsmasq is a lightweight, easy-to-configure DNS forwarder and DHCP server. It's often used in small networks or for home routers. However, users sometimes encounter issues where Dnsmasq fails to resolve hosts that have been assigned static IP addresses. Let's explore this problem, analyze it, and provide useful solutions.
The Original Problem
The problem statement might have been confusing, but it's clear now: "Dnsmasq is not resolving hosts that have static IPs."
Original Code Example
If you have a configuration file for Dnsmasq located at /etc/dnsmasq.conf
, you might have static IP assignments specified like this:
# Static DHCP lease assignments
dhcp-host=00:11:22:33:44:55,192.168.1.100,host1
dhcp-host=66:77:88:99:AA:BB,192.168.1.101,host2
In this example, host1
and host2
are supposed to resolve to the static IP addresses 192.168.1.100 and 192.168.1.101, respectively.
Analyzing the Issue
When Dnsmasq doesn't resolve these static IPs, it can be due to several reasons:
- Configuration Errors: There might be typos or incorrect formatting in the
dnsmasq.conf
file. - Restarting Dnsmasq: After making changes, if Dnsmasq has not been restarted, the changes will not take effect.
- DNS Caching: Your system or network might be caching DNS records, preventing immediate resolution changes.
- Firewall Rules: Sometimes firewall settings can block DNS requests, leading to resolution issues.
Troubleshooting Steps
Here’s how you can troubleshoot the problem:
-
Check the Configuration: Ensure that the Dnsmasq configuration file is correctly formatted. For instance, verify that you have not missed any commas or colons.
-
Restart Dnsmasq: Use the following command to restart Dnsmasq and ensure it picks up your configuration changes:
sudo systemctl restart dnsmasq
-
Flush DNS Cache: On the client machine, flush the DNS cache to ensure it's querying Dnsmasq for the latest records:
sudo systemd-resolve --flush-caches # For systems using systemd-resolved
-
Check Firewall Settings: Make sure that your firewall isn’t blocking DNS requests. Use commands like:
sudo ufw status
This will show you the status of your firewall and whether DNS traffic is allowed.
-
Testing: You can test if Dnsmasq is resolving the static IP addresses with tools such as
dig
ornslookup
:dig @localhost host1 nslookup host2
Practical Example
Let’s say you have set up Dnsmasq on your home network. You’ve assigned a static IP to a Raspberry Pi for a web server:
dhcp-host=00:11:22:33:44:55,192.168.1.110,raspberrypi
After applying this, if you cannot resolve raspberrypi
to 192.168.1.110
, follow the troubleshooting steps outlined above. Flushing the DNS cache and restarting Dnsmasq often resolves such issues.
Conclusion
While Dnsmasq is an excellent tool for managing DNS and DHCP on small networks, it can sometimes face challenges in resolving hosts with static IPs. By carefully checking your configuration, restarting the service, flushing the DNS cache, and verifying firewall rules, you can resolve most issues that arise.
Additional Resources
By following the guidance in this article, you can ensure your Dnsmasq setup runs smoothly, allowing you to resolve hostnames correctly in your network.