I am trying to determine domain name of my network. I tried some programming methods, commands but i could not get domain name of my network.I got ip address using cat /etc/resolv.conf

I was doing program to get domain name but i dont know even where it is actually stored?

Can you tell me location where domain name is stored?

  • Are you after the hostname of your current computer? As in hostname? – Josh Hunt Mar 12 '13 at 9:17
  • 1
    Welcome to Ask Different! Can you make the question a bit easier to answer by adding some more information? Do you have a domain name set at all (and how did you set it), which specific methods have you tried already, what are you intending to do with the domain name once you know it? – nohillside Mar 12 '13 at 9:18
  • @ David Pearce No definitely not.I want the result obtained by domainname command on terminal – PathFinder Mar 12 '13 at 9:39
  • @ patrix♦ I want to know in which network i am working so that i can save domain name and ip address pair for network information database. – PathFinder Mar 12 '13 at 9:43
  • 1
    This is a great example of a question that could be improved by the OP (in this case @PathFinder) from asking "and then what" several times and then editing the question to show the work, what was tried and what you don't get. – bmike Mar 12 '13 at 10:53

Macs don't store configuration information in flat files like most historical UNIX systems do and instead rely on various directory services.

Depending on how you configure the services (and which version of OS you run), the actual storage mechanism and location varies.

What will work is simply making a shell script to dump all the network information you care to document.

 domain name # will dump NIS domain if set
 grep ^search /private/etc/resolv.conf # will list DNS search domains
 grep ^nameserver /private/etc/resolv.conf # will list DNS servers by IP or name

As you see, even though the DNS information is stored in a directory, the OS will automatically generate a flat file in some cases since most programs look for and parse that file.

Should you need a primer on every command likely to be of use in tracking networking, you should run this command and then poke over the tar.gz report that gets saved to your desktop. It is a wealth of diagnostic data and shows how to dump mDNS information better than the manual pages and most written manuals.


Try executing the scutil --dns command.

  • That tool doesn't ship on OS X, however I'd turn my down vote into an up vote if you provided a way to get that command on OS X. – bmike Mar 12 '13 at 10:51
  • 1
    Try executing the scutil --dns command. I'm sorry. I'm new to the AskDifferent. I mainly use Stack Exchange. Just found this question and wanted to provide a hint as it works fine on Linux. Anyway, I'm going to un-register from this site as it's the first site where I got minus mark just for trying to help someone... – Guardian Mar 12 '13 at 11:06
  • 1
    Normally we delete unsourced / unreferenced answers as the system flags them. You could go, but you also could edit it and get a +. As you see, starting at one and getting a minus does nothing other than sort this below other answers. Also - votes are changeable but if one single down vote and a comment showing why the answer isn't useful is all it takes to dampen your spirits, I respect that position. – bmike Mar 12 '13 at 11:09
  • 3
    scutil does ship on the Mac. – Tony Williams Jan 27 '14 at 14:20
  • 1
    scutil ships on mac. Just tried it. – Qix - MONICA WAS MISTREATED Sep 29 '14 at 21:05

The command line utility 'domainname' will give you the NP domainname but this is not definitive.

The 'hostname' command will give you the entire FQDN of your computer and you can then get the domain name out of that by chopping off everything before the first '.' character.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .