4

What is the Solaris equivalent of the Linux hostname -f command? On Solaris, when I type hostname, I receive the short name but I need to get the FQDN.

Typing hostname -f sets the short name to be "-f", and the manpage for hostname is pitiful.

user9517
  • 114,104
  • 20
  • 206
  • 289
Matthew
  • 2,666
  • 8
  • 32
  • 50
  • /etc/nodename just lists shortname for the server. The /etc/hostname.* files are all giving me an error when I try to cat them :( – Matthew Nov 18 '11 at 18:48
  • What errors do you get with /etc/hostname.if? If those are corrupted then you have bigger problems. – James O'Gorman Dec 06 '11 at 20:27
  • This question has also been asked before. Here's the previous answer: http://serverfault.com/questions/229706/on-solaris-what-is-a-terse-way-to-get-the-fully-qualified-domain-name-fqdn-fo – scottm32768 Mar 20 '13 at 02:02

3 Answers3

2

This is likely to work:

perl -mNet::Domain -e 'print Net::Domain::hostfqdn(), "\n"'

but it's not guaranteed. You can view the module source:

perldoc -m Net::Domain

to see how it works (if you know Perl well enough).

Keith Thompson
  • 510
  • 2
  • 9
2

If you are on a system that the DNS knows about, you could try this:

bash-3.00# nslookup `hostname` | grep 'Name:' | awk '{print $2}'
ep60.bar.foo.com

or, as suggested by a commenter, use "host" instead of nslookup:

host $(hostname) | cut -d" " -f1

I tested this successfully on Linux, Solaris, AIX, and HP-UX.

Foo
  • 163
  • 4
  • `nslookup` has been deprecated for a long time. `host` or `dig` are preferred and would involve fewer pipes: `host $(hostname) | cut -d" " -f1` – James O'Gorman Dec 06 '11 at 20:26
  • @JamesO'Gorman `nslookup` is part of the POSIX standard, only a hairbrain OS wouldn't include it these days. – Chris S Mar 20 '13 at 04:04
  • @ChrisS True, and `nslookup` generally still comes with `host` and `dig` in the BIND utilities package (OS/distro dependent) but the output from `dig` is BIND zonefile-compatible and `host` is slightly easier to parse, therefore I'd say it's better to use `host` or `dig` _if you can_. – James O'Gorman Mar 21 '13 at 09:03
2
check-hostname | awk '{ print $NF }'
longneck
  • 22,793
  • 4
  • 50
  • 84
ealgumby
  • 21
  • 1