DNS Configuration Tool
Download hosts2dns-0.95.tar.gz (09/19/11)
See the Change Log.
New! Added support for Mac OSX Lion.
This program makes it easy to maintain a DNS server by just using the entries
in your /etc/hosts file.
Special comment markers (shown in red below) set the domain name, and 'START' and 'END'
markers set which entries in the /etc/hosts file will be added to DNS.
Setting Up A New DNS Server
Here's an example of how to set up a new DNS server on a Mac OSX machine:
- Install the hosts2dns script in /usr/sbin
- Edit your /etc/hosts file
Add the red text comments to configure the domain name,
and start/end of hosts you want in DNS:
# HOST ENTRIES BETWEEN THE START/END MARKERS WILL BE INSTALLED IN DNS
# After making changes here, run 'hosts2dns -update'
# to update your changes to DNS. Aliases are optional.
#!DNS:DOMAIN foo.x -- CHANGE THIS: SET TO YOUR DNS DOMAIN NAME
#!DNS:START -- Start of hosts to be added to DNS
192.168.0.1 router ro -- eg. this will become router.foo.x
192.168.0.2 howland ho how -- eg. this will become howland.foo.x
192.168.0.3 tahoe ta
192.168.0.4 meade me
192.168.0.5 superior su sup
192.168.0.6 ontario on
192.168.0.8 powell po pow
192.168.0.9 texoma te tex
192.168.0.10 george ge geo
192.168.0.11 michigan mi mich
192.168.0.12 havasu ha
#!DNS:END -- End of hosts to be added to DNS
- Run 'hosts2dns -update' to start up your DNS server:
$ hosts2dns -update -- installs and starts DNS|
- That's it.
hosts2dns should create a named.conf file, the appropriate zone files,
and should enable your DNS server so that it starts on boot, and starts it
You should be able to then test your new server with nslookup(1) [what you type is shown in blue]:
$ nslookup -- start nslookup(1) so we can test our DNS server
> server 192.168.0.2 -- point nslookup at our new DNS server
Default server: 192.168.0.2
> tex -- check the alias for 'texoma'
tex.foo.x canonical name = texoma.foo.x. -- correctly determined we used a CNAME
Name: texoma.foo.x -- correct official name
Address: 192.168.0.9 -- correct IP address of texoma
> 192.168.0.9 -- check the reverse lookup for texoma's IP
18.104.22.168.in-addr.arpa name = texoma.erco.x. -- correct reverse lookup
> google.com -- check internet lookups
Name: google.com -- correct lookups for google.com
> quit -- quit back to the shell
Assuming you then configure all your client machines to use your new DNS server,
and have the "Search Domain" set to the domain you set for the
#!DNS:DOMAIN command, your DNS clients
should now be able to resolve hostnames (eg. via nslookup(1)).
When ever you need to add or remove machines, just edit the /etc/hosts file,
then run 'hosts2dns -update' to update your changes.
When you run 'hosts2dns -update', the hostnames between
the START/END markers will be added to DNS; the script handles
updating the zone file's hostnames and serial numbers, and handles
re-starting the DNS daemon. Hostname aliases are automatically
converted into DNS 'CNAME's.
When you need to add or remove hosts from DNS, just edit your /etc/hosts file,
then re-run 'hosts2dns -update' to make the changes take effect. The DNS files
will be rebuilt, and the server will be updated.
This script is intended *only* for maintaining a simple, single internal
fictitious DNS domain (such as for a small home or business network)
on an internal DNS server that is inside a firewall. The DNS server will
act as an authoritative server for your internal domain, and will also
resolve internet domain names through the root servers, the way any regular
DNS server would. (ie. it does *not* depend on your ISP's name server
to resolve internet names)
This script overwrites any previous DNS installation on the local machine;
no attempt is made to preserve any previous DNS server configuration.
This script assumes it is free to completely manipulate the local DNS server
and all its related files.
The purpose of this script is to be as simple to operate as possible,
and thus, is dedicated to a very specific configuration. For this reason,
the script does handle multiple subnets, or complex DNS configurations
where eg. security is an issue.
By having your DNS server /inside/ a NAT'ing firewall, it will be completely
secure from the outside, and your local 'fictitious' domain will be
completely limited to your internal network.
The following is what you get when you run 'hosts2dns' without
any arguments, or with the -help flag:
hosts2dns -- Converts /etc/hosts file into DNS server config
Version 0.95, Copyright (C) 2006 Greg Ercolano.
Your /etc/hosts file is used for all input information
to control this program. (See -showexample)
-update -- update DNS with current /etc/hosts
-view -- view files to be generated (no update)
-viewzone -- view files to be generated (no update)
-showexample -- show an example hosts file
-update will update the named.conf and all zone files with
new serial numbers, and handles telling DNS to reload.
If DNS isn't running, hosts2dns starts it, and enables
it to start on boot (if possible).
After doing an -update, tail your syslog to check
for error messages from "named" (the DNS daemon).
WARNING: "hosts2dns -update" does NOT try to save
your previous DNS configuration. Any previous
named.conf and zone files will be *overwritten*!
Whenever you create or modify your /etc/hosts file,
run this command to update those changes to DNS:
If you are DNS savvy, and want to see the zonefiles host2dns
would create, without it actually saving them out, use:
If you're just starting out, and want to see an example /etc/hosts
file configured for hosts2dns, use:
This script is licensed under the GPL. See the script and the LICENSE.txt
file in the tar file you downloaded for details.
To report bugs, see the instructions in the comment header at the top
of the script.
Back to my home page.
You can send me mail.