Setting a hostname and FQDN

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.

BACKGROUND
For clarity’s sake, this section assumes a home network or an equally trivial setup.

An FQDN takes the form hostname.domain.tld, where:

  1. 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.
  2. 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.
  3. 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:

hostname

And to check your FQDN, add the “-f” argument:

hostname -f

CHANGING THEM
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:

HOSTNAME=hostname.domain.tld

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.

REFERENCES
Mageia-2 Beta3: Terminal session still says “user@localhost”
Setting an FQDN in Mageia and Ubuntu

Advertisements

About Warren Post

So far: Customer support guy, jungle guide, IT consultant, beach bum, entrepreneur, teacher, diplomat, over-enthusiastic cyclist. Tomorrow: who knows?
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

4 Responses to Setting a hostname and FQDN

  1. Pingback: Installing and configuring vtiger | Warren's tech notes

  2. Pingback: Installing Apache locally on Linux | Warren's tech notes

  3. Pingback: Configuring postfix | A maze of twisty little passages

  4. Pingback: Security and stability tuning on Linux | A maze of twisty little passages

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s