How to get 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
Key Facts
- The `hostname -f` command is the most common way to get the FQDN in Linux.
- The FQDN includes the hostname and all domain name components.
- If `hostname -f` returns an incorrect or incomplete name, check your `/etc/hosts` file and DNS settings.
- The `hostname` command without any options shows the short hostname.
- An FQDN uniquely identifies a computer on the internet.
What is an FQDN?
A Fully Qualified Domain Name (FQDN), also known as an absolute domain name, is the complete domain name for a specific computer, or host, on the internet. It is a string of characters that unambiguously identifies the host's location in the hierarchical Domain Name System (DNS). An FQDN consists of a hostname and a domain name. For example, in `server1.example.com`, `server1` is the hostname, and `example.com` is the domain name.
Why is the FQDN Important?
The FQDN is crucial for network communication and identification. It ensures that each device on a network has a unique and resolvable address. This is vital for services like email, web hosting, and secure connections (SSL/TLS certificates), which rely on accurate domain name resolution to function correctly. Without a proper FQDN, a server might not be accessible by its intended name, leading to connectivity issues.
How to Get the FQDN in Linux
The primary command-line utility for retrieving the FQDN on most Linux distributions is hostname. Specifically, using the -f flag tells the command to resolve and display the FQDN.
Using the hostname -f Command
Open your terminal and type the following command:
hostname -fThis command will output the FQDN of your Linux system. For instance, if your system's FQDN is my-linux-box.localdomain, that's what will be displayed.
Understanding the Output
The output of hostname -f is the system's FQDN. If it returns just the hostname or an unexpected result, it often indicates a misconfiguration in the system's network settings.
Alternative Commands and Methods
While hostname -f is the standard, other commands and methods can provide similar information or help diagnose FQDN issues:
hostname: Runninghostnamewithout any flags will display the short hostname (e.g.,my-linux-box).uname -n: Similar tohostname, this command also typically returns the short hostname.dnsdomainname: This command often displays the DNS domain name part of the FQDN (e.g.,localdomain).host: You can perform a reverse DNS lookup to find the hostname associated with an IP address. This can help verify if your FQDN is correctly registered in DNS.dig: Thedig(Domain Information Groper) tool is a more advanced DNS lookup utility. You can use it to query DNS records, including A records (for IP addresses) and PTR records (for reverse lookups).
Troubleshooting FQDN Issues
If hostname -f is not returning the correct FQDN, the issue usually lies in the system's network configuration files. Here are the common places to check:
/etc/hostsfile: This file maps IP addresses to hostnames. It's consulted before DNS. Ensure that your system's IP address is correctly mapped to its FQDN and short hostname. A typical entry might look like this:127.0.1.1 my-linux-box.localdomain my-linux-box/etc/hostnamefile: This file should contain your system's short hostname.- Network Manager or systemd-networkd configuration: Depending on your Linux distribution and how it manages network settings, you might need to check configurations related to these services.
- DNS Server Configuration: Ensure that your DNS server (often specified in
/etc/resolv.conf) is correctly configured and that your FQDN is properly registered with it.
By understanding and correctly configuring these settings, you can ensure that your Linux system has a properly resolved FQDN, facilitating smooth network operations.
More How To in Daily Life
Also in Daily Life
More "How To" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- Fully qualified domain name - WikipediaCC-BY-SA-4.0
- hostname(1) - Linux man pagesCC-BY-4.0
- How to Set Up and Use DNS with BIND on CentOS 7fair-use
Missing an answer?
Suggest a question and we'll generate an answer for it.