[erlang-questions] {error,timeout} with gethostbyname

info info@REDACTED
Fri Sep 25 15:46:01 CEST 2009


On Fri, Sep 25, 2009 at 03:16:41PM +0200, info wrote:
> On Fri, Sep 25, 2009 at 12:03:38PM +0200, info wrote:
>  > Hi Raimo,
>  > Note that I appreciate your help because it seems that the problem is not in erlang.
>  > 
>  > On Thu, Sep 24, 2009 at 04:55:57PM +0200, info wrote:
>  >   > I also tried to add the address of my dns server.
>  >   > inet_db:add_ns({ip}).
>  >   > But no effect.
>  >   > 
>  >   > inet_getrc(). gives now:
>  >   > 
>  >   > [{host,{127,0,0,1},["my_host"]},
>  >   >  {nameserver,{192,168,1,33}}]
>  >   > 
>  > You have {res_lookup,[native,file]} meaning first is the OS
>  > gethostbyname equivalent function used. During the startup
>  > of Erlang it discovered that "my_host" could not be
>  > resolved so it entered "my_host" as {127,0,0,1} into the
>  > internal hosts table to ensure that inet:gethostbyname("my_host")
>  > would succeed.
>  > 
>  > But the native lookup method times out, probably due
>  > to misconfigured name resolving in the OS, so the
>  > internal hosts table is never used.
>  > 
>  > How long does the call inet:gethostbyname("my_host")
>  > take to return {error,timeout}?
>  >   >  >  >  >  >  >  >  >  >  >  >  > 6-7 seconds
> 
> Ok...
> 
>  > 
>  > Can the native lookup method look up any name at all?
>  > Try: inet_gethost_native:gethostbyname("localhost").
>  >   >  >  >  >  >  >  >  >  >  >  >  > {error,timeout}
>  > inet_gethost_native:gethostbyname("my_host").
>  >   >  >  >  >  >  >  >  >  >  >  >  > {error,timeout}
>  > inet_gethost_native:gethostbyname("www.google.com").
>  >   >  >  >  >  >  >  >  >  >  >  >  > {error,timeout}
> 
> Nothing worked.
> 
>  >   >From a Windows command shell, try:
>  > nslookup my_host
>  >   >  >  >  >  >  >  >  >  >  >  >  >server: my_host.my_domain.local
>  >   >  >  >  >  >  >  >  >  >  >  >  >address: 192.168.1.33
>  >   >  >  >  >  >  >  >  >  >  >  >  >name: my_host.my_domain.local
>  >   >  >  >  >  >  >  >  >  >  >  >  >address: 192.168.1.33
>  > nslookup localhost
>  >   >  >  >  >  >  >  >  >  >  >  >  >server: my_host.my_domain.local
>  >   >  >  >  >  >  >  >  >  >  >  >  >address: 192.168.1.33
>  >   >  >  >  >  >  >  >  >  >  >  >  >my_host.my_domain.local doesn't find localhost: no existing domain (*** I translated from french ! )
> 
> Well well, of course that worked...
> This means your host is its own DNS server (?).
> 
>  > 
>  > Pay special attention to which nameserver that answers.
>  > 
>  > If you can not fix the network configuration, which will
>  > solve your problem, you can configure erlang to not
>  > use the native lookup method. The erlang DNS resolver
>  > client was much improved to R13B02, but it worked
>  > well in R13B01 too.
>  >   >  >  >  >  >  >  >  >  >  >  >  >My problem is I don't see what is wrong in my network configuration or in my dns server configuration !
>  > Set the lookup method to [file,dns] and add your
>  > nameserver as you tried:
>  > inet_db:add_ns({192,168,1,33}).
>  >   >  >  >  >  >  >  >  >  >  >  >  >ok
>  > inet_db:set_lookup([file,dns]).
>  >   >  >  >  >  >  >  >  >  >  >  >  >ok
>  > Then try inet:gethostbyname("my_host"),
>  >   >  >  >  >  >  >  >  >  >  >  >  >{ok,{hostent,"my-host",[],inet,4,[{127,0,0,1}]}}             BETTER !!
> 
> That is the patched 'file' lookup method that found the name.
> This is often enough to run a local non-distributed node.
> 
>  > or even inet_res:gethostbyname("my_host).
>  >   >  >  >  >  >  >  >  >  >  >  >  >{error,timeout}                         WHY ?
> 
> Maybe your firewall does not allow DNS requests from erlang.
> Try:
> rr(inet_res).
> +++++++
> [connect_opts,dns_header,dns_query,dns_rec,dns_rr,hostent,
>  listen_opts,sctp_opts,udp_opts]
> 
> inet_res:nslookup("my_host.my_domain.local", in, a, [{{192,168,1,33},53}]).
> +++++++
> {ok,#dns_rec{header = #dns_header{id = 2,qr = 1,opcode = 0,
>                                   aa = 1,tc = 0,rd = 1,ra = 1,pr = 0,
>                                   rcode = 0},
>              qdlist = [#dns_query{domain = "my_host.my_domain.local",
>                                   type = a,class = in}],
>              anlist = [#dns_rr{domain = "my_host.my_domain.local",class = in,
>                                type = a,cnt = 0,tm = undefined,ttl = 3600,
>                                bm = [],
>                                data = {192,168,1,33},
>                                func = false}],
>              nslist = [],arlist = []}}
> 
> 
> And, maybe using the external IP address is what is not allowed.
> inet_res:nslookup("my_host.my_domain.local", in, a, [{{127,0,0,1},53}]).
> +++++++++
> {ok,#dns_rec{header = #dns_header{id = 3,qr = 1,opcode = 0,
>                                   aa = 1,tc = 0,rd = 1,ra = 1,pr = 0,
>                                   rcode = 0},
>              qdlist = [#dns_query{domain = "my_host.my_domain.local",
>                                   type = a,class = in}],
>              anlist = [#dns_rr{domain = "my_host.my_domain.local",class = in,
>                                type = a,cnt = 0,tm = undefined,ttl = 3600,
>                                bm = [],
>                                data = {192,168,1,33},
>                                func = false}],
>              nslist = [],arlist = []}}
> +++++++++++++
>  inet_gethost_native:gethostbyname("www.google.com").                
> {error,timeout}
> inet_gethost_native:gethostbyname("localhost").                     
> {error,timeout}
> inet_gethost_native:gethostbyname("my_host").                      
> {error,timeout}
> 
> DO YOU SEE A DIFFERENCE ?

Nope.

This means that:
inet_db:add_ns({127,0,0,1}).
inet_db:set_domain("my_domain.local").
inet_db:add_search("my_domain.local").
inet_db:set_lookup([file,dns]).
should make inet:gethostbyname("my_host") work.
*******
Correct:
inet:gethostbyname("my_host").
{ok,{hostent,"my_host",[],inet,4,[{127,0,0,1}]}}


But that is a workaround. The native lookup should work.
Windows nslookup also probably bypasses the normal
name resolving functions and does direct DNS queries.

Is it maybe an issue with your DHCP server that i does
not state a DNS server, 
******
Client DNS service and Client DHCP service are running.
since you use your local
machine as DNS server. 
******
Exactly: but it is not forbidden ? Normally I should not use a server to access to the web with a browser ... but it is another story.

Google for name resolving for
Windows 2003...
******
I already past long times on Google ...

> 
>  > But I hope you can fix your network configuration instead...
>  > 
>  >   > 
>  >   > 
>  >   > n Wed, Sep 23, 2009 at 04:31:35PM +0200, info wrote:
>  >   >    > Hi all,
>  >   >    > On a windows 2003 server sbs this command returns {ok,"my_host"} :
>  >   >    > 
>  >   >    > {ok,N}=inet:gethostname().
>  >   >    > 
>  >   >    > But the following command returns {error,timeout} :
>  >   >    > 
>  >   >    > inet:gethostbyname(N).
>  >   >    > 
>  >   >    > On a Vista machine, the previous command returns a correct answer.
>  >   >    > 
>  >   >    > I know that it is not an erlang problem but if you could give me support, I will appreciate ;-)
>  >   > 
>  >   > Erlang may have problems configuring name lookups.
>  >   > Give me the output from ets:tab2list(inet_db).
>  >   > 
>  >   > Which erlang release are you running, it sounds like pre-R13B02?
>  >   > 
>  >   > Try starting with erl -name foo
>  >   > and do the same, ets:tab2list/1 too.
>  >   > 
>  >   > -- 
>  >   > 
>  >   > / Raimo Niskanen, Erlang/OTP, Ericsson AB
>  > 
>  > -- 
>  > 
>  > / Raimo Niskanen, Erlang/OTP, Ericsson AB
> 
> -- 
> 
> / Raimo Niskanen, Erlang/OTP, Ericsson AB

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB


More information about the erlang-questions mailing list