Linux – How to get a linux terminal to show me the DNS domain suffix of a machine

linuxUbuntu

I am trying to make a script that will ping an IP address and tell you the name of the server it is pinging.

It works….mostly

I cannot seem to figure out how to make Linux (Ubuntu more specifically) to display the dns domain suffix that is set inside of the "resolv.conf" file.

if I type "hostname" at a command prompt all I get is "ubuntu01"

I tried typing domainname and all I get is the output "(none)" which is confusing me considering I can type the hsotname of any computer on my network and it will append the DNS suffix of "solignis.local" to it just like it is supposed to.

Any ideas?

Best Answer

hostname provides this functionality:

$ hostname -d

If you are getting (none) then the domain may not be set, there is also the -y switch for the NIS/YP domain name.