By default, a new Linux installation is named “localhost” or “localhost.localdomain” on many distributions. You should usually replace this with at least a hostname. And for some purposes you’ll need a fully qualified domain name (FQDN).
Curiously, I have been unable to find authoritative newbie-friendly instructions for this basic task. What follows is my understanding of best practice, but may contain errors, omissions, or be inappropriately distro-specific. Please correct me as needed in the comments.
For clarity’s sake, this section assumes a home network or an equally trivial setup.
An FQDN takes the form hostname.domain.tld, where:
- hostname is the name of a specific computer, router, or other named device on the given domain. The hostname manpage calls this the short host name. It can be whatever you want, although it is customary to have a naming scheme. In the workplace, those who follow in your footsteps will appreciate functional names: accounting, marketing, billing. On a home network, you have more latitude. My home devices are named after composers: Bach, Mozart, Verdi. Other people use planets, elements of the periodic table, or favorite breakfast cereals. Be creative and earn yourself some geek cred.
- domain is the name of the local network the device is on. It likewise can be whatever you want, so long as all devices on the network use the same. For the local network of a small business, your company’s name or initialism might be a good choice. For a home network, “home” is the logical if unimaginative choice.
- tld is the top level domain (TLD). For our purposes, it should normally be “invalid”.
CHECKING YOUR HOSTNAME AND FQDN
To check your hostname, as user run:
And to check your FQDN, add the “-f” argument:
In the following instructions, replace “hostname” and “hostname.domain.tld” as appropriate. All editing is done as root.
Changing the hostname
Edit /etc/hostname so that it contains only one datum: your hostname (not your FQDN). There is disagreement on this point: some authorities state that what goes here should be the FQDN.
It is usually desirable to have /etc/hosts associate your short hostname and FQDN with an IP address. For our trivial example setup, that would be 127.0.1.1 unless you have reason to assign it differently. For example, on one box (FQDN verdi.home.invalid) I have:
[warren@verdi ~]$ cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 verdi.home.invalid verdi
Changing the FQDN
How this is done depends on your distribution. On Red Hat and derivatives, edit /etc/sysconfig/network to contain the line:
TODO: Document what to do on Debian and derivatives. In the meantime, my Ubuntu boxes do what I need without FQDNs and only have hostnames.
Checking your work
Give the commands hostname and hostname -f as above and insure that the results are as expected. Reboot and check your work again. Once all is well, add the files you edited to your backup set.
SETTING IT IN DISTRO-SPECIFIC TOOLS
In openSUSE 42.2, open YaST and go to System – Network Settings – Hostname/DNS – Hostname and Domain Name. The following settings work for me:
- Hostname: As desired (e.g. Vivaldi)
- Domain Name: As desired (e.g. home.invalid)
- Change Hostname via DHCP: yes, any
- Assign Hostname to Loopback IP: Enabled
TIPS AND TRICKS
Some distributions (Ubuntu and perhaps others) ask for a computer name during a clean install. Provide an FQDN here and avoid the hassle of having to set it manually later.