This is not a complete DNS setup tutorial.
It covers how to how hostnames can be resolved using /etc/hosts instead of running a DNS server such as BIND.
It also covers how to set up a caching-only DNS server, to fasten up your DNS queries.
0.0.0.0 and 0 refer to the local host, and 127.0.0.1 refers to the loopback interface.
The difference between 0.0.0.0 and 127.0.0.1 is that the former refers to the local host's physical interface(s), while the latter refers to a software interface.
So on a computer with no NIC, only 127.0.0.1 will work.
From the man page of the loopback interface, man lo, we can read:
"The loop interface is a software loopback mechanism which may be used for performance analysis, software testing, and/or local communication."
So, in the end, 127.0.0.1 also refers to the local host.
The loop interface acts as any network interface, which means you can perform the following operations on it, for example:
ifconfig lo0 down (you can't ping 127.0.0.1 now)
ifconfig lo0 up
ifconfig lo0 1.2.3.4 (your loopback IP changed to 1.2.3.4, try to ping 1.2.3.4)
ifconfig lo0 127.0.0.1
which brings down, up, sets, and restores lo0's IP, respectively.
Conclusion: It isn't surprising that you can see a local host's web page using the IPs in the examples above.
But what about localhost?
Why does localhost resolve to a local IP?
No DNS server is configured to resolve localhost to your computer's IP (you may even be disconnected from the Net, unable to query a DNS server).
Let's have a look at the hosts line in /etc/nsswitch.conf:
hosts: files dns
This means that address lookups are done first trying to query local files, and only if that fails trying to query a DNS server.
Check man nsswitch.conf for details.
nsswitch.conf generates host.conf automatically:
# Auto-generated from nsswitch.conf
hosts
dns
Here we can see explicitly that address lookups query the /etc/hosts file.
Now it's time to modify /etc/hosts.
The format for each line is row is
/etc/namedb/named.conf is the only BIND file which has to be modified:
// uncomment this line to not resolve any names in our server
forward only;
// uncomment these lines to point to the ISP's DNS servers
forwarders
{
192.168.1.1; 192.168.1.2;
};
// add this line to configure a caching only nameserver
zone "0.0.127.in-addr.arpa" { type master; file "master/localhost-reverse.db"; };
We don't have to touch /etc/namedb/master/localhost-reverse.db.
Just assure it looks like this:
Check that the named process is running correctly:
ps axww|grep named
3867 ?? Ss 0:00.04 /usr/sbin/named -t /var/named -u bind
tail /var/log/messages
May 30 13:34:12 localhost named[4223]: starting BIND 9.4.3-P2 -t /var/named -u bind
May 30 13:34:12 localhost named[4223]: command channel listening on 127.0.0.1#953
May 30 13:34:12 localhost named[4223]: command channel listening on ::1#953
May 30 13:34:12 localhost named[4223]: the working directory is not writable
May 30 13:34:12 localhost named[4223]: running
The message the working directory is not writable seems to be ignorable, according to this forum discussion.
You can test the caching-only server like this:
dig @127.0.0.1 google.com
The first time, there may be a short delay during the query before the response.
The second time, the query should respond must faster.
That means that you queries are caching properly.
You can use any hostname or alias configured in /etc/hosts for your queries: