hostname -f says "hostname: the specified hostname is invalid". Guess why?
Solution 1
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.
Solution 2
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?
Solution 3
/etc/hostname should only contain the hostname and not a full FQDN.
Solution 4
hostname -f
relies on DNS working.
What does:
host `cat /etc/hostname`
print?
Related videos on Youtube
![Gargaroz](https://i.stack.imgur.com/nV3Yn.jpg?s=256&g=1)
Gargaroz
Updated on September 17, 2022Comments
-
Gargaroz almost 2 years
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.
-
rodjek about 14 yearsWell... what's the contents of /etc/hostname or do we need to guess that too?
-
David about 14 yearsPlease share the contents of your /etc/hostname and /etc/hosts. Maybe the hostname is in fact invalid.
-
-
Admin about 14 yearsclearly not the problem.
-
Gargaroz about 14 yearsTried this. No difference.
-
Gargaroz about 14 yearsAl that's there.
-
user728702 about 13 yearssolved the problem for me, Host \209\149something.sld.tld returned servfail - it looked ok though, osx terminal injecting funny things again ;)