10

I'm using Ubuntu 10.04 LTS, and when I type the command hostname --fqdn, I get the message: hostname: Name or service not known.

Because of this, I cannot install global successfully, and get the following error when I try:

Setting up global (5.7.1-1) ...
hostname: Name or service not known
dpkg: error processing global (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 global
E: Sub-process /usr/bin/dpkg returned an error code (1)

My /etc/nsswitch.conf is below.

# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd:         compat
group:          compat
shadow:         compat

hosts:          files dns
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

Does anyone have any ideas on what this means and how I can fix this?

  • 1
    Why do you want a FQDN? If you have to ask, you probably don't want one or can't make use of one or both. – msw Jul 8 '10 at 0:00
11

Can you provide the content of /etc/nsswitch.conf ?

It looks like /etc/nsswitch.conf has a bad value for the "hosts" line. Does it start with "files" ?

Otherwise the FQDN is set by editing /etc/hosts and putting the FQDN on the line where the hostname appears. Suppose you have an hostname "foo", and you find a line:

127.0.0.1 foo

You would edit it like this:

127.0.0.1 foo.localdomain foo

foo.localdomain would be your new FQDN.

  • I have included the contents of that file as you asked! THANKS for the reply!! :) – RadiantHex Jul 8 '10 at 9:17
  • @Rapael I changed the /etc/hosts file but it started giving me Temporary failure in name resolution. Any ideas why its happening? – Muhammad Adeel Zahid Mar 6 '17 at 17:21
6

edit /etc/hosts to add your FQDN

Information on syntax located here: http://www.faqs.org/docs/securing/chap9sec95.html

update: reading over your question again it almost sounds like you either don't have your path set right, or there is something wrong with the hostname program.

do 'which hostname'

it should return with the path '/bin/hostname'

if that works try the command again like,

'/bin/hostname --fqdn'

  • Thanks!!! Sorry if I ask this, but how do I find out my FQDN? – RadiantHex Jul 7 '10 at 23:07
  • 1
    well this stands for 'Fully Qualified Domain Name' superuser.com is a FQDN. If you own a domain, you could use it, otherwise you can just make up something if you are on an internal network. – Mudfly Jul 7 '10 at 23:11
  • 1
    Thanks @Mudfly! I tried your instructions, the last commands returns "hostname: Name or service not known" again! – RadiantHex Jul 7 '10 at 23:12
  • Without more info its hard to know the conditions of your problem. EG: is this a local install, are you logged in over ssh, are you using a user account or logged in root? You might want to visit ubuntuforums.org and search for others who have solved similar issues. – Mudfly Jul 7 '10 at 23:23
  • 1
    This is taking a wild jump here but, Ubuntu favors using sudo over the use of root. It is quite possible that the shell isnt setup correctly. To test this is very simple. First you can do 'ls -al /root/' and see if you can see a .bashrc Second if you don't have a .bashrc copy it from skel 'cp /etc/skel/.bashrc ./' you can do this even if you already have the file. Third do '/bin/bash' to make sure you are running bash. Finally try your original command again, you should be running in a fully configured bash shell. – Mudfly Jul 7 '10 at 23:42
0

Unlike the simple hostname command invocation, the invocation hostname --fqdn will attempt to do a few more things, which will often result in some DNS lookups.

Take for example the following (successful) invocation (this is from a Red Hat box, but I would imagine it should be the same for Ubuntu):

# hostname --fqdn --verbose
gethostname()=`myserver.example.com'
Resolving `myserver.example.com' ...
Result: h_name=`myserver.example.com'
Result: h_addr_list=`10.1.2.3'
myserver.example.com

Note the very helpful --verbose option.

In short, anything other than a simple hostname is probably doing more than you expect. Here's another example:

# hostname --ip --verbose
gethostname()=`myserver.example.com'
Resolving `myserver.example.com' ...
Result: h_name=`myserver.example.com'
Result: h_addr_list=`10.1.2.3'
10.1.2.3

And to round it off:

# hostname --verbose
gethostname()=`myserver.example.com'
myserver.example.com

Note that the hostname of a system (as returned by gethostname) can me an unqualified hostname, such as just 'myserver'. This is why the program you are wanting to install is using the hostname --fqdn instead.

The error message hostname: Name or service not known comes from the resolver functions: these are the parts of the system library that translate between names and addresses (typically DNS names and IP addresses).

Actually, the resolver does more than just DNS (and more than just translating between hostnames and IP addresses); its behaviour is configured in part by the file /etc/nsswitch.conf, and typically it will consult the following, typically in this order:

  • 'hosts' (on Linux, the means /etc/hosts)
  • (sometimes) nscd (name-service caching daemon)
  • 'dns'

(note, you can also have a caching DNS server such as dnsmasqd --- for the point of the above, that is still under the 'dns' mechanism).

It is worth pointing out that tools such as dig, host and the venerable nslookup do not follow this order; they are explicitly DNS querying tools. This means that if you rely on them (in a script for example) you may end up getting a different result than what regular client programs would (that use the system resolver). For this reason, use the getent program in scripts, particularly if you have a caching component such as nscd running.

# getent hosts myserver.example.com
10.1.2.3    myserver.example.com

So the key takeaway here is that a) if you have /etc/hosts well configured with an entry for your own machine, and b) your /etc/nsswitch.conf has the usual configuration -- hosts: files dns in that order, then c) even if you don't have DNS well-configured in your environment, then hostname --fqdn should work.

In a well-configured DNS, you would be expected to have one 'reverse' address (a "PTR record") that gives the 'canonical' name of your server, and that name should also be able to be looked up (an "A record" for IPv4).

Short version: add --verbose; it will point you to what you are lacking.

Hope that helps you to understand what is going on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.