MySQL Remote Access Hosts With Range

rinkleton

Well-Known Member
Jul 16, 2015
108
4
68
Cleveland
cPanel Access Level
Root Administrator
I'm trying to integrate with Google Data Studios and they provide a list of IPs they will hit your MySQL database with, however, they are ranges. For example: 64.18.0.0/20.

MySQL connector - Data Studio (Beta) Help

I've tried using the API to add "64.18.0.0/20" or "64.18.0.0/255.255.240.0" but neither work. Is there any way to do this? The error I get is "The IP address/netmask is not valid."
 

rinkleton

Well-Known Member
Jul 16, 2015
108
4
68
Cleveland
cPanel Access Level
Root Administrator
But that's in addition to setting up MySQL access hosts right? Just because I allow some IPs through the firewall doesn't necessarily mean MySQL will permit the connection is my understanding.
 

rinkleton

Well-Known Member
Jul 16, 2015
108
4
68
Cleveland
cPanel Access Level
Root Administrator
Let me just clarify that I'm asking if cpanel (API) can accept IP ranges in for MySQL access hosts, and if so, is there a limit on the ranges and what format does it need to be in? Is that something you can help with?

What I am not looking for is help connecting Google Data Studios. I just mentioned it so it's understood why I'm asking.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,228
463
Hello @rinkleton,

You can use the percent symbol as a wildcard. EX:

Code:
uapi --user=username Mysql add_host host=192.168.%.%
Note that while it's not necessarily required for this UAPI function via the command line, it's good practice to URI encode values when using our API:

Code:
uapi --user=username Mysql add_host host=192.168.%25.%25
Thank you.
 

rinkleton

Well-Known Member
Jul 16, 2015
108
4
68
Cleveland
cPanel Access Level
Root Administrator
So 192.168.0.% would be equivalent to 192.168.0.0/24 and 192.168.%.% would be 192.168.0.0/16 right?

So if I need a /20 I'd have to do 192.168.%.% which opens up more IPs than what I want.... but that probably should be fine because I'll also have to set firewall exceptions which should accept the ips in ranges rather than wildcards.

I guess I'm curious if this is a mysql limitation or an API limitation.
 

rinkleton

Well-Known Member
Jul 16, 2015
108
4
68
Cleveland
cPanel Access Level
Root Administrator
Yep, thanks. The docs there seem to indicate they can take any subnet mask, but I guess that's not true. They can only take ones which fully allow or deny an A, B, C, or D block. IE: /24 and /16 work but not /19. So that was part of my confusion.
 

rinkleton

Well-Known Member
Jul 16, 2015
108
4
68
Cleveland
cPanel Access Level
Root Administrator
Hi Rinkleton,
Did you get this working. I'm trying to set up the same thing and not getting very far.
Thx
I did. Here was my steps as far as I remember:
  1. In your firewall add the IPs google provides exactly in the format they give. Don't forget to restart your firewall after. Example for CSF: "tcp:in:d=3306:s=64.18.0.0/20" (You only have to do this once per server)
  2. Set mysql access hosts for each of the IPs google gives you, but you have to do it in the mysql wildcard format. It doesn't exactly match up with the ranges google gives, but your firewall shouldn't allow them through in the first place. Example:
    64.18.%.%. (Do for each cpanel account you need to grant access to)
  3. Create new mysql user and give them select only permissions on the DB. (Do for each DB you need to grant access to)
This should let GDS connect to your DB.