Question

If I ask gethostbyaddr() to look up a NAT-generated IP address, such as 192.168.0.4, should I expect it to work?

Background: I'm running tests at home on some control code intended for a networked environment. At times, this code does a gethostbyaddr() call to get details of the machine that sent it a message. The address will often be that of a local machine, and at times even turns out to be the address of the current machine itself. Normally, this causes no problems. However, I have replaced my old Netcomm ADSL router by a Netgear router, and discovered that a gethostbyaddr() call for a machine in the local NAT environment now a) times out after 30 seconds, b) returns NULL to indicate an error. Experimentally going back to my old router, I find that the same call also fails, returning NULL, but does so immediately. The code can handle the error return (which is why I'd never noticed this before), but the new 30-sec timeout is a huge nuisance. Obviously, there are a host of ways to code around this problem, but most involve trapping the case where the address is a 192.168 address and avoiding the gethostbyaddr() call. My question is, does a gethostbyaddr() call always fail in a NAT environment, or are there cases where it will work? (In which case I don't want to end up avoiding them.) Or is it just that I've not set up my routers properly? By the way, I'm running this on OS X, and see the same behaviour on both Snow Leopard and Lion.

Was it helpful?

Solution

They won't work unless you setup private dns or add them to your hosts file. Sendmail provides some good documentation on this:

http://www.sendmail.com/sm/open_source/tips/private_dns/

The calls that end up reaching the root name servers get blackholed.

Some routers might already provide the reverse DNS. You don't need to have every host in there, just be authoritative for the address space so the request doesn't get forwarded.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top