domainname Command in Linux With Examples
Last Updated :
10 Oct, 2024
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 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 the “/etc/hosts” file to map the IP address with the domain name.
Syntax
domainname [options]
Key Options for the domainname Command
1. domainname -h
Displays the help menu with all available options and syntax for the command. This is helpful for beginners who want to explore what the domainname command can do.
domainname -h
2. domainname -a or –alias
It is used to display the alias name. Returns blank line if alias name is not set up.
domainname -a
3. domainname -A or –all-fqdns
It is used to display all the fully qualified domain names (FQDN).
domainname -A
4. domainname -b or –boot
Sets the default domain name if none is available. This option is useful for configuring domain names during the boot process.
domainname -b allinone
In the below example, you can see initially ‘none’ domainname was returned but after setting up command returns the new name.
5. domainname -s or –short
Displays the short version of the hostname (without the domain name).
domainname -s
6. 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
7. domainname -i or –ip-address
Shows all IP addresses assigned to the host. You can use ip -a as an alternative to check IP addresses.
domainname -i
8. 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
Option |
Description |
Command |
-d or --domain |
Displays the domain name of the DNS (Domain Name System). |
domainname -d |
-f or --fqdn or --long |
Displays the long hostname, also known as the Fully Qualified Domain Name (FQDN). This includes both the hostname and the domain name. |
domainname -f |
-F or --file |
Reads the hostname or NIS domain name from a specified file. Useful for automated scripts that require fetching the domain name from a file. |
domainname -F /path/to/file |
Conclusion
The domainname command in Linux is a crucial tool for managing network domain settings. If you’re troubleshooting network issues or configuring domain names for hosts, domainname helps you view and modify the NIS domain names easily. Its wide range of options, including displaying IP addresses, setting default domain names, and listing FQDNs, makes it versatile and essential for system administrators managing Linux systems in networked environments.
domainname Command in Linux – FAQs
What does the domainname command do in Linux?
The domainname command is used to display or set the Network Information System (NIS) domain name of a Linux host. It helps manage domain names associated with the host within a network.
How do I check the domain name of my system using the domainname command?
You can simply run the domainname command without any options to check the domain name of your system:
domainname
What’s the difference between domainname and hostname -d?
Both domainname and hostname -d can be used to display the domain name of the host. However, domainname focuses on the NIS domain, while hostname -d retrieves the domain name directly from the DNS.
How do I display the Fully Qualified Domain Name (FQDN) using the domainname command?
You can use the following command to display the Fully Qualified Domain Name (FQDN):
domainname -f