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 -h : It is used to display all the options and syntax of the command.
- domainname -a or –alias : It is used to display the alias name. Returns blank line if alias name is not set up.
- domainname -A or –all-fqdns : It is used to display all the fully qualified domain names (FQDN).
- 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 -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 or –ip-address : Displays the localhost address.
- domainname -y or –yp or –nis : Displays the Network Information System (NIS) domain name.
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.
- yes command in Linux with Examples
- cpp command in Linux with Examples
- man command in Linux with Examples
- ssh command in Linux with Examples
- tac command in Linux with Examples
- cal command in Linux with Examples
- which command in Linux with examples
- cut command in Linux with examples
- atd command in Linux with examples
- cp command in Linux with examples
- cvs command in Linux with Examples
- rcp Command in Linux with examples
- for command in Linux with Examples
- fc Command in Linux with Examples
- help Command in Linux with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.