dnsdomainname Command in Linux



The Linux dnsdomainname command prints the system’s DNS domain name. DNS (Domain Name System) translates domain names into IP addresses and vice versa.

The dnsdomainname command extracts the system’s DNS domain name, which can be used in scripting for further processing. It can also be used to check whether a DNS domain name is set.

Let’s understand it with an example: if the fully qualified domain name (FQDN) is "servername.example.com", then the output of the command will be "example.com".

Table of Contents

Here is a comprehensive guide to the options available with the dnsdomainname command −

Syntax of dnsdomainname Command

The general syntax for using the dnsdomainname command is as follows −

dnsdomainname

The dnsdomainname is a straightforward command and does not come with any specific options.

Examples of dnsdomainname Command in Linux

This section covers the usage of the dnsdomainname command in Linux.

Displaying the Domain Name

To display the domain name, execute the dnsdomainname command −

dnsdomainname
Displaying Domain Name dnsdomainname Command

The output shows that example.com is the system’s domain name.

You may get no output because this command does not produce any output unless a domain name is set.

Checking the Domain Name Configuration

The dnsdomainname is a simple command that can be used to check whether a domain name is set or not on a Linux. The following script checks whether the system's domain name is set or not.

#!/bin/bash

domain=$(dnsdomainname)

if [ -z "$domain" ]
then
   echo "Domain name is not set"
else
   echo "Domain name is set $domain"
fi
Checking Domain Name dnsdomainname Command

Difference between Hostname and Domain Name

A FQDN contains both the hostname and the domain name. The hostname is the endpoint or machine, while the domain name is a unique name used to identify a device over a network. For example, if the FQDN is myserver.example.com, the hostname will be myserver, while example.com will be the domain name.

Conclusion

The dnsdomainname command in Linux displays the system’s domain name if it is set. The command may give an empty output if the domain name is not configured.

The dnsdomainname command is a part of the Linux net-tools package and can be used to verify the domain name configuration on a system.

In this tutorial, we covered the dnsdomainname command, its syntax, and its usage on Linux.

Advertisements