added entry to hosts file (ubuntu); can ping ok; cannot nslookup

1

added entry to /etc/hosts

 127.0.0.1    testjd.com

can ping ok

ping testjd.com

PING test.com (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.100 ms

but nslookup (and apache2 config) can't resolve the new name...

nslookup testjd.com
;; connection timed out; no servers could be reached

sudo /etc/init.d/apache2 reload
[error] (EAI 2)Name or service not known: Could not resolve host name > -- ignoring!

note: cat /etc/host.conf

order hosts,bind
multi on

what i ultimately want to achieve is for my apache2 config to be able to resolve the new local name (note: i configured a virtualhost for testjd.com, but i can't get past the "resolve host name" problem shown above)

thanks.

user2897

Posted 2010-02-10T00:08:03.693

Reputation: 185

Answers

3

This is because the nslookup command works with a DNS, and your DNS can't find testjd.com. You can use the host command instead, which will interact with your hosts file.

john@awesome:~$ host localhost
localhost has address 127.0.0.1
localhost has IPv6 address ::1

John T

Posted 2010-02-10T00:08:03.693

Reputation: 149 037

tried "host testjd.com" and also got "no servers could be reached" what i ultimately want to achieve is for my apache2 config to be able to resolve the new local name. thanks. – user2897 – 2010-02-10T00:23:49.053

I think what you want is a VirtualHost: http://httpd.apache.org/docs/2.2/vhosts/examples.html

– John T – 2010-02-10T00:30:22.643

you're right; i already configured the virtualhost for testjd.com (should have been more clear); but that's where my name resolution problems started (which led to trying nslookup; i was thinking that if i fix the nslookup problem, then that'll take care of the apache problem as well)) – user2897 – 2010-02-10T00:33:08.600

Can you post your vhost config? also what is the output of apachectl -t? – John T – 2010-02-10T00:36:08.037

output for apache2ctl -t : "[error] (EAI 2)Name or service not known: Could not resolve host name" --- and finally "Syntax OK" – user2897 – 2010-02-10T02:25:36.920

@openjd sorry for the delayed response, was a little busy. Could you pastebin your entire httpd.conf? – John T – 2010-02-10T04:39:54.223

0

To use both the hosts file and a DNS Server, use getent. For example:

getent ahosts <hostname>


Notes:

  • As John T answered, nslookup will use a DNS server and the /etc/hosts file is not a DNS server
  • DNS configuration can be found in /etc/resolv.conf
  • Name service (including the hosts file) can be found at /etc/nsswitch.conf

Thomas Bratt

Posted 2010-02-10T00:08:03.693

Reputation: 803