domainname Command in Linux



The Linux domainname command displays or sets the NIS/YP domain name of the system. The Network Information Service (NIS), formerly known as Yellow Pages (YP), connects systems using shared NIS maps within an NIS domain. Each NIS domain has a name called the NIS domain name.

Table of Contents

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

Note − The NIS/YP is no longer used because of its poor security. They are largely replaced by newer and secure protocols such as LDAP, FreeIPA, or Kerberos. However, though not encouraged, the NIS/YP can still be set up in systems where security is not a concern.

Syntax of domainname Command

The syntax for the domainname command is as follows −

domainname [options]

The [options] field is used to display various details about the domainname command.

domainname Command Options

The commonly used options for the domainname command are listed in the following table −

Flags Options Description
-a --alias It displays the alias associated with the domain name
-A --all-fqdns It displays all Fully Qualified Domain Names associated with the host
-b --boot name It sets the domain name if it is not currently set
-d --domain It displays the domain name of the DNS
-F file It reads the hostname or NIS information from the specified file
-f --fqdn / --long It displays the long hostname of a fully qualified domain name
-h It displays the help about the command
-i --ip-address It displays the IP address(es) of the host
-I --all-ip-addresses It displays all the configured IP addresses assigned to the host
-s --short It displays the short hostname
-y --yp / --nis It displays the information of NIS domain name

Examples of domainname Command in Linux

This section demonstrates the use of the domainname command in Linux through various examples −

  • Setting the Domain Name
  • Displaying the Domain Name
  • Displaying the Short Hostname
  • Displaying the IP Addresses
  • Displaying the Hostname of FQDN
  • Displaying the DNS Domain Name
  • Display Help Related to domainname Command

Setting the Domain Name

To set the domain name, use the -b or --boot option. You need sudo privileges to set the domain name −

sudo domainname -b nis.example.com

If the domain name is set successfully, then there will be no output.

Displaying the Domain Name

To display the NIS/YP domain name, execute the domainname command without any option −

domainname
Displaying Domain Name 1

If the domain name is not set, the output will be (none).

Another way to display the NIS/YP domain name is using the -y flag or --yp/--nis options

domainname -y
domainname --nis
domainname --yp
Displaying Domain Name 2

Displaying the Short Hostname

The domainname command can display the short hostname as well using the -s flag.

domainname -s
Displaying Short Hostname

Displaying the IP Addresses

To display the IP address of the host, use the -i option −

domainname -i

To display all the configured IP addresses, use the -I option −

domainname -I
Displaying IP Addresses

Note − The -i option resolves IP addresses through DNS, while the -I option lists all the configured IP addresses.

Displaying the Hostname of FQDN

To display the long hostname of a fully qualified domain name, use the -f or --long option −

domainname -f
Displaying Hostname of FQDN

Displaying the DNS Domain Name

To display the DNS domain name, use the -d option −

domainname -d
Displaying DNS Domain Name

Display Help Related to domainname Command

To learn more about the domainname command, execute it with the -h option −

domainname -h

Conclusion

The domainname command in Linux prints the NIS/YP domain name. The NIS/YP domain name is given to the logically grouped systems. The NIS/YP is an outdated protocol and has been replaced by LDAP, FreeIPA, and Samba. However, NIS/YP is still found in older systems.

It can also be set up if the security is not a concern. The domain name of the NIS/YP system can be displayed in the terminal using the domainname command.

Advertisements