Here's a thing. Slackware almost always includes notes and cautions in configuration files (if they're not already there from the developers); sort of lessons learned during a wasted youth kinds of things.
/etc/hosts, straight from the "factory," has this:
Code:
# By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1
# should NEVER be named with the name of the machine. It causes problems
# for some (stupid) programs, irc and reputedly talk. :^)
#
# For loopbacking.
127.0.0.1 localhost
So that one has to be there and you should not monkey with it.
Your machine should have a name and an address. The name can be anything you like (the default on Slackware is "darkstar"); just something short and sweet (I name my servers
fubar,
snafu,
pita and other pungent things). The address for a non-public server (not an Internet address) should be something like 192.168.x.y. The
x is the subnet address from your router or switch and is, usually but not always, 1. The
y is an address you pick, greater than 1 and less than 100, just so it's unique on your network (consisting of one or more Ethernet devices -- computers, printers, etc.)
Why 1? Because 1 is usually the gateway address of your router (a lot of them default to 192.168.1.1. Why < 100? Because DHCP starts at 100 by default and you can use a fixed IP address for your machine less that 100 and it won't interfere with DHCP.
Remember, we're talking about Slackware here; some other distribution might do things differently (and who cares what some other distribution fiddles around with).
Do you have a router? Probably you do -- many of the "modems" you get from your service provider nowadays are a combination modem/router (so you can't conveniently run a web site).
So, what does an
/etc/hosts file look like? Like this:
Code:
#
# hosts This file describes a number of hostname-to-address
# mappings for the TCP/IP subsystem. It is mostly
# used at boot time, when no name servers are running.
# On small systems, this file can be used instead of a
# "named" name server. Just add the names, addresses
# and any aliases to this file...
#
# By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1
# should NEVER be named with the name of the machine. It causes problems
# for some (stupid) programs, irc and reputedly talk. :^)
#
# For loopbacking.
127.0.0.1 localhost
# Local servers
192.168.1.10 fubar.com fubar
192.168.1.15 InkJet
192.168.1.20 snafu.com snafu
192.168.1.30 pita.com pita
# Public servers
75.126.162.205 www.linuxquestions.org linuxquestions.org
# End of hosts.
In the above there are three local servers,
fubar.com,
snafu.com and
pita.com. There is one Ethernet printer,
InkJet. This is one external server,
linuxquestions.org.
Defining an external server as above means that you avoid hitting a DNS server;
/etc/hosts is the first place "looked at" to find an address and, if an address is not found in
/etc/hosts, the next places looked at is a DNS server, either BIND (if you're running it) or DNS server addresses in
/etc/resolv.conf; e.g.,
Code:
cat /etc/resolv.conf
search com
nameserver 8.8.8.8
nameserver 8.8.4.4
Those two -- you only need two -- are Google's public DNS servers addresses. You're free to use those or ISP-provided addresses (these are just an example). If the first one is not available, the second will be looked at and it will take some time for the look up to fail before that switch happens (by then you'll be frustrated) so make sure you've got good DNS server addresses in
/etc/resolv.conf.
Now, the trick is that all your local servers are listed in
/etc/hosts (and the file is identical on all the servers). The IP address is first, followed by the name and domain of the server; e.g.,
fubar.com, followed by an alias (
fubar). The alias means that your can, say, connect from
fubar to
snafu with SSH like this:
You don't have to type the domain name. Not really a big deal, just a convenience.
Your host name is found in
/etc/HOSTNAME; e.g.,
Code:
cat /etc/HOSTNAME
fubar.com
That's pretty much it. Simple and elegant.
Hope this helps some.