Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

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
share|improve this answer
    
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 Feb 10 '10 at 0:23
    
I think what you want is a VirtualHost: httpd.apache.org/docs/2.2/vhosts/examples.html –  John T Feb 10 '10 at 0:30
    
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 Feb 10 '10 at 0:33
    
Can you post your vhost config? also what is the output of apachectl -t? –  John T Feb 10 '10 at 0:36
    
output for apache2ctl -t : "[error] (EAI 2)Name or service not known: Could not resolve host name" --- and finally "Syntax OK" –  user2897 Feb 10 '10 at 2:25
show 1 more comment

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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