Red Antigua Logo slogan
Ads by Goooooogle
Search this site (by Google)
Menu
Home
About
Tools
Perl modules
Perl tutorials
C tutorials
Server configurations
UNIX on Windows
Misc. FreeBSD/UNIX
Redirect a web page
JavaScript
Virus list
Old stuff
Off topic

Tools    (top)
Your IP
Check a site for broken links
(W3C)

Perl modules    (top)
Tree::Numbered::Tools
(CPAN)
Perl tutorials    (top)
Perl modules
HTML::Template
CGI::Application
Mail::POP3Client
Mail::Send
MIME::Tools
Cookies with CGI::Application
Upload files with CGI::Application
Download files with CGI::Application
Redirect with CGI::Application
CPAN shell
Install DBD::mysql from the CPAN shell
Perl trim function
Validate an IP with Perl
Run suid Perl scripts under Apache
Perl taint mode
Perl date functions with Date::Calc

In Spanish
Curso de Perl

C tutorials    (top)
C - Introduction
C - Absolute beginner's Emacs
C - Examples for beginners
C - Makefile examples
C - Autotools examples
Server configurations    (top)
DNS
Apache
Apache Authentication and Access Control
mod_perl on FreeBSD
MySQL
MySQL add account
phpMyAdmin
Squid
DHCP

UNIX on Windows    (top)
Apache setup on Windows
MySQL setup on Windows
PHP setup on Windows
Perl setup on Windows
Emacs setup on Windows
UnxUtils
PuTTY
WinSCP
GIMP on Windows
MinGW - gcc on Windows
MSYS - make-in-a-shell on Windows
msysDTK - autotools on Windows
GDB for MinGW on Windows

Misc. FreeBSD/UNIX    (top)
CD and DVD creation on FreeBSD using 'k3b' on FreeBSD
'ipf' on FreeBSD
'pf' on FreeBSD
'su' on FreeBSD
Mount an ISO image under FreeBSD
Load the correct sound driver under FreeBSD without knowing what sound card you are using
Simultaneous sound channels on FreeBSD
Boot floppies for FreeBSD
Problems with old disks/controllers and the 'ata' driver
FreeBSD network stuff
DOS-to-UNIX file conversion
favicon.ico on UNIX
Emacs tips
Sendmail tips
GKrellm
Command Line Calculator
Save multimedia streams with 'mplayer'
xargs - solution to 'Argument list too long'
Process multiple images from the command line using 'ImageMagick'
Turn the system bell off under X Windows
Process each line in an input file from the command line (or in a shell script)
How to keep a program running in the background using 'nohup'
How to remove symbolic links in the current directory using 'find' and 'rm'
How to remove Emacs backup files in the current directory and all subdirectories using 'find' and 'rm'
How to execute .profile without logging in

Redirect a web page    (top)
Redirect to another web page
Apache redirect
C redirect
Perl redirect
PHP redirect
HTML redirect
JavaScript redirect

Javascript    (top)
Trim function
Login form
Register form
Popup window

Virus list    (top)
Latest viruses - Computer Virus HQ (external)
Latest 10 viruses - Sophos

Links    (top)
HTML and PHP Scripts - Html Web Template

Old stuff    (top)
POP3 server setup
About AnyMail
AnyMail downloads

Off topic    (top)
Personal links

Validated by
Valid HTML 4.01!
Valid CSS!
Powered by
apache.org
DNS setup
DNS setup
Using /etc/hosts
Using BIND

This is a DNS setup tutorial, but first we will have a look at how names can be resolved using /etc/hosts instead of running a DNS server such as BIND.


Using /etc/hosts (top)

Let's say you have setup Apache on the local host, and want to access some document:
http://0/myfirsttest.html
http://0.0.0.0/myfirsttest.html
http://127.0.0.1/myfirsttest.html
http://localhost/myfirsttest.html
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, and sets 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 /etc/host.conf:
# First try the /etc/hosts file
hosts
# Now try the nameserver next.
bind
Let get the details from man /etc/host.conf:
hosts        When this service name is used in host.conf, name and
             address lookups are done by using the local hosts database.
             The local hosts database is described in hosts(5).
bind         This service makes the resolver use Internet Domain System
             (DNS) for resolving hostnames and addresses.  The DNS
             resolver configuration is described in resolver(5).
This means that before even trying to query a DNS server, address lookups are done using /etc/hosts:
127.0.0.1              localhost localhost.my.domain myname.my.domain
Here is where 127.0.0.1 resolves to localhost.
As you see, it also resolves to localhost.my.domain and to myname.my.domain, so you can also access you web documents these ways:
http://localhost.my.domain/myfirsttest.html
http://myname.my.domain/myfirsttest.html
because they all resolve to the loopback interface, IP 127.0.0.1.
Now modify /etc/hosts:
127.0.0.1              localhost www www.redantigua.com redantigua.com bengt.dennis.com
Now you can access your web documents these ways:
http://localhost/myfirsttest.html
http://www/myfirsttest.html
http://www.redantigua.com/myfirsttest.html
http://redantigua.com/myfirsttest.html
http://bengt.dennis.com/myfirsttest.html
To separate the web contents between different domains resolving to the same server, have a look at this Apache virtual hosts example.

So now we know about three different sources that affect the access to localhost.
  • lo0
  • /etc/host.conf
  • /etc/hosts
Here arethree ways to disable access to localhost:
  • lo0 down
  • Comment out the 'hosts' line in /etc/host.conf
  • Removing the word 'localhost' line in /etc/hosts


Using BIND (top)

WORK IN PROGRESS

Last modified: Wed Mar 21 17:36:19 Romance Standard Time 2007