Remember that you are resolving names to IP addresses.
Your hosts file can act as the poor man's DNS by adding entries of IP address/ name combinations (mappings).
On a small network it might be easier to assign static IP's (like 192.168.1.10, 192.168.1.11 etc) to each machine and then add them to the hosts file. Otherwise, the common SOHO/residential routers
have DNS capabilities, which you could enable.
Let's say you have three machines. You give them the static IP's and host names:
192.168.1.10 tgrier1
192.168.1.11 tgrier2
192.168.1.12 tgrier3
The /etc/hosts file for tgrier1, tgrier2 and tgrier3 would look like this:
Quote:
/etc/hosts
127.0.0.1 localhost.localdomain localhost
192.168.1.10 tgrier1
192.168.1.11 tgrier2
192.168.1.12 tgrier3
|
Now you can reference tgrier2 from tgrier1 by just typing tgrier2 (user@tgrier2, ssh tgrier2, etc. etc.), because the local hosts file points to 192.168.1.11.
There would be no reason to prevent you from creating your own domain, but you couldn't use it on the internet, i.e., machines from the internet would not be able to resolve the IP address unless it was a legal and registered domain name (xxxx.com, xxxx.org, etc), and you have DNS set up.
For example, you can create a domain called grier.inc and then name your machines
tgrier1.grier.inc, tgrier2.grier.inc and tgrier3.grier.inc.
The hosts file would end up like this:
Quote:
/etc/hosts
127.0.0.1 localhost.localdomain localhost
192.168.1.10 tgrier1.grier.inc tgrier1 tg1
192.168.1.11 tgrier2.grier.inc tgrier2 tg2
192.168.1.12 tgrier3.grier.inc tgrier3 tg3
|
Notice tg1, tg2 and tg3. I have created nicknames or aliases for the fully qualified domain names, so now I can reference the machines by them.
What is cool about the hosts file, is when working on web-site development, you often create the pages with links in them, that reference your real domain name, such as
www.grier.com.
If you haven't registered the name yet, but need to view them in your browser to make sure it all works as intended, you create an entry in your hosts file that references the
www.grier.com domain, i.e., the development site on the machine:
Quote:
/etc/hosts
127.0.0.1 localhost.localdomain localhost
192.168.1.10 www.grier.com
|
Now you can enter the url into your browser without it trying to resolve the name via DNS on the internet i.e., it resolves it via the hosts file. Obviously you would need content and a web server enabled to do this.
If you actually click on the link above (
www.grier.com), you would be taken to a site that claims ownership of the domain. Likewise, if you had a web-site already running somewhere (
www.grier.com hosted for example), the entry in the hosts file would conflict, if your intent was to resolve the real site instead of your development site on the local machine. You would then have to remove the entry or comment it by placing a hash/pound character (#) in front of the line.