hostname --fqdn returns only hostname

General support questions
Post Reply
altiris
Posts: 334
Joined: 2013/05/31 01:27:50

hostname --fqdn returns only hostname

Post by altiris » 2014/04/19 21:03:24

Whenever I issue the command "hostname --fqdn" I only get the hostname of the machine, rather than getting the hostname and domain name. Why is this? I have already edited my hosts file to have "127.0.0.1 my-pc my-pc.mydomain.com my-pc" without the "". I have also put the correct FQDN in /etc/sysconfig/network. Is there something else that I am missing?

User avatar
TrevorH
Site Admin
Posts: 33218
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: hostname --fqdn returns only hostname

Post by TrevorH » 2014/04/19 21:47:23

Yes, your hosts file entry is wrong. It needs the fqdn as the first thing after the ip address.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

altiris
Posts: 334
Joined: 2013/05/31 01:27:50

Re: hostname --fqdn returns only hostname

Post by altiris » 2014/04/20 15:23:39

TrevorH wrote:Yes, your hosts file entry is wrong. It needs the fqdn as the first thing after the ip address.
(Let say my hostname is PC1 and domain name is computer.com)
The first time I tried it like this "127.0.0.1 PC1.computer.com" and when I try the command "hostname --fqdn" I get unknown host. Then I tried "127.0.0.1 PC1.computer.com PC1" and now when I do hostname --fqdn it returns the correct fqdn. Thank you for help, I hope this helps others.

Visolara
Posts: 3
Joined: 2014/04/18 15:58:48

Re: hostname --fqdn returns only hostname

Post by Visolara » 2014/04/22 16:47:55

What do you have listed for your "HOSTNAME" in /etc/sysconfig/network ?

gerald_clark
Posts: 10642
Joined: 2005/08/05 15:19:54
Location: Northern Illinois, USA

Re: hostname --fqdn returns only hostname

Post by gerald_clark » 2014/04/22 17:34:59

If the machine has a static IP address put this address and the FQDN in /etc/hosts, not on the localhost line.

altiris
Posts: 334
Joined: 2013/05/31 01:27:50

Re: hostname --fqdn returns only hostname

Post by altiris » 2014/05/24 23:08:30

gerald_clark wrote:If the machine has a static IP address put this address and the FQDN in /etc/hosts, not on the localhost line.
is it okay if my hosts file also has this (below), or should I comment those out?

Code: Select all

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

User avatar
TrevorH
Site Admin
Posts: 33218
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: hostname --fqdn returns only hostname

Post by TrevorH » 2014/05/25 01:22:50

Those are correct and necessary.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

Post Reply