GCP CloudSQL connection timed out from dbeaver/psql - google-cloud-platform

I have created a GCP cloudSQL instace and I am trying to connect using public IP. I have found my ip from https://checkip.amazonaws.com/ and I have white listed it in the connections tab from the console's sidebar. Then I opened dbeaver and I have added the instance's public IP address along with db name and db user and password and I get "Connection attempt timed out.". Then I have tried usingthe instance's Outgoing IP address and the connection succeded. So the question is what are the differences between cloudSQL Public IP address and Outgoing IP address and why I can connect only using the outgoing one but not the public one.
Also one more question, do these public ip addresses going to change overtime? also my public Ip address going to change? So each time I got to develop my app using the cloudSQL instance I have to change the environment variables that contain the public ip, as well as the whitelist of my own ip in order to work?
Thank you

Related

Can existing key pair be used if I restart the ec2 instance(stop and start) in aws or do we need to create new key pair or launch another instance?

I am trying to connect to linux ec2 instance feom windows pc. Firewall is open on port 22. But I am getting Network Timeout while connecting through putty. I have tried to debug, but everything seems fine.
I am able to connect using browser based ssh instance but not using putty or standalone ssh client.
So my only doubt is if I had to create a new key pair because I once restarted the ec2 instance.
No, you don't need to create a new key pair(.pem file) for connecting to your EC2 instance after restarts.
You should be able to connect to the instance through ssh after restart if you nothing has changed such as IP address or Security Group rules.
One of the reason can be that your public IP has changed due to some reason, so check that and connect accordingly.
The public IP associated to the EC2 instance can change in some circumstances. Here is the official documentation snippet referring that:
You cannot manually associate or disassociate a public IP address from
your instance. Instead, in certain cases, we release the public IP
address from your instance, or assign it a new one:
We release your instance's public IP address when it is stopped or
terminated. Your stopped instance receives a new public IP address
when it is restarted.
We release your instance's public IP address when you associate an
Elastic IP address with it. When you disassociate the Elastic IP
address from your instance, it receives a new public IP address.
If the public IP address of your instance in a VPC has been released,
it will not receive a new one if there is more than one network
interface attached to your instance.
If your instance's public IP address is released while it has a
secondary private IP address that is associated with an Elastic IP
address, the instance does not receive a new public IP address.
First of all, you do not need to create new key pair to launch your instance. What you need to do are the following:
Make sure you are using the correct key pair. You can verify this by going to the AWS console, select your instance, at the data section below, find "Key pair name"
Then, check for that public key (pem) file that you used to launch that instance
Using PuttyGen, load you pem file and save the generated key as private key (now you have your ppk file
Check your instance's Security Group and make you you opened port 22 (SSH) to 0.0.0.0/0
Open Putty and paste the following:
Host Name: Instance's Public IP
Connections > Data > Login Details: ec2-user (AmazonLinux) ubuntu (Ubuntu)
Connection > SSH > Auth > Private Key: Choose the generated PPK in step3
Click Open
You should now be able to open your instance via SSH
It was corporate network issue. Got it resolved. Sorry for inconvenience.

std#socket_bind exception when trying to bind socket on AWS

I'm trying to launch a simple socket server on Amazon Web Services, but I get an error message when trying to bind the socket like this:
var s:Socket = new Socket();
s.bind(new Host("Public AWS image IP here"), 5000);
The error is std#socket_bind exception. What am I doing wrong? Am I misusing IP address or do I need to open 5000 port? I'm a complete beginner.
UPD: I've changed IP address to 0.0.0.0, the server has started successfully, however, a client still can't connect to server:
s.connect("AWS Public IP", 5000);
But why? As I have figured out, binding to 0.0.0.0 should bind the socket to all of IPs available and there is a rule in my AWS console to allow all the connections to port 5000
If you are trying to bind the EC2 Public IP, you cannot as the public IP is not assigned to your network interface. You would bind the private IP address. The EC2 instance does not know anything about the public IP address assigned "logically" to it.
The AWS Internet Gateway (IGW) is a special type of 1 to 1 NAT gateway for public to private address mapping. This means that the public IP address is assigned to the public side of the gateway and not to your EC2 instance. Your EC2 instance receives a private IP address and this is the address that you can use in your bind() call.
However, the better choice is to bind 0.0.0.0 as this means bind to all network interfaces.

publicly access app from aws ec2 instance

I have just started with aws ec2.
I have deployed a simple web app on ec2 which listens on port 12345.
After SSH-ing into the instance from my windows machine using putty and once connected using curl for the apps endpoint and using either localhost, private IP address as well as public Dns (IPv4) it works fine.It does not work with IPv4 public ip though.
I now want to make that app accessible from the internet via browser. But, when I use public Dns or even Ipv4 Public ip along with the port , and try to access , it is not accessible. I only get the message , "This site can’t be reached" from chrome.
I have Inbound rule setup for the security group associated with the instance,
which allows ,
all trafic, via all protocol , via all ports (0-65535), and also I have given the Source as Custom, with IP range of 0.0.0.0/0.
I also have added another rule with same attributes, except for Source a Custom with IP range of , ::/0.
Can someone advise me on the right way to do this.

I cannot connect my web server via public IP in AWS instance

I'm studying AWS.
But I have a problem that I cannot connect to my web server on my AWS instance
AWS instance is Windows Server 2012
this is my instance status
I want to connect my web server via public ip 52.78.47.142 outside the AWS instance
if I connect to the private ip 172.31.15.206 inside the instance, home page showed up.
But if I connect to the public ip 52.78.47.142 inside the AWS instance and outside the AWS instance, home page didn't show up both.
although I set a new rule for http protocol at port 80, it doens't work
any helps? thanks a lot...
open up tcp:80 port in the security group(Inbound) for the IP address of the machine from where your accessing the website( In this case your Desktop or Laptop IP address).
If you are trying to access the web server from another AWS Instance open the port for that particular Instance IP. For troubleshooting case you can open up All traffic and test it(Though this is not recommended)

ftp access from AWS VPC private subnet behind a NAT instance

I have created a VPC with public and private subnets on AWS. All app servers are in private subnets and all outbound requests have to be through an internet-facing NAT instance.
At the moment, our project requires the app servers to access a ftp server provided by a service provider.
I have tried several ways to manage that, but all no luck. What I have done was to open a port range, let's say (40000 - 60000) on both NAT and APP security groups, also standard ftp ports 20 - 21 as well.
The user authentication can be passed, but I could not list contents from app servers.
I am able to access the ftp server from NAT, not problem at all.
So what should I do to make it work?
#JohnRotenstein is absolutely correct that you should use Passive FTP if you can. If, like me, you're stuck with a client who insists that you use Active FTP because their FTP site that they want you to connect to has been running since 1990 and changing it now is completely unreasonable, then read on.
AWS's NAT servers don't support a machine in a private subnet connecting using Active FTP. Full stop. If you ask me, it's a bug, but if you ask AWS support they say it's an unsupported feature.
The solution we finally came up with (and it works) is to:
Add an Elastic Network Interface (ENI) in a public subnet on to your EC2 instance in the private subnet
So now your EC2 instance has 2 network adapters, 2 internal IPs, etc.
Let's call this new ENI your "public ENI"
Attach a dedicated elastic IP to your new public ENI
Let's assume you get 54.54.54.54 and the new public ENI's internal IP address is 10.1.1.10
Add a route in your operating system's networking configuration to only use the new public ENI
In windows, the command will look like this, assuming the evil active ftp server you're trying to connect to is at 8.1.1.1:
route add 8.1.1.1 mask 255.255.255.254 10.1.1.1 metric 2
This adds a route for all traffic to the FTP server at 8.1.1.1 using subnet mask 255.255.255.254 (ie. this IP and only this IP) should go to the internet gateway 10.1.1.1 using ethernet adapter 2 (your second NIC)
Fed up yet? Yeah, me too, but now comes the hard part. The OS doesn't know it's public IP address for the public EIN. So you need to teach your FTP client to send the PORT command with the public IP. For example if using CURL, use the --ftp-port command like so:
curl -v --ftp-port 54.54.54.54 ftp://8.1.1.1 --user myusername:mypass
And voila! You can now connect to a nightmare active FTP site from an EC2 machine that is (almost entirely) in a private subnet.
Try using Passive (PASV) mode on FTP.
From Slacksite: Active FTP vs. Passive FTP, a Definitive Explanation:
In active mode FTP the client connects from a random unprivileged port (N > 1023) to the FTP server's command port, port 21. Then, the client starts listening to port N+1 and sends the FTP command PORT N+1 to the FTP server. The server will then connect back to the client's specified data port from its local data port, which is port 20.
Thus, the traffic is trying to communicate on an additional port that is not passed through the NAT. Passive mode, instead, creates an outbound connection, which will then be permitted through the NAT