Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The problem seems to be relatively easy, but I can't find good solution.


I have local DHCP and DNS server running on ADSL router. It assigns IP addresses to local hosts and also keeps DNS records for assigned IPs.

This modem also registers itself via DynDNS services.

Let's assume I have no control over this modem, as it serves several groups.


When I look the host via nslookup it works fine:

$ nslookup vanja

Name:   vanja

but with ping it fails:

$ ping vanja
ping: unknown host vanja

This happens, because ping appends the local domain to the host, but DNS server does not know this domain (and I have no ways to set it), see strace output:

$ strace ping vanja
open("/lib/i686/cmov/", O_RDONLY) = 4
stat64("/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=23, ...}) = 0
connect(4, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("")}, 28) = 0
send(4, "\377N\1\0\0\1\0\0\0\0\0\0\5vanja\10dynalias\3com\0"..., 36, MSG_NOSIGNAL) = 36
recvfrom(4, "\377N\201\203\0\1\0\0\0\1\0\0\5vanja\10dynalias\3com\0"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("")}, [16]) = 97

Also note that nslookup will also fail on the same reason: DNS only maps dynamically assigned IPs to short PC names (which are passed from MS Windows workstations).

When I set the hostname to name without domain (# hostname centurion) ping magically starts working, but I cannot leave hostname not in FQDN form, as otherwise it may confuse apache & postfix or break other things.

Question: How can I make ping working together with having hostname in FQDN form?

Note: My attempts to play with search and domain options of /etc/resolv.conf haven't succeeded. My goal was to force NSS library not to append domain name to the passed argument, or, better, make two tries: without and with domain appended.

Relative settings

$ hostname
$ cat /etc/resolv.conf
$ grep hosts /etc/nsswitch.conf
hosts:          files dns
share|improve this question

migrated from Feb 9 '10 at 18:48

This question came from our site for professional and enthusiast programmers.

Seems like this is a better question for – Jeremy H Feb 9 '10 at 15:37
@Jeremy: Maybe, but I like very much the community and this resource, that's why I would like to contribute also with well-described question :) – dma_k Feb 9 '10 at 18:26
up vote 2 down vote accepted

You may try

search . domainname.ext

to see if just adding the '.' works. Also

$ ping vanja.

would give you some clues.

share|improve this answer
+1 One comment: in order to 'ping vanja.' you don't need to add anything to '/etc/resolv.conf', as you tell explicitly, that you deal with 1st level name. Thanks, that helps. – dma_k Feb 9 '10 at 16:34

Your resolver search path needs to be set.

In /etc/resolv.conf, add the line:

search domainname.ext

(Of course, replace above with your domain name).

This will ensure that ping hostname also looks up hostname.domainname.ext. Note that, you can add multiple domain names to the search path if you want.

share|improve this answer
Sorry, that does not work. The problem is that appending a domain name leads to "host not found". It would be nice, if I could say "search '', 'domainname.ext'" or (my dreams) "search .". I've updated the problem description to state this explicitly, so you can update your reply, if you have a solution, or withdraw it, because it is not solving a problem at all. – dma_k Feb 9 '10 at 14:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .