LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   gethostbyname returns "no address associated with this name" if behind a proxy (http://www.linuxquestions.org/questions/linux-networking-3/gethostbyname-returns-no-address-associated-with-this-name-if-behind-a-proxy-660099/)

iamback 08-03-2008 09:59 AM

gethostbyname returns "no address associated with this name" if behind a proxy
 
Hi,
I'm sitting behind a firewall. I want to know how do I query addresses of websites outside the firewall like "www.yahoo.com" becuase it returns "No address associated with this name" but returns queries ffor internal websites alright.
I think that I'll have to ask my proxy to do that for me but I dont know how to do that. Please help me
Thanks and Regards

Mr. C. 08-03-2008 12:42 PM

Your system's resolver must be configured correctly. You also need access to a forwarding nameserver, or a recursive nameserver and your firewall must allow DNS queries.

The file /etc/resolv.conf specific the nameserver to be used.

iamback 08-03-2008 12:52 PM

Thanks very much.
But I just want to tell that I have no control over these thigns and I dont want a control either. I just want to write a C program that can get me the ip address of a web address outside my domain. e.g. Firefox does this for me even when my /etc/resolv.conf lists only the internal addresses.
thanks

Mr. C. 08-03-2008 01:03 PM

Does dig work correctly to query a hostname?

dig some_external_hostnmame_here

iamback 08-03-2008 08:49 PM

It seems that dig also doesnt answer my requests. Here is a sample output:
$ dig www.yahoo.com
; <<>> DiG 9.3.2 <<>> www.yahoo.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44141
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 0

;; QUESTION SECTION:
;www.yahoo.com. IN A

;; AUTHORITY SECTION:
. 518400 IN NS G.ROOT-SERVERS.NET.
. 518400 IN NS H.ROOT-SERVERS.NET.
. 518400 IN NS I.ROOT-SERVERS.NET.
. 518400 IN NS J.ROOT-SERVERS.NET.
. 518400 IN NS K.ROOT-SERVERS.NET.
. 518400 IN NS L.ROOT-SERVERS.NET.
. 518400 IN NS M.ROOT-SERVERS.NET.
. 518400 IN NS A.ROOT-SERVERS.NET.
. 518400 IN NS B.ROOT-SERVERS.NET.
. 518400 IN NS C.ROOT-SERVERS.NET.
. 518400 IN NS D.ROOT-SERVERS.NET.
. 518400 IN NS E.ROOT-SERVERS.NET.
. 518400 IN NS F.ROOT-SERVERS.NET.

;; Query time: 1 msec
;; SERVER: 172.27.16.1#53(172.27.16.1)
;; WHEN: Mon Aug 4 06:03:03 2008
;; MSG SIZE rcvd: 242


Thanks.

Mr. C. 08-03-2008 09:01 PM

Your system is configured to use the DNS server at 172.27.16.1. If this server will not resolve domains for you, and you cannot configure your system to use another DNS server, then you are out of luck.

Your Firefox is configured to use a proxy server; the proxy server responds to the requests for you.

The gethostbyname() call relies on the system resolver, and hence working DNS to perform the translation. No working DNS means you are out of luck.

iamback 08-04-2008 01:02 AM

Hello, I'm really grateful that you're following my thread. Thanks for all the replies. Can you please tell me how does firefox ask the proxy server to resolve the dns address, I mean what requests does it send to the proxy server. If possible, please give me pointers to write a C-code for that.
Thanks

Mr. C. 08-04-2008 01:28 AM

When you configure your browser to use a proxy, the browser hands the entire URI to the proxy. The browser does not resolve the hostname into an IP address and then pass that to the proxy. The proxy itself then queries DNS as necessary to resolve the name and make the HTTP request.

The entire point of the proxy is that it does the work on behalf of the client, only returning the results. You are thinking of a proxy in an incorrect way. A proxy can only return what it is programmed and configured to return; you can't just decide you want it to give you data it isn't programmed to return.

iamback 08-04-2008 08:24 AM

Mr. C,
Thank you very much for all the info. I'm really grateful to you.
BTW, dont you sleep :) ??

unSpawn 08-04-2008 09:40 AM

Quote:

Originally Posted by iamback (Post 3236133)
BTW, dont you sleep

Bad question. What if he does?... Who's gonna answer your questions then? BTW, you *can* use a proxy to resolve addresses, see for instance 'proxychains' (search Sourceforge). It comes with 'proxyresolv' which works like 'dig' but then through your SOCKS or HTTP proxy. [EDIT] No that you have to of course, anything that can use http://proxyip:proxyport/webhosturi type of URI's or accepts the proxy by configuration (like wget) can help. Depending on what you want to do of course.[/EDIT]

Mr. C. 08-04-2008 03:07 PM

Let's hope proxychains doesn't get iamback fired or booted from his network.

unSpawn 08-04-2008 03:58 PM

Good one. (And kinda weird as well since that's usually my line ;-p)

@iamback: please contact your (network) administrators if you have any doubts about legitimacy of network usage that way.

iamback 08-10-2008 01:23 PM

Thanks for the info. I'll try proxychain and reply.
BTW, thanks for the answers.
Hey unspawn!, I just said that 'sleeping' thing jokingly because I saw a huge time difference in Mr. C's posts :)


All times are GMT -5. The time now is 06:41 PM.