hostnameand see the name for the system displayed.
# hostname moonpoint
Yet, if I tried entering any option for the command, I received the error message "Name or service not known".
# hostname -a hostname: Name or service not known # hostname -i hostname: Name or service not known # hostname -f hostname: Name or service not known # hostname --fqdn hostname: Name or service not known
The hostname command existed and when I checked the
man page for the
command by issuing the command
man hostname, I saw all of those
options listed as supported arguments to the command - see
hostname man page.
# which hostname /bin/hostname #
I attempted to use strace, a "system call tracer" tool, to check the
command, but found it wasn't present on the system, so I installed it
yum install strace. I then tried
strace hostname --fqdn
, but didn't see the cause of the problem in its output - I stored
the results in
strace -o hostname-fqdn_trace.txt hostname --fqdn. I saw
an IP address in the output; when I checked that IP address I realized it was a
Domain Name System (DNS) server for the system, so thought the system
may have been attempting to look up a
fully qualified domain name (FQDN) for the system, but
perhaps could not.
I had specified the hostname for the system a week ago
using the hostname command, but hadn't
specified a domain name then. I examined the
but there wasn't one specified there.
# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
etc/hosts file on another CentOS system was the same as
the one above, but I could issue the
hostname command there
with the above arguments to the command without the error message appearing,
though whenever I added an option to the command there was a delay in the
$ hostname saturn $ hostname -i fe80::21b:fcff:fe2f:66fd%enp1s4 192.168.0.5 $ hostname -f saturn $ hostname --fqdn saturn$
But I added a line at the end of
/etc/hosts in the form:
serverIPaddress myhostname.mydomain.tld myhostname
Note: "tld" stands for "top-level domain", e.g. .com, .net, .org, etc.
E.g., since I had the domain moonpoint.org pointed to the server I added a line similar to the following one:
192.168.8.5 moonpoint.org moonpoint
Immediately after I did so, all of the options that hadn't worked with the hostname command previously now worked.
# hostname -f moonpoint.org # hostname --fqdn moonpoint.org # hostname -a moonpoint # hostname -i 192.168.8.5 # hostname moonpoint