Search code examples
mysqlnetwork-programminghostnamedig

Issue in remote db connection , probably in resolving host name ip


I am trying to connect to a remote db on '1and1' and through Php mysqli I receive this error:

php_network_getaddresses: getaddrinfo failed: Name or service not known

also trying to connect via ssh I have this error:

ssh: Could not resolve hostname db661101787.db.1and1.com: Name or service not known

I tried with DIG command in shell and the response I receive is:

; <<>> DiG 9.10.3-P4-Ubuntu <<>> db661101787.db.1and1.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 15841
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;db661101787.db.1and1.com.  IN  A

;; AUTHORITY SECTION:
1and1.com.      329 IN  SOA rns.ui-dns.de. dnsadmin.1und1.de. 2013087505 10800 3600 604800 600

 ;; Query time: 61 msec
 ;; SERVER: 127.0.1.1#53(127.0.1.1)
 ;; WHEN: Mon Apr 03 22:47:32 CEST 2017
 ;; MSG SIZE  rcvd: 117

I really don't have idea which could be the problem.


Solution

  • That hostname doesn't exist, at least not on the public internet. It's possible that your provider has special internal DNS servers that do provide answers, Amazon EC2 works this way, so if that's the case you must use those servers.

    If you're trying to access this database server from outside your provider's local network that may not work. It's a best practice to never expose MySQL to the public internet, the risks are too high.