Google Cloud - Adding additional Internal IP to VM - google-compute-engine

I'm trying to build a webserver in Google Cloud Platform that hosts multiple websites (GBP, IE, FR, DK etc.)
Generally, we assign a range of IPs to the server statically, set the bindings in IIS, then loadbalance using a virtual IP.
It seems near enough impossible to assign another internal IP in GCP. Lots of guides about additional external IPs, but we don't want a public facing webserver like this.
Anybody have any idea on how to add additional internal IPs to a VM / Instance?
Also, I have tried changing the internal address I have assigned to the Instance to static in network adapter settings, next thing I know I can't access my VM for love nor money, had to delete and re-create. If I go into advanced settings to add additional static IPs, w'ere set to DHCP apparently, so can't add additional IPs.
Thanks all.

Answer that I recieved from GCE discussion group, in Google Groups:
"You can add additional internal IP addresses to a VM instance. This is possible by enabling IP forwarding for the VM, creating a static network route, adding appropriate firewall rules, and setting additional internal IP addresses to network adapter of Windows. These steps are described in this article for Linux machines (https://cloud.google.com/compute/docs/networking#set_a_static_target_ip_address). The same steps are valid for Windows VMs. You will need to keep the initial internal IP address, subnet mask, gateway address and DNS settings of the adapter and manually enter them in properties of IPv4 of the network adapter. The below is a screenshot of my configuration on a VM instance (Windows 2008 R2) that perfectly works."

Update:
Now, you can create instances with multiple network interfaces On Google Compute Engine and assign IPs. For more information, refer to this public documentation link. However, currently it has following limitations:
Alias IP ranges are not supported on any network interface on a VM
that has multiple network interfaces enabled.
You cannot modify or delete the network interfaces after the VM has
been created.

Related

VM Instances on Google Cloud

I have created a VM instances on Google cloud and i want to access it from WAN. I try type address in address bar but it say server down. I can remote desktop to my window instance but cannot access it in browser.
What is the problems? How to solve it?
You can access linux instances with SSH and windows instances using remote desktop. More details can be found in the google cloud documentation here.
Update:
If you want to enable http access to your website then you need to
1) Make sure you are trying to connect to correct external ip address. Your server will either have a static or Ephemeral ip address. Ephemeral ip address changes every time you reboot your server. Static ip doesn't change, but it is not free. More details here.
2) Make sure you enabled http access in your firewall settings. (Maybe you forgot to check this option when you are creating your virtual machine?) To set the firewall settings go to Networking -> vpc network -> firewall rules

How to access service in google container engine from google compute engine instance

I have a cluster on a google container engine. There are internal service with the domain app.superproject with exposed port 9999.
Also I have an instance in google compute engine.
How can I access to service with it's domain name from the instance of google compute engine?
GKE is built on top of GCE, a GKE instance is also a GCE instance. You can view all your instances either in the web console, or with gcloud compute instances list command.
Note that they may not be in the same GCE virtual network, but in your use case, it's better to put them in, e.g., the default network (I guess they are already, but check their network properties if you are not sure), then they're accessible to each other through the internal IPs (if not, check firewall settings).
You can also use instance names, which resolve to internal IPs, e.g., ping instance1.
If they're not in the same GCE virtual network, you have to treat the service as an external service by exposing an external IP, which is not recommended in your use case.

AWS: can't connect to RDS database from my machine

The EC2 instance/live web can connect just fine to the RDS database. But when I want to debug the code in my local machine, I can't connect to the database and got this error:
OperationalError: (2003, "Can't connect to MySQL server on 'aa9jliuygesv4w.c03i1
ck3o0us.us-east-1.rds.amazonaws.com' (10060)")
I've added .pem and .ppk keys to .ssh and I already configure EB CLI. I don't know what should I do anymore.
FYI: The app is in Django
It turns out it is not that hard. Do these steps:
Go to EC2 Dashboard
Go to Security Groups tab
Select and only select the RDS database security group. You'll see the security group detail at the bottom
Click Inbound tab
Click Edit button
Add Type:MYSQL/Aurora;Protocol:TCP;Range:3306;Source:0.0.0.0/0
MAKE SURE PUBLIC ACCESSIBILITY IS SET TO YES
This is what I spent the last 3 days trying to solve...
Instructions to change Public Accessibility
Accept traffic from any IP address
After creating an RDS instance my security group inbound rule was set to a specific IP address. I had to edit inbound rules to allow access from any IP address.
"Security group rules"
Select a security group
Click "Inbound Rules"
Click "Edit Inbound Rules"
Under "Source" Select the Dropdown and click "Anywhere"
::0 or 0.0.0.0/0 Should appear.
Click "Save Rules"
Just burned two hours going through the great solutions on this page. Time for the stupid answer!
I redid my Security Groups, VPC's, Routing Tables, Subnets, Gateways... NOPE. I copy-pasted the URL from the AWS Console, which in some cases results in a hidden trailing space. The endpoint is in a <div> element, which the browser gives a \n when copying. Pasting this into the Intellij db connector coerces it to a space.
I only noticed the problem after pasting the URL into a quote string in my source code.
Make sure that your VPC and subnets are wide enought.
The following CIDR configuration works great for two subnets:
VPC
10.0.0.0/16
10.0.0.0 — 10.0.255.255 (65536 addresses)
Subnet 1
10.0.0.0/17
10.0.0.0 — 10.0.127.255 (32768 addresses, half)
Subnet 2
10.0.128.0/17
10.0.128.0 — 10.0.255.255 (32768 addresses, other half)
Adjust it if you need three subnets.
I wasn't being able to connect to my RDS database. I've manually reviewed any detail and everything was alright. There were no indications of any issues whatsoever and I couldn't find any suitable information in the documentation. My VPC was configured with narrow CIDR: 10.0.0.0/22 and each subnet had a 255 addresses. After I've changed CIDR to 10.0.0.0/16 and split it totally between two subnets my RDS connection started to working. It was a pure luck that I've managed to find a source of the problem, because it doesn't make any sense to me.
Well almost everyone has pointed out the answers, i will put it in different perspective so that you can understand.
There are two ways to connect to you AWS RDS
You provision an instance in the same VPC & Subnet. You install the workbench you will be able to connect to the DB. You would not need to make it public accessible. Example: You can provision an windows instance in the same VPC group and install workbench and you can connect to the DB via endpoint.
The other way is to make the Db publically accessible to your IP only to prevent unwanted access. You can change the DB security group to allow the DB port traffic to your IP only. In this way your DB will be publically accessible but to you only. This is the way we do for various AWS services we add there security group in the source part of the SG.
If both the options doesn't work then the error is in the VPC routing table, you can check there if it associated with the subnet and also if the internet gateway is attached.
You can watch this video it will clear your doubts:
https://youtu.be/e18NqiWeCHw
In my case, when I upgrade the size. The private address of the rds instance fell into a private subnet of the VPC. You can use the article
My instance is in a private subnet, and I can't connect to it from my local computer to find out your db instance address.
However, changing the route table didn't fix my issue. What I did finally solve my problem is to downgrade the size and then upgrade the size back. Once the private address falls back to the public subnet. Everything works like a charm.
I was also not able to connect even from inside an ec2 instance.
After digging AWS RDS options it turns out that ec2 instances are only able to connect to RDS in the same VPC they are in.
When creating an ec2 instance in the same VPC where the RDS was I could access it as expected.
Do not forget to check if you have your VPN or firewall blocking connection.
The ideal debugging checklist is:
Instance's "Publicly Accessible" property should be enabled
The security group attached to the instance should have open inbound rules (as open as you'd want)
The funny part is still if you're not able to access it - then the problem surely is with your instance lying in a private subnet of the respective VPC.
However, there're more secure ways to access your RDS instance. The best bet would be not make it publicly accessible, lock down security groups and have a P2P relay endpoint (think Tailscale).
In case you've tried all answers above try this...
Recreate the database....
AWS on database creation provides an option to allow public/private access access
I'm sure it's not the proper answer but I added the internet gateway to all my private subnet route tables..
Even though the private subnets and the public subnets are in the subnetgroup.
For me none of the above worked.
What did work was creating a peering connection between my default VPC and the VPC in which the database was created, as it appears that when connecting to resources in AWS, it automatically goes through the default VPC.
Then, set up routing using the peering connection between the 2 VPCs. Also, make sure that your security groups permits postgres ports from your default VPC CIDR block as well. And finally, make sure all the subnets are associated with your route table accessing this peering connection.

AWS RDS MySQL How to restrict db access to a single EC2 instance

I recently inherited an AWS account's maintenance and noticed that the db access is wide open to any network, anywhere! So I decided it must be simple like it is when we do it with our own VMs. Except on Amazon AWS EC2 instances have an internal IP and a public IP and sometimes an elastic IP. So I thought ok I'll search google and find a simple quick writeup, and there doesn't seem to be one. So can someone please provide a simple writeup, here, on how to do this. I understand there are three methods on the RDS security and so forth. If you don't have time or desire to cover all three please just pick the one you like and have used for the example. If I don't get a good response on this within a day or so I'll hit the docs and piece it together myself, thank you in advance!
Well I tinkered with it a bit. The docs are not too suggestive. I found on an EC2 instance that has an Elastic IP assigned I had to use the Private IP allowed in the security group I applied to the RDS MySQL database. The Elastic IP assigned or UN-assigned did not affect connection. On the EC2 instance which had no Elastic IP assigned I had to use the Public IP allowed in the security group. The Private IP did not matter. This seems a bit strange to me.
An Amazon Relational Database Service (RDS) instance should typically be kept private to prevent access from the Internet. Only in rare circumstances should an RDS instance be accessible on the Internet.
An RDS instance can be secured in several ways:
1. Launch it in a Private Subnet
A Virtual Private Cloud (VPC) can be configured with public and private subnets. Launching the RDS instance in the private subnet will prevent access from the Internet. If access is still required across the Internet (eg to your corporate network), create a secure VPN connection between the VPC and your corporate network.
2. Use Security Groups
Security Groups operate like a firewall around each individual EC2 instance. They define which ports and IP address ranges are permitted for inbound and outbound access. By default, outbound access is permitted but inbound access is NOT permitted.
3. No Public IP address
If an RDS instance does NOT have a Public IP address, it cannot be directly accessed from the Internet.
4. Network Access Control Lists
These are like Security Groups, but they operate at the Subnet level. Good for controlling which app layers can talk to each other, but not good for securing specific EC2 or RDS instances.
Thus, for an RDS instance to be publicly accessible, it must have all the following:
A public IP address
A Security Group permitting inbound access
Located in a public subnet
Open Network ACL rules
For your situation, I would recommend:
Modify the RDS instance and set PubliclyAccessible to False. This will remove the public IP address.
Create a new Security Group (I'll refer to it as "SG1") and assign it to the single EC2 instance that you want to allow to communicate with the RDS instance
Modify the Security Group associated with the RDS instance and allow Inbound communication from SG1 (which permits communication from the EC2 instance). Note that this refers to the SG1 security group itself, rather than referring to any specific IP addresses.

Getting AppHarbor and AWS RDS MySql to play nice

I have an app with two workers (Web and Background) on AppHarbor that connect to a MySql database hosted on Amazon's RDS.
I keep getting "Unable to connect to any of the specified MySQL hosts." exception.
The RDS instance in the US-East region and I have added the following AppHarbor CIDR to the security group.
50.17.211.192/28
54.235.159.192/27
I have added my own CIDR to the security group and I connect to the instance just fine.
However when the app is running on AppHarbor it fails.
My connection string (censored) is:
Server=myinstanceXXXX.cykjvptrw5xs.us-east-1.rds.amazonaws.com;Database=MyDatabase;UID=XXXXXX;PWD=XXXXX;
I have tried including the port 3306 on the server endpoint but it made no difference.
Am I missing something on getting the two to play nice with one another?
By default AppHarbor use Amazon's internal DNS service for resolving hostnames. Because of that Amazon RDS instances in the same region as AppHarbor will resolve the private IP addresses rather than the public ones listed in the knowledge base article, so setting up rules based on the public IPs will not work most of the time.
In case Amazon's DNS service becomes unavailable we'll fail over to an external DNS service. This means you'll still have to configure the external IPs for the highest availability as an external DNS service will resolve the public IPs. This way you can ensure that your application is resilient towards DNS failures.
You can set up security group based access rules for your RDS security group. We've updated this knowledge base article with a section specifically for Amazon RDS where you can find the information necessary to set this up.