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.

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”.

To check your hostname, as user run:


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

hostname -f

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 unless you have reason to assign it differently. For example, on one box (FQDN verdi.home.invalid) I have:

[warren@verdi ~]$ cat /etc/hosts    localhost    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.

In openSUSE 42.2 and 42.3, 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

In one instance on 42.3 I also had to open System – Network Settings – Global Options and change the general network settings from the default Wicked Service to the NetworkManager Service. I suspect this should not be necessary however.

You will need to log out and back in before the hostname will take effect.

Some distributions (openSUSE, Ubuntu, and no doubt others) ask for a computer name during a clean install. Provide a name or FQDN here and avoid the hassle of having to set it manually later.

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


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.

5 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

  5. Pingback: Upgrading to openSUSE 42.3 | A maze of twisty little passages

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s