Package: devns
PyDevNS is a pure Python DNS server for developers. You know how you need
a domain name to use for interacting with your app locally? Well, this is the
tool for you.Installationpip install devnsHey, not everything has to be hard.RationaleI know what you’re thinking:Dude, what? I just putlocal.devin my/etc/hostsfile.That’s all well and good, but what about when you needlocal.devand*.local.co?There’s like a million things out there that do this. I could usednsmasq, or one of the other 40 random Python “dev DNS” servers you
probably stole your implementation from.OK,dnsmasqkind of seems like overkill, but what about when you needlocal.devorreallycoolprogrammer.local.devto work from inside a
docker container?Well then I just makednsmasqresolve it to my real IP instead of127.0.0.1.So you edit the config and restartdnsmasqevery time you move from home,
to the coffee shop, to the office, wherever…That is kind of a pain, now that you mention it…Thought so.Default BehaviorIf you rundevnswith no arguments, the server will start, bind to0.0.0.0with a random port and try to discover a suitable IP address to use
for resolving any incoming DNS requests. It literally does not care what domain
you ask for, it always responds and always with the same IP, hopefully the IP
address of your actual network interface (e.g.192.168.1.52or whatever).
It tries to figure that out on its own, and I think it does a pretty good job
of it.But then how do I make DNS queries go to it, especially if it’s using a
random port every time it runs?Glad you asked. It’ll also try to write a file to/etc/resolver/dev, which
if your OS supports such things, would tell it to send any DNS queries for
domains ending it.devtodevns.But wouldn’t I need to…Run it withsudoto do that? Yeah probably, unless your system is insane
and just lets anybody write to/etcall willy nilly, in which case you have
bigger problems than gettinglocal.devto resolve to something sensible.Don’t I have to restart it every time my IP changes, just likednsmasq?No, there’s a configurable TTL associated with the addressdevnsuses in
its responses. By default, that’s 5 minutes. If a query comes in and the
address was last confirmed more than 5 minutes prior, it’ll try to rediscover
it. That should cover most cases of relocating from one spot to another.ExamplesRun the server with a random port and auto-configured resolver for.devresolving to a sensible, auto-detected IP address:sudo devnsRediscover the response address every 15 minutes instead of 5:sudo devns--ttl900Listen on port53535without writing any resolver files:devns--port53535--no-resolverWrite the resolver files to/usr/local/etc/resolverinstead of/etc/resolver:devns--resolver-dir/usr/local/etc/resolverRespond to all queries with172.24.3.1, and ignore the TTL:sudo devns--address172.24.3.1Listen on port53535, write config files for.devand.local.co:sudo devns--port53535--domainsdev local.coBind to a random port on127.0.0.1, and make a lot of noise:sudo devns--host127.0.0.1-vvvNotes/CaveatsIf you have entries in your/etc/hostsfor any domains you want to use withdevns, you’ll have to remove those. That’s all.UsageHere’s whatdevns--helpgets you:usage: devns [-h] [--version] [--verbose | --quiet]
             [--address ADDRESS | --ttl SECONDS] [--host HOST] [--port PORT]
             [--domains [DOMAIN [DOMAIN ...]]] [--resolver-dir DIRECTORY]
             [--no-resolver]

PyDevNS - A DNS server for developers.

optional arguments:
  -h, --help            show this help message and exit
  --version             show version and exit

Logging:
  --verbose, -v         verbose output
  --quiet, -q           quiet mode

Address:
  --address ADDRESS, -a ADDRESS
                        IP address to respond with
  --ttl SECONDS, -t SECONDS
                        how often to refresh the address

Network:
  --host HOST, -H HOST  address to listen on
  --port PORT, -p PORT  port to listen on

Resolver:
  --domains [DOMAIN [DOMAIN ...]], -d [DOMAIN [DOMAIN ...]]
                        domains to create resolver files for
  --resolver-dir DIRECTORY, -rd DIRECTORY
                        where to put resolver files
  --no-resolver, -nr    disable creating resolver files