Software & Apps Linux Everything You Need to Know About the 'Domainname' Command A computer's host name serves several purposes by Gary Newell Writer Gary Newell was a freelance contributor, application developer, and software tester with 20+ years in IT, working on Linux, UNIX, and Windows. our editorial process Gary Newell Updated on December 03, 2020 Linux Switching from Windows Tweet Share Email Several related commands expose or modify the hostname of your computer. They are standard commands that should work regardless of your Linux distribution. The 'hostname' Command Every computer has a hostname, and your computer's hostname is likely to have been set up when you first installed Linux. Discover your computer's hostname by running the following command in a terminal window: On some machines, your hostname may show up as something like computername.computerdomain. The hostname is basically used to identify your computer on a network and the domain that it belongs to. You can get just the computer name returned by running the following command: Alternatively, see just the domain name by running this command: Some Linux shells include the hostname as part of the shell prompt. The 'domainname' Command Instead of using the hostname with the -d switch to return the domain name, run the following command: If you have a domain set up it will be returned otherwise you will see the text (none). In many cases, especially when you're not otherwise networked, you may see localdomain instead. The domainname command returns the NIS domain name of the system. NIS stands for Network Information System. NIS is a Remote Procedure Call-based client/server system that allows a group of machines within a NIS domain to share a common set of configuration files. This arrangement permits a system administrator to set up NIS client systems with only minimal configuration data and to add, remove, or modify configuration data from a single location. The dnsdomainname Command The dnsdomainname command returns the DNS domain name. Run it by typing the following into the terminal: d DNS stands for Domain Name Server and it is used by the internet to convert IP addresses to real domain names. Without domain names, we would all be using large spreadsheets to work out that 207.241.148.82 will take us to linux.lifewire.com. Unless you are running a web server, your computer will not have a DNS domain name and running the dnsdomainname command will return either nothing or the localhost. Setting the NIS Domain Name Set a NIS domain name for your computer using the following command: dnsdoma You probably need sudo to elevate your permissions. The /etc/hosts File In a terminal window run the following command to open the hosts file in the Nano editor: sudo nan You'll see several lines of text in the /etc/hosts file as shown above: The first part is the IP address of the computer, the second part is the computer name. To permanently add a NIS domain for the computer change the line as follows: doma You can also add aliases as follows: d More About the 'domainname' Command The domainname command offers several switches, including: -a: Returns the aliases for the domain listed in the hosts file-b: Sets a domain name-d: DNS domain name-f: Long host name-F: Read the host name information from a file-i: IP addresses for the host name-I: All addresses for the host-s: Short host name Was this page helpful? Thanks for letting us know! Get the Latest Tech News Delivered Every Day Email Address Sign up There was an error. Please try again. You're in! Thanks for signing up. There was an error. Please try again. Thank you for signing up. Tell us why! Other Not enough details Hard to understand Submit