Hi all, I’ve just finished making a simple DNS sinkhole in Elixir:
Basically how it works is:
- Application tree starts up main GenServer
- Genserver loads hosts files into an ETS table
- Genserver listens for incoming DNS requests on port 53, and opens another UDP socket for communicating with a nameserver
- If the domain is found in the ETS table respond to the client with an IP of 0.0.0.0, otherwise check the Cachex cache of previously forwarded responses.
- If no response is found in the cache, forward the request to the nameserver and log the client’s address & request in an ETS table, otherwise respond to the client instantly with the cached response.
- When the response from the nameserver comes back, check the ETS table to see which client requested that domain and send them the response. The response gets cached for future requests.
Any feedback/suggestions/PRs are more than welcome!