How can I find the full hostname (FQDN) of the system I am running on?

Answer Posted / chaitanya

Some systems set the hostname to the FQDN and others set it to just the unqualified host name. I know the current BIND FAQ recommends the FQDN, but most Solaris systems, for example, tend to use only the unqualified host name.

Regardless, the way around this is to first get the host's name (perhaps an FQDN, perhaps unaualified). Most systems support the Posix way to do this using uname(), but older BSD systems only provide gethostname(). Call gethostbyname() to find your IP address. Then take the IP address and call gethostbyaddr(). The h_name member of the hostent{} should then be your FQDN.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Are sockets files?

493


How does a socket work?

485


Why does the sockets buffer fill up sooner than expected?

986


How can I write a multi-homed server?

1269


What is af_inet in socket?

468






What is the function of socket?

507


What is sae socket?

430


Can multiple clients connect to same socket?

508


What is a socket set used for?

493


What is a socket connection?

494


Are unix sockets faster than tcp?

488


Whats the difference between select() and poll()?

1203


What is socket address with example?

485


Where is the socket located?

466


What is socket address?

559