Support » Fixing WordPress » Database hostname isn’t resolved

  • Resolved henriwahl

    (@henriwahl)


    Hi,

    when setting up a fresh 4.8 instance of WordPress with some external database server I only get a ‘Error establishing a database connection’ message in the browser. If I do not use the database server DNS name but its plain IPv4 address everything works fine.
    Looks like WordPress doesn’t like to ask the system DNS servers, because when I put the IPv4 and database server name into /etc/hosts – it works.
    Any clue?

    Regards

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator Steve Stern

    (@sterndata)

    Looks like WordPress doesn’t like to ask the system DNS servers

    Is the system name for that DB server in your DNS?

    Yes, the DNS has the DB server. WordPress doesn’t even ask the DNS, that’s why I assume there is a bug.

    Moderator Steve Stern

    (@sterndata)

    WordPress calls the normal network stack so if the DB host is resolved in the DNS then it will be used. Are you sure you have it typed correctly in wp-config.php?

    This works:
    /** MySQL hostname */
    define( ‘DB_HOST’, ‘172.16.1.1’ );

    This doesn’t:
    /** MySQL hostname */
    define( ‘DB_HOST’, ‘db.local.net’ );

    At the Terminal:
    root@mariadb-client# host db.local.net
    db.local.net has address 172.16.1.1

    Tcpdumping while trying to access the page just shows there is no attempt to resolve the name:
    root@mariadb-client# tcpdump -i ens160 port 53
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on ens160, link-type EN10MB (Ethernet), capture size 65535 bytes

    Nothing.

    Is there any way, necessity or bug to tell WordPress which DNS server to use?

    Moderator Steve Stern

    (@sterndata)

    Does your web server had contact the right dns server for you local network?

    without db.local.net in your hosts file, what do you see for

    nslookup db.local.net?

    is your local name server in /etc/resolv.conf?

    root@mariadb-client# cat /etc/resolv.conf
    search local.net
    nameserver 172.16.1.2
    nameserver 172.16.1.3

    root@mariadb-client# nslookup db.local.net
    Server: 172.16.1.2
    Address: 172.16.1.2#53

    Name: db.local.net
    Address: 172.16.1.1

    Moderator Steve Stern

    (@sterndata)

    Dang, well, that all looks right. WordPress *should* be using it. Let me consult.

    This is solved now – restarting the Apache server ‘fixed’ it. Way too simple…

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.