How to get fqdn from cmd

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: To get the Fully Qualified Domain Name (FQDN) from the command line, you can use the `hostname -f` command on Linux/macOS or `ipconfig /all` on Windows. The FQDN includes the hostname and its associated domain name, providing a unique identifier for a computer on a network.

Key Facts

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 combination of the hostname and the domain name. For example, if a computer is named 'server1' and it belongs to the 'example.com' domain, its FQDN would be 'server1.example.com'. The FQDN uniquely identifies a host's location in the Domain Name System (DNS) hierarchy. It is crucial for ensuring that network requests reach the correct destination, especially in large or complex networks.

Getting the FQDN on Windows

On Windows operating systems, you can retrieve the FQDN using the Command Prompt (cmd). The most direct way is to use the ipconfig /all command. This command displays a comprehensive list of your network adapter configurations, including the hostname and the DNS suffix search list. If your system is configured correctly, the DNS suffix will often be appended to your hostname to form the FQDN. You can also use the hostname command, which might display just the hostname, and then manually combine it with the DNS suffix if it's not automatically appended.

Alternatively, you can use PowerShell. Open PowerShell and type $env:USERDNSDOMAIN. This environment variable often holds the DNS domain name. Then, you can combine this with the output of hostname. For example, if hostname returns 'mycomputer' and $env:USERDNSDOMAIN returns 'example.com', the FQDN is 'mycomputer.example.com'.

Getting the FQDN on Linux/macOS

On Linux and macOS systems, obtaining the FQDN from the command line is generally more straightforward. The most common command is hostname -f. This command is specifically designed to display the FQDN of the system. If this command does not return the FQDN, it might indicate a misconfiguration in the system's network settings or its DNS resolution capabilities. In such cases, you might need to check the /etc/hosts file and the network configuration files (e.g., /etc/resolv.conf).

Another command that can be useful is simply hostname, which typically returns the short hostname. You can then try to resolve this hostname to its FQDN using tools like dig or nslookup. For instance, running dig -x $(hostname -i) +short can attempt to perform a reverse DNS lookup for the IP address, which often yields the FQDN.

Troubleshooting FQDN Issues

If you are unable to retrieve the FQDN using the standard commands, several factors could be at play:

In summary, while commands like hostname -f (Linux/macOS) and ipconfig /all (Windows) are the primary tools for obtaining an FQDN from the command line, understanding the underlying network and DNS configurations is key to troubleshooting when these commands don't produce the expected results.

Sources

  1. Fully qualified domain name - WikipediaCC-BY-SA-4.0
  2. What is DNS? - Microsoft Learnfair-use
  3. How to Set and Check Hostnames and DNS in Linuxfair-use

Missing an answer?

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