I would like to have a local DNS server which I can configure in some way. Maybe a php script, which gets the requested hostname and returns the IP. I don't want to have an IP/Hostname list, but I want to generate the IPs in code! Do you know how to do this?
I think that host
file should be your option.
Client and other DNS server caches DNS queries anyway therefore there is no reason why to generate these on the fly. You have to refresh host file periodically.
I'm not quite sure what it is that you want, but many routers have a built in DNS capability which is usually very easy to use.
Simple DNS Plus has several APIs (plain HTTP, .NET, COM, command line) that are easy to use.
For example, you could add an IP-address (A-record) by seding it a simple HTTP request like "http://127.0.0.1:8053/updatehost?host=test.example.com&data=1.2.3.4" - which you could issue from your PHP script with the standard cURL library.
Maybe MyDNS is something to look into. It gets the IPs from a database (MySQL or PostgreSQL).
I don't know if it can be hooked directly to another source. But maybe it is wiser to decouple that and let the database be updated from the internet-source and let the DNS system query the database.