How to fqdn in linux

Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.

Last updated: April 4, 2026

Quick Answer: In Linux, an FQDN (Fully Qualified Domain Name) is a complete domain name for a specific computer or host on the internet. It includes the hostname and the domain name, separated by a dot (e.g., `mycomputer.example.com`). You can view your system's FQDN using commands like `hostname -f` or by checking the `/etc/hosts` file.

Key Facts

What is an FQDN in Linux?

In the realm of networking and computer systems, a Fully Qualified Domain Name (FQDN), sometimes also referred to as an absolute domain name, is the complete domain name for a particular computer, or host, on the internet. It specifies its exact location in the hierarchical Domain Name System (DNS). An FQDN consists of a hostname and a domain name, separated by a dot. For instance, if your computer's hostname is `mywebserver` and it belongs to the `example.com` domain, its FQDN would be `mywebserver.example.com`.

Understanding Hostnames and Domain Names

Before diving deeper into FQDNs, it's crucial to understand the components:

An FQDN combines these two elements to create a unique address. The FQDN is always read from left to right, starting with the specific hostname and ending with the top-level domain. For example, in `www.example.com`, `www` is the hostname, and `example.com` is the domain name.

How to Find Your FQDN in Linux

Linux provides several straightforward ways to determine your system's FQDN:

Using the `hostname` command

The most common and direct method is to use the `hostname` command with the `-f` (or `--fqdn`) option:

hostname -f

This command attempts to resolve the system's hostname to its FQDN using DNS or the local host file. If your system is configured correctly and has a valid FQDN registered in DNS, this command will output it.

Checking the `/etc/hosts` file

The `/etc/hosts` file is a crucial system file that maps IP addresses to hostnames. It's often used for local network name resolution before DNS is consulted. You can inspect this file to see how your system's hostname is defined:

cat /etc/hosts

Look for a line that starts with `127.0.1.1` or your system's primary IP address, followed by your hostname and potentially your FQDN. For example:

127.0.0.1 localhost127.0.1.1 myhostname.mydomain.com myhostname

In this example, `myhostname.mydomain.com` is the FQDN.

Using the `uname` command

While `uname` primarily provides system information, the `-n` option can display the network node hostname:

uname -n

This might output just the hostname or the FQDN, depending on the system's configuration.

Configuring Your FQDN in Linux

Setting up a correct FQDN is important for various network services, including email servers, web servers, and secure shell (SSH) connections. Here’s how you can configure it:

Editing `/etc/hostname` (or `/etc/sysconfig/network` on older systems)

The primary hostname is often set in the `/etc/hostname` file. You can edit this file to set your desired hostname. For systems using older network configuration scripts (like Red Hat/CentOS 6 and earlier), the hostname might be set in `/etc/sysconfig/network` within the `HOSTNAME=` variable.

After changing this file, you'll typically need to reboot or restart networking services for the changes to take effect.

Editing `/etc/hosts`

As mentioned earlier, this file plays a role in name resolution. Ensure it has an entry that maps your system's primary IP address (or `127.0.1.1` for local resolution) to your desired FQDN and hostname. For example:

sudo nano /etc/hosts

Add or modify a line like:

192.168.1.100 myhostname.mydomain.com myhostname

Replace `192.168.1.100` with your actual static IP address.

Configuring DNS (for external access)

If your Linux machine needs to be accessible from the internet or other networks, you'll need to configure your DNS records. This involves:

  1. Registering a domain name: Purchase a domain name from a domain registrar.
  2. Creating DNS records: Log in to your domain registrar's control panel or your DNS hosting provider's interface. Create an 'A' record that maps your desired FQDN (e.g., `mywebserver.mydomain.com`) to your server's public IP address. You might also need a 'PTR' record for reverse DNS lookups.

This process is external to your Linux system itself but is crucial for making your FQDN resolvable across the internet.

Why is an FQDN Important?

A properly configured FQDN is essential for several reasons:

Troubleshooting FQDN Issues

If `hostname -f` is not returning the expected FQDN, consider the following:

In summary, an FQDN is your computer's full, unique address on the internet, comprising its hostname and domain name. Linux provides simple commands and configuration files to view and set this crucial network identifier.

Sources

  1. Fully qualified domain name - WikipediaCC-BY-SA-4.0
  2. hosts(5) - Linux man pagefair-use
  3. How to Set or Change the Hostname on a Linux System - Red Hatfair-use

Missing an answer?

Suggest a question and we'll generate an answer for it.