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
Key Facts
- The FQDN combines the hostname with its domain name (e.g., 'mycomputer.example.com').
- The `hostname -f` command is commonly used on Unix-like systems.
- On Windows, `ipconfig /all` displays network configuration details including the DNS suffix and hostname, from which the FQDN can be inferred.
- The `nslookup` command can also be used to resolve a hostname to its FQDN.
- An FQDN is essential for unambiguous network communication and resource identification.
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:
- Network Configuration: Ensure your computer has a valid IP address and is connected to a network that provides DNS services.
- DNS Settings: Verify that your system's DNS settings are correctly configured to resolve hostnames and domains. This often involves checking the DNS server addresses and the domain search list.
- `/etc/hosts` File (Linux/macOS): The
/etc/hostsfile maps IP addresses to hostnames. An incorrect entry here can interfere with FQDN resolution. - Network Adapter Settings (Windows): In Windows, check the properties of your network adapter, particularly the DNS settings and the advanced TCP/IP settings, to ensure the correct DNS suffix is being used.
- DHCP: If your IP address is assigned by DHCP, ensure the DHCP server is providing the correct domain name information.
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.
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
Missing an answer?
Suggest a question and we'll generate an answer for it.