简体   繁体   中英

PHP not remembering the IP address of a domain name

System:

  • CentOS 7
  • PHP-FPM 7.1

Issue:

  • PHP resolves local domain name only if it is set for the DHCP server as static address
  • The server won't have any connection in the future to the DHCP server, thus it is unable to resolve the IP address of the domain name.

Tried:

  • Tried to test if it remembers the ip address if I remove it from the DHCP server (but it still has direct connection to the other server)
  • gethostbyname("mylocal.example.com"); comes back with the domain name itself as result
  • The domain name is added to the /etc/hosts file. Restarted network since then a few times.

Question:

  • How can I burn in PHP to lookup a specific domain name on an specific IP address?

The same domain name is returned by gethostbyname function only when its not able to resolve that host.

To resolve a non-existent domain name from host file add a trailing dot to the domain name. Eg gethostbyname(“mydomain.com.”);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM