Search code examples
google-cloud-platformgoogle-compute-enginegoogle-vpc

Compute Engine VM can't connect to internet even with an external IP


I am having trouble setting up a compute engine VM that can access the internet to install new packages. The VM has an external IP address set and I have opened port 22 for SSH access. After connecting via SSH I am trying to install the redis-cli via apt-get but the VM cannot access the internet for some reason. Something to point out is it's deployed inside a custom VPC and if I deploy the exact same VM inside the default VPC everything works as expected. I do not want to setup a Cloud NAT exit and I don't believe it's required as I have an external IP on the VM itself and the default network functions as expected without a NAT. Any insight into what VPC settings could be causing this would be helpful.

Solution

Posting the actual fix for my issue here as the marked answer was great and led me to the solution for my specific issue. Basically after running the connectivity test that dany L suggested it pointed out the custom VPC did not have a route to the internet which is automatically created for you with the default VPC. I added the internet route isolated only to this VM and everything is working as expected now. More information on VPC routes can be found here https://cloud.google.com/vpc/docs/routes.


Solution

  • Try the following

    https://console.cloud.google.com/ > Menu > Network Intelligence > Connectivity tests > Create a connectivity test > set source IP to be your VM > set destination IP (an external IP to Google as an example) > create

    View results details @ VIEW, and it should tell you why connection is failing