Reputation: 17903
I have an odd situation (TLS certificate validation via axTLS) where I need to access a local development server via a DNS-resolved hostname, not an IP address.
Is there a DNS service that dynamically resolves the A record for a subdomain like "192-168-0-42.example.com" to whatever IP address is represented?
I am not trying to do a reverse lookup of an IP address to its hostname. In my case, my local DNS infrastructure does not have a hostname for the IP address. I'm needing a public DNS entry for a particular IP address, and rather than setting one up myself and waiting for it to propagate, perhaps someone has set a dynamic resolver already?
Upvotes: 1
Views: 2629
Reputation: 4391
You can achieve this with dnsmasq using the --synth-domain
parameter.
After installing dnsmasq with your favorite package manager, run it in the foreground (-k
) to test (note: if you package manager starts up dnsmasq for you, you may have to stop it in order to start up a second instance):
$ sudo dnsmasq -k --synth-domain=ip,0.0.0.0,255.255.255.255,internal-
This will synthesize A records for all hostnames on the .ip TLD which have the form the form internal-10-11-12-13.ip
(you are free to use a narrower range of IPs or an address and net mask; see the man page for detail). The trailing internal-
is optional, you may omit it if you want to use addresses of the form 10-11-12-13.ip
.
In another shell, test that this is working as expected:
$ dig @localhost internal-10-11-12-13.ip
; <<>> DiG 9.8.3-P1 <<>> @localhost internal-10-11-12-13.ip
; (3 servers found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10038
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;internal-10-11-12-13.ip. IN A
;; ANSWER SECTION:
internal-10-11-12-13.ip. 0 IN A 10.11.12.13
This tells dig to use the nameserver running on localhost, which should be the dnsmasq instance we just started in the first section.
When you are satisfied with the format of the synthesized records, you can configure your OS to use dnsmasq as its resolver for the .ip TLD. Assuming you have a fairly recent Linux or OS X as the host distribution, this can be achieved simply. Create a file (as root) /etc/resolver/ip
with the contents:
nameserver 127.0.0.1
(You may have to tickle the OS to get it to recognize this change; on Yosemite I had to touch /etc/resolv.conf
before this started working).
Finally, you may wish to make this change permanent in dnsmasq. Consult your package manager for the location of dnsmasq's configuration file and how to make it start on boot. On Yosemite, and installed with homebrew, it is found in /usr/local/etc/dnsmasq.conf
. You can include the following in the configuration file:
address=/ip/127.0.0.1
synth-domain=ip,0.0.0.0,255.255.255.255
This causes all addresses of the form 10-11-12-13.ip
to resolve to the indicated IP address, and everything else on .ip resolves to 127.0.0.1.
E.g.,
$ ping 10-11-12-13.ip
PING 10-11-12-13.ip (10.11.12.13): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
^C
--- 10-11-12-13.ip ping statistics ---
3 packets transmitted, 0 packets received, 100.0% packet loss
$ ping foo.ip
PING foo.ip (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.027 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.071 ms
^C
Finally, note that while dnsmasq does do reverse resolution for synthesized addresses, they will only be reversible on machines which are using a similarly configured instance of dnsmasq.
Upvotes: 4
Reputation: 17903
Yes! 37Signals provides http://xip.io/ and it looks exactly what I was wanting! From its homepage:
xip.io is a magic domain name that provides wildcard DNS for any IP address. Say your LAN IP address is 10.0.0.1. Using xip.io,
10.0.0.1.xip.io resolves to 10.0.0.1 …
Credit: discovered this via https://stackoverflow.com/a/12162955/179583.
Upvotes: 3