Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I want the fully qualified domain name on Linux, I can write ...

hostname --fqdn

To get the same thing on Solaris, is it necessary to write ...

cut -f 2-3 /etc/hosts | grep ^`hostname`\t | cut -f 2

... or is there something more brief?

share|improve this question
up vote 2 down vote accepted

From here:

The hostname command should return an FQDN...
The solution is to edit /etc/nodename and put the FQDN in there and reboot.

    echo > /etc/nodename

You might also be able to use:

getent hosts `hostname` | cut -f 3

or similar.

share|improve this answer
Will "getent hosts | cut -f 3" depend on the layout of /etc/hosts ? – Thomas L Holaday Feb 1 '11 at 17:12
@Thomas: Yes. That command retrieves the same field as your command. You could try to use a sed or AWK command to be more flexible and selective. – Dennis Williamson Feb 1 '11 at 18:01

Your method depends upon the /etc/hosts file being formatted in a particular way, on a S10 system I have to hand it returns loghost which is incorrect.

If set up you can ask the DNS system with

dig -x your.ip.add.ress +short

or if you are using NIS then

echo `hostname`.`domainname`

or you could setup /etc/nodename as Dennis suggests.

share|improve this answer

Would two digs be better than one?

dig -x `dig +short "$(hostname)"` +short

Just be mindful of the trailing dot.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.