6

hostname -f says "hostname: the specified hostname is invalid". The hostname (FQDN) specified in /etc/hostname is also listed in /etc/hosts and is pingable. No actual DNS server yet of the host knows. Is this a reason of the error reported or something else? (the OS is Ubuntu 10.04 Server).

Update: registering the host at a DNS server (so that the name can be successfully resolved via Internet) did not help.

Ivan
  • 3,398
  • 19
  • 50
  • 71
  • 1
    Well... what's the contents of /etc/hostname or do we need to guess that too? – rodjek Jun 29 '10 at 05:06
  • Please share the contents of your /etc/hostname and /etc/hosts. Maybe the hostname is in fact invalid. – David Jun 30 '10 at 07:34

5 Answers5

14

From this thread on Ubuntu Forums.

Apparently the underscore is an illegal character for hostnames. I had one in my hostname, and it gave me your failure message. Maybe you're getting something similar.

user128952
  • 141
  • 1
  • 2
3

Check the configuration of:

/etc/host.conf
/etc/nsswitch.conf

host.conf should have "order hosts, bind" and nsswitch.conf should have "hosts: files dns" at a minimum. Possibly you've got something out of whack that's searching only DNS and not your local files?

1

/etc/hostname should only contain the hostname and not a full FQDN.

Florian Diesch
  • 1,794
  • 1
  • 11
  • 5
1

hostname -f relies on DNS working.

What does:

host `cat /etc/hostname`

print?

Mikel
  • 3,867
  • 2
  • 20
  • 16
0

You can edit your hostname at /etc/hostname or directly from the CLI like this:

echo "<desired_hostname>" > /etc/hostname hostname -F /etc/hostname

For systems that support it (such as Ubuntu 18.04+), you can also use hostnamectl like this:

hostnamectl set-hostname <desired_hostname>

Then reboot or login/logout and you should see the latest hostname, regardless of illegal characters like underscores.

Blairg23
  • 101
  • 3