Monday, September 26, 2011

A DNS server to test your mobile apps

Why would you want to set up an Internet Domain Name System server (DNS) on your laptop? Well, it can be handy to serve test domain names to your iPhone and test the mobile apps you're working on, or to use HTTPS on an insecure network with an TLS/SSL certificate you've created for your test domains.

DNS has a reputation to be tricky to set up, so I thought I'd share the steps to do it on Mac OS X. It's easy, when you know what to do.

Say you want to map the supercoolapp.com domain (an example test domain) and all the *.supercoolapp.com sub-domains to IP address 10.1.1.55 for example.

1) In a terminal window run the following commands:
sudo rndc-confgen -a -c /etc/rndc.key
to generate the rndc.key file as it's included by /etc/named.conf.
Named is the domain name server, rndc is the Mac OS name server control utility.

sudo launchctl load -w /System/Library/LaunchDaemons/org.isc.named.plist
to enable and start named.

2) Add the following to the /etc/named.conf file:
zone "supercoolapp.com" {
  type master;
  file "supercoolapp.com.zone";
};


3) Create a /var/named/supercoolapp.com.zone file, containing this:
supercoolapp.com. 7200 IN SOA supercoolapp.com. root.supercoolapp.com. (
3 ; Serial
15 ; Refresh
3600 ; Retry
3000000 ; Expire 86400 ) ; TTL
IN NS supercoolapp.com.
IN MX 10 supercoolapp.com.
IN A 10.1.1.55
*.supercoolapp.com. IN A 10.1.1.55


4) Open your Mac OS System preferences, go to Network / Advanced / Dns and add 127.0.0.1 to the top of the DNS servers list.

5) To test your new DNS settings try this:
dig my.supercoolapp.com
ping my.supercoolapp.com


6) On your iPhone go to Settings / your wifi network / DHCP and change the DNS field to your Mac OS system's IP address.

7) That's it! Now open http://my.supercoolapp.com in Safari on your iPhone. You should hit your mobile app running on 10.1.1.55.

Hope this helps!


The postings on this site are my own and don’t necessarily represent positions, strategies or opinions of my employer IBM.