- slide 1 of 4
What is a hostname?
A hostname is the name given to a server that is part of a network. But a server name must follow certain rules. Most will recognize the FQDN - Fully Qualified Domain Name - such as mail.yourdomain.com. Let's take a look at that sample FQDN. We'll break the name into two sections: mail and yourdomain.com. Say you are a business and you own the domain name "yourdomain.com". You want to set up various servers to serve up web, mail, ftp, etc. To have all of these servers on one domain you might have a machine called mail.yourdomain.com, a machine called www.yourdomain.com, and a machine called ftp.yourdomain.com. Now you have mail, web, and ftp all on your single domain.
- slide 2 of 4
If you issue the command hostname -a, if you haven't already set your hostname, you might see something like this:
The -a switch instructs hostname to report the alias name of the host (if one is used.) If you issue the command hostname -d you might see something like this:
The -d switch instructs hostname to report the DNS domain name of the server. If you issue the command hostname -f you might see something like this:
- slide 3 of 4
Setting the hostname
You can also set the hostname of the server with the command hostname YOURHOSTNAME (Where YOURHOSTNAME is the hostname you want to use.) Now a problem can arise. If the hostname you set with the command differs from the hostname in the /etc/hosts file you will have some problems with your machine. If you need to set your hostname with the command you will want to edit the /etc/fstab file to match what you have entered with hostname.
- slide 4 of 4
The most useful aspect of the hostname command is, without a doubt, the ability to check hostnames on servers. Being able to set that hostname with this command is a definite plus. Just make sure you don't create a discrepancy between the hostname command and /etc/hosts.