Not able to access mysql created in private subnet where vpc is having subnet cidr range of 100.0.0.0/26

Viewed 77

I've created a VPC and it's having 2 public and 2 private subnets.

The cidr_range for public is [100.0.0.0/26, 100.0.0.64/26] and for the private is [100.0.0.128/26, 100.0.0.192/26].

Now I created a mysql instance in private subnet which is having a private ip as 10.85.0.2.

To access the private db, first created the bastion which is having both public and private ip in the same VPC and then created the master instance which is in the private subnet (having only private ip).

Now if I want to access mysql from master then getting error as

ERROR 2003 (HY000): Can't connect to MySQL server on '10.85.0.2:3306' (110)

If I change the cidr_range of subnets in the range of 192.168.0.0/26 then I'm able to access the db.

Is there any solution to access db without changing the cidr_range (access in range of 100.0.00/26)?

1 Answers

Writing this as Community Wiki for better visibility.

Answer for this question was written by John Hanley in the comment section.

The CIDR 100.0.0.128/26 is not a valid private IP address. That is a valid routable public IP address. Consult RFC 1918 to create valid addressing.datatracker.ietf.org/doc/html/rfc1918 A public IP cannot connect to a private IP without a gateway/proxy.

In GCP Documentation - Virtual Private Cloud you have Valid Ranges section which provides your default Private IP ranges which are ready to use.

Private IP addresses RFC 1918

10.0.0.0/8

172.16.0.0/12

192.168.0.0/16

That's why you have set CIDR to 192.168.0.0/26 you were able to connect.

Regarding your question:

Is there any solution to access db without changing the cidr_range (access in range of 100.0.00/26)

IMO, the best solution would be to reconfigure your whole network in your GCP project. Not use default VPC but use custom and customize VPC to your specific needs

Related