0

I want to connect to a Google cloud SQL instance using its free IPv6 address instead of buying an IPv4 address. For that I looked up my IPv6 address and allowed it. I also looked up my routers IPv6 prefix and allowed that (afaik that should allow all pc in my home network to access the SQL instance).

The following code creates the problem:

$servername = "2001:6532:1234:1:6a4f:e1d7:5d69:52a3";
$username = "looooool";
$password = "superSecretStuff";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

And that code generates this error:

Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: Der angegebene Host ist unbekannt. in C:\Users\kjh\Documents\SF WEBSITE\appengine-try-php-master\connect_db.php on line 8

Warning: mysqli::mysqli(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Der angegebene Host ist unbekannt. in C:\Users\kjh\Documents\SF WEBSITE\appengine-try-php-master\connect_db.php on line 8
Connection failed: php_network_getaddresses: getaddrinfo failed: Der angegebene Host ist unbekannt.

I'm sorry that the error message is in German, but I don't know where I would even change that. Also line 8 is the line with $conn = new mysqli($servername, $username, $password, $dbname); on it. I've changed the IP adress so if it looks weird that is why. Hope you can help me.

If I get an IPv4 adress from Google it works without any problems.

This is a repost from here where I was told to reask it here, because it could be a problem with my ISP not assigning a persistent IPv6 address.

After I just wanted to look up my IPv6 address I noticed somethin strange. I went to wieistmeineip.de to look up my IPv6 address and at first it only showed my IPv6 address, then when I went to the speedtest my IPv6 address vanished, and I only have an IPv4 address since then. At least that is what all the ip address sites say. Also the same happend with google when you google "what is my ip address" google shows you your ip address, at first it showed my ipv6 and now it only shows ipv4.

My ISP: Kabel Deutschland

Now finnally my two questions:

  1. Should the code above work given that I permitted my IPv6 address to access the cloud sql and that my ISP is not screwing me up?

  2. Is there some way I could check if my ISP is doing something strange?

Update:

I tried to disable IPv4 completely on my machine (Windows) so I did that and restarted my computer. After the restart I did not get an IPv6 address from my router so I enabled IPv4 again, and I got an IPv4 address but no IPv6 address. I hope that helps.

usbpc102
  • 121
  • 4
  • Please try http://myip.addr.space/ as I built this to detect users' IPv4 and IPv6 addresses properly in most circumstances. The result it gives may shed some light on your situation. – Michael Hampton Nov 28 '15 at 19:13
  • This error »Der angegebene Host ist unbekannt« means Unknown host. So it _suggests_ that PHP has not recognized your host as a valid IP address and is attempting to treat it as a hostname. Are you sure you have entered the IPv6 address correctly _in your PHP code_? The one shown in your question doesn't appear to be valid. – Michael Hampton Nov 28 '15 at 19:19
  • Well, now I have an IPv6 address again... It is diffrent from the address I had befor so I added it to the allowed IPs with Cloud SQL, but I get the same error again. – usbpc102 Nov 28 '15 at 19:20
  • Yes I have used the correct IPv6 address in my code, I just changed it here to not make it public. But that it does not see that as a valid host is confusing me aswell because I'm wondering if the syntax for IPv6 is diffrent. – usbpc102 Nov 28 '15 at 19:23
  • If there's a question about PHP syntax you probably should go back to [so], because we don't really know about that here :) I even took a look at the PHP documentation for mysqli but it doesn't address the question of IPv6 at all. – Michael Hampton Nov 28 '15 at 19:24
  • O.o well okay. So I have an domain, on that domain I added a AAAA entry that points to the SQL database. And it works!!!!! But that means there is something wrong with the syntax of that IPv6 address. – usbpc102 Nov 28 '15 at 19:27
  • There are a few other things you should do: Make sure IPv6 privacy extensions are disabled on your workstation (unless you want to whitelist a new address every 10 minutes). Also contact your ISP and ask them to not change your IPv6 prefix frequently. Because of privacy reasons, most German ISPs change their customers' IPv6 prefixes very frequently. You want this to _not_ happen, again unless you want to whitelist a new address every so often. – Michael Hampton Nov 28 '15 at 19:30
  • Okay... now I don't have an IPv6 address anymore so I still have a problem that you could help me to solve. – usbpc102 Nov 28 '15 at 19:30
  • You could try [su], or contact your ISP. I think something is wrong with them :) – Michael Hampton Nov 28 '15 at 19:31
  • To be more clear, my router still has a IPv6 address, just my workstation does not have one. Also my ISP is somewhat awesome and only changes IP addresses when I restart my router. Well that is also not completly true, my workstation shows that I still have an IPv6 address when I use the ipconfig command, just your website dosen't show it anymore, so dosen't get it anymore. :/ – usbpc102 Nov 28 '15 at 19:34
  • OK, well it might be your router. But we don't do home networking at [sf]. – Michael Hampton Nov 28 '15 at 19:34
  • Where is the right place to get help with home networking and IPv6 problems? – usbpc102 Nov 28 '15 at 19:38
  • As noted above, [su] – Michael Hampton Nov 28 '15 at 19:41
  • Oh, sorry missed that. Thank you very much you helped a lot already! But befor I go and post there, let's just restart everything to make sure that it is not that easy to fix. ;) – usbpc102 Nov 28 '15 at 19:47

1 Answers1

1

So I can answer the question myself now, with help from Michael Hampton.

  1. No. The IPv6 address needs to be in square brackets. So the following should work: $servername = "[2001:6532:1234:1:6a4f:e1d7:5d69:52a3]";

  2. The way to check is to just try over and over again after you have got the right code. In my case my home network was doing something strange, and restarting all my network gear fixed it.

usbpc102
  • 121
  • 4