next up previous contents index
Next: 4.11 What To Do Up: 4.10 Miscellaneous Tasks Previous: 4.10.1 System startup files

4.10.2 Setting the hostname

      In a networked environment, the hostname is used to uniquely identify a particular machine, while in a standalone environment the hostname just gives the system personality and charm. It's like naming a pet: you can always address to your dog as ``The dog,'' but it's much more interesting to assign the dog a name such as Spot or Woofie.

Setting the system's hostname is a simple matter of using the hostname command. If you are on a network, your hostname should be the full hostname of your machine, such as goober.norelco.com. If you are not on a network of any kind, you can choose an arbitrary host and domainname, such as loomer.vpizza.com, shoop.nowhere.edu, or floof.org.

When setting the hostname, the hostname must appear in the file /etc/hosts, which assigns an IP address to each host. Even if your machine is not on a network, you should include your own hostname in /etc/hosts.

For example, if you are not on a TCP/IP network, and your hostname is floof.org, simply include the following line in /etc/hosts:

127.0.0.1 floof.org localhost

This assigns your hostname, floof.org, to the loopback address 127.0.0.1 (used if you're not on a network). The localhost alias is also assigned to this address.

If you are on a TCP/IP network, however, your real IP address and hostname should appear in /etc/hosts. For example, if your hostname is goober.norelco.com, and your IP address is 128.253.154.32, add the following line to /etc/hosts:

128.253.154.32 goober.norelco.com

If your hostname does not appear in /etc/hosts, you will not be able to set it.

To set your hostname, simply use the hostname command. For example, the command

# hostname -S goober.norelco.com

sets the hostname to goober.norelco.com. In most cases, the hostname command is executed from one of the system startup files, such as /etc/rc or /etc/rc.local. Edit these two files and change the hostname command found there to set your own hostname; upon rebooting the system the hostname will be set to the new value.



next up previous contents index
Next: 4.11 What To Do Up: 4.10 Miscellaneous Tasks Previous: 4.10.1 System startup files



Matt Welsh
mdw@sunsite.unc.edu