In this article, we are going to introduce 5 Linux commands that are essential for your everyday operation. They include:
The hostname Command
All computers have a specific hostname. It’s very likely that the hostname of your computer was set up when you installed Linux.
To find out your hostname, open a terminal window and run the command: “hostname”.
When I did, my result was “emmossad”.
Your hostname may show up as “computername.computername”. Don’t panic if it does, you’re on the right track.
Hostnames are used for identification of computers on a network and locating the domain where it belongs.
If you want to find out only the computer’s name, run this command: “hostname-s”.
For just the domain name, run the command: “hostname-d”.
The domainname Command
The domainname command allows you to get the domain name directly without using a modification of the hostname command (hostname-d).
Run the following command to get the domain name: “domainname”.
Your domain name will be returned if you have one set up otherwise you will get the response: “none”.
The domain name returned by the domanainname command is more appropriately called the Network Information System (NIS) domain name.
The Freebsd guide defines NIS as a Remote Procedure Call-based server/client system that permits computers within the same NIS domain to share similar configuration files, allowing an administrator to set up an NIS client system easily. An administrator would only need to add, remove or/and modify the configuration data from a single location.
The ypdomainname Command
The ypdomainname and domainname commands return the same result. To execute the command, open a terminal and enter the command: ypdomainname.
The reason both commands return the same result is that YP stands for yellow pages but the name “yellow pages” was changed to NIS for legal reasons.
Of course, you can still use ypdomaainname command if you prefer but domainaname is shorter and will give you the same result.
The nisdomainname Command
The nsidomainname returns the same result as the ypdomainname and the domainname command. As already explained above, network system information replaced yellow pages for legal reasons and that is how the nsidomaainname command came about. This was further changed to just domainname to avoid ambiguity.
To execute the command, open a terminal and key in the command: “nsidomainname”.
You will get the same result.
The dnsdomainname Command
Domain name Servers (DNS) converts IP addresses to the actual domain name. Whenever you key in a domain name into your address bar, it’s the DNS that converts the letters into numbers (IP addresses) that a computer can understand.
For example, whenever you type in “facebook.com”, the DNS converts it into 220.127.116.11 that the internet understands. Without DNS, we would all need spreadsheets to work out the actual IP address that a domain name represents.
The dnsdomain command displays your web server DNS domain name. Open a terminal and enter the command: dnsdomainname.
“If you have a web server running on your domain name, the DNS information will be displayed. If not, you will get absolutely nothing” - Brendan at Umbrellar Cloud Hosting
Setting the NIS Domain Name
To set up your computer’s NIS domain name, enter the command below:
sudo domainname myselecteddomainname
Replace “myselecteddomainname” with a name of your choice.
You may need sudo to gain access to higher permissions.
Nsidomainname and ypdomainname commands can be used to set up your domain name also. All you need to do is to replace “domainname” in the above command with nsidomainname and ypdomainname respectively:
sudo ypdomainname myselecteddomainname
sudo nisdomainname myselecteddomainname
Opening /etc/hosts File
Open a terminal and enter the command “sudo nano/etc/hosts” and the host file will open in the nano editor.
The /etc/hosts files will display the following lines of texts:
Your computer IP address is the number displayed above, while the other part of the text is your computer name.
An NIS domain name can be added permanently by changing the line of text as follows:
You can add aliases if you choose as follow:
127.0.0.1 localhost.yourselecteddomainname mycomputer mylinuxsupercomputer
More on domainname Command
In addition to the previous commands, the domainname commands have the following switches:
This command will display all the aliases listed for the domain
This will display the domain name to be used if no other has been set.
If you’ve not set the domain name to be used if no other is available, you can do so with the command below:
Other commands include:
domainname -d – to display the DNS domain name
domainname -F - to display the host name from the file
domainname -f – to display the Long host name
domainname -I - All addresses for the host
domainname -i – to display IP addresses for the host name
domainname -s – to display the short host name
domainname -y – to display NIS/YP domain name
The above commands will enable you use the domainname command effectively in Linux.