Dynamic IP with dnsmasq

I am building a black box NAS for a friend, that is going to run a few docker containers with things like NextCloud and a few other services. By black box I mean that it should be setup in a way that no configuration is required, it’s just going to be plugged in to he’s router and work.

I want to setup dnsmasq with a wildcard domain that should redirect all requests to a reversed proxy which will then internally redirect requests to the correct service. But this means that the DNS need to point to itself, which is problematic seen as this machine is meant to obtain it’s IP via DHCP from the router.


My only current idea is to have a systemd service run when network is online and then update the conf file with the hosts current IP, but this seams so hacky. Is there no way to automate this with dnsmasq itself?

Asked By: Denny


(My answer reflects on a typical SOHO environment)

You can’t do this without at least minor configuration on the client side (If we include router as well), because you need direct the client computer’s request to the right ip address, where the services like NextCloud will be running.
As your friend’s DHCP service has already one or more DNS server entries that (by default) correspond to one of the ISP’s recursive DNS server, you would need to overrule this mechanism.
I can see that you want to implement this service with zero touch configuration required, but if you go for a local DNS server, then you have to at least set a fix ip address, that refers to in the DHCP settings on the router.

I suggest to do one of the following:

Run a local Recursive DNS server, add a zone mydomain.com, set the A records that points to the reverse proxy’s ip address and set this DNS server on the router. (In this case you will have full control over DNS settings with minuscule config on client side, But with more job to do and responsibility, because this have to also reply any web related DNS queries.

Modify the hosts file on the client computer where you can add entries with the destination ip address (reverse proxy’s ip) with each subdomain. (I would recommend this one in a small environment)
You can make this method more elegant by running a startup script that pulls the hosts file from FTP, so you can achieve a centralized solution, when it comes to updating the domain mapping.) This script must be be placed on each client devices, which can be cumbersome on mobile devices.

As you see, you need to consider responsiblity and client side configuration to find the right solution, but none of them involve 0% configuration on client side.

Answered By: david_beszeda
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.