3

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?

Thomas L Holaday
  • 1,353
  • 4
  • 16
  • 19

3 Answers3

2

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 foo.your.domain.com > /etc/nodename

You might also be able to use:

getent hosts `hostname` | cut -f 3

or similar.

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
2

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.

user9517
  • 115,471
  • 20
  • 215
  • 297
2

Would two digs be better than one?

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

Just be mindful of the trailing dot.

raubvogel
  • 46
  • 1