domainname Command in Linux With Examples

domainname command in Linux is used to return the Network Information System (NIS) domain name of the host. You can use hostname -d command as well to get the host domainname. If the domain name is not set up in your host then the response will be “none”.
In the networking terminology, the domain name is the mapping of IP with the name. Domain names are registered in the DNS server in case of a local network. If the DNS server is not present you can put the entry in /etc/hosts file to map IP address with the domain name.


domainname [options]


  • domainname -h : It is used to display all the options and syntax of the command.
    domainname -h

  • domainname -a or –alias : It is used to display the alias name. Returns blank line if alias name is not set up.
    domainname -a

  • domainname -A or –all-fqdns : It is used to display all the fully qualified domain names (FQDN).
    domainname -A
  • domainname -b or –boot : Used to set default domainname if none available.
    domainname -b allinone

    In the below example, you can see initially ‘none’ domainname was returned but after setting up command returns the new name.

  • domainname -s or –short : Displays the short hostname.
    domainname -s

  • domainname -I or –all-ip-addresses : Used to displays all IP addresses assigned to the host, use ip -a command to check IP addresses.
    domainname -I

  • domainname -i or –ip-address : Displays the localhost address.
    domainname -i

  • domainname -y or –yp or –nis : Displays the Network Information System (NIS) domain name.
    domainname -y

    In this example you can see, the displayed domain name is the same as we set up using -b option.

Other Useful Options:

  • -d, –domain Displays the domain name of DNS.
  • -f, –fqdn, –long Long hostname fully qualified domain name(FQDN).
  • -F, –file Read hostname or NIS domain name from given file.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.