Jump to content

gethostbyaddr() and /etc/hosts file


WebStyles

Recommended Posts

Hi guys.

 

This is my first question on phpFreaks (the other 900+ posts I've made were always an attempt to help someone else)

 

Here's the issue: when using gethostbyaddr($_SERVER['REMOTE_ADDR']) on a local machine (current using MAMP on OS X) the name returned is not the first entry in my /etc/hosts file.

(On php.net there's another person also commenting on this and saying that apparently gethostbyaddr selects a random entry from the file.)

 

This is not really an issue, since everything will work fine on my FreeBSD production server where each IP address has only one DNS record (I'm building the company's intranet, so I know exactly what's in our DNS tables) but I'm curious to know if anyone has had the same issue/problem and if there's a way around it. (Logic/Common sense tells me the first record should be the one returned)

 

Currently I have the following information in my /etc/hosts file:

127.0.0.1	localhost
127.0.0.1       iSy
255.255.255.255	broadcasthost
::1             localhost 
fe80::1%lo0	localhost
# Other names for testing purposes
127.0.0.1	name1.blablabla.com
127.0.0.1	name2.blablabla.com
127.0.0.1	name3.blablabla.com
127.0.0.1	name4.blablabla.com
127.0.0.1	name5.blablabla.com
127.0.0.1	name6.blablabla.com
127.0.0.1	name7.blablabla.com
127.0.0.1	name8.blablabla.com

 

the value returned is always line 8: name2.blablabla.com. If I comment out that line, then it moves 'randomly' to line 12: name6.blablabla.com and sticks with it even if I shut down the servers and then boot up again.

 

any ideas?

 

cheers.

Link to comment
https://forums.phpfreaks.com/topic/246796-gethostbyaddr-and-etchosts-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.