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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.