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.
- ZIP command in Linux with examples
- look command in Linux with Examples
- ssh command in Linux with Examples
- yes command in Linux with Examples
- fc Command in Linux with Examples
- dir command in Linux with examples
- less command in Linux with Examples
- Cat command in Linux with examples
- dc command in Linux with examples
- rm command in Linux with examples
- which command in Linux with examples
- fmt command in Linux with examples
- until command in Linux with Examples
- gs command in Linux with Examples
- pwd 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 email@example.com. 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.