Access localhost on Google Cloud instance using External IP - google-cloud-platform

There are many similar questions to this on SO, but none of the solutions I saw really solved my issue completely. I'm doing test runs for a website framework hosted on the Google Cloud Platform.
By default, the website is hosted on http://localhost:2800 And I know the external IP of the instance I'm running it on. How can I access the hosted website through a browser on my local machine? Do I use virtual hosts / port forwarding etc.?

go to your VPC firewall
https://console.cloud.google.com/networking/firewalls
and create a firewall rule to allow traffic on your desired tcp port
Create a Firewall Rule for SQL Server
Configure a firewall rule to allow traffic on port 1433 so other clients can connect to the newly created SQL Server instance over the public internet:
In the Developers Console main menu, go to the Firewall rules section.
OPEN THE FIREWALL RULES
Click the Add firewall rule button.
Name the new firewall rule allow-tcp-1433.
Set Source Filter to IP Ranges.
For Source IP Ranges enter 0.0.0.0/0. This value allows access by all IP addresses.
Warning: This configuration leaves your SQL Server instance open to traffic from everyone, everywhere. It is used only for demonstration purposes. In production environments, restrict access to only those IP addresses that need access.
For Allowed protocols and ports enter tcp:1433.
Click the Create button to create the firewall rule.

Set firewall rules for you google cloud project with following properties:
Target: all instances
Direction: ingress
Source IP ranges: 0.0.0.0/0
Ports and protocols: allow all
Then Depending on your framework, set allowed_host to externalIP or "*" .
For example - In Django, in settings.py set ALLOWED_HOSTS = ["*"]
Now run server on specific 0.0.0.0:[your_port]
For example in django - Python manage.py runserver 0.0.0.0:8000
After this note down you instance external IP address and then in your browser :- goto
[external-IP:[your_port]]

you have to go VPC network, then add firewall to allow your port. then don't forget to select [All intances in the network] (see pic). because, by default its value is [Spesified by tags].
and you can access that instance to its External IP

Try your [externalip]:[port] This worked for me in Amazom ec2.
example: 31.181.171.141:2800

Related

Cannot SSH to google cloud Linux machine

When i attempt to SSH from https://console.cloud.google.com/compute/instances?authuser=0&projec
I get the error:
Connection via Cloud Identity-Aware Proxy Failed
Code: 4010
Reason: destination read failed
Please ensure you can make a proper https connection to the IAP for
TCP hostname: https://tunnel.cloudproxy.app You may be able to connect
without using the Cloud Identity-Aware Proxy.
Though on a seperate machine i am able to login, but Firewall and other settings seem identical ?
What should i do to get in ?
Krgds.
C
This issue is due to the lack of a firewall rule to allow-ingress-from-iap with this IP range 35.235.240.0/20 that needs to be configured when using IAP (Identity-Aware Proxy).
To Allow SSH access to all VM instances in your network, do the following:
1- Open the Firewall Rules page (Navigation menu > VPC network > Firewall) and click Create firewall rule
2- Configure the following settings:
Name: allow-ingress-from-iap
Direction of traffic: Ingress
Target: All instances in the network
Source filter: IP ranges
Source IP ranges: 35.235.240.0/20
Protocols and ports: Select TCP and enter 22 to allow SSH
3- Click Create
My impression is that the root casuse, was the the linux box had run out of hard disk space, causing the issues.
So when i recreated the same machine, with more disk space, the issue was resolved.

ERR_CONNECTION_REFUSED when allowing https traffic to dataiku instance on GCP

I installed dataiku on GCP instance.
It works perfectly fine on http protocol.
Now I am trying to allow https traffic.
I followed this official doc: https://doc.dataiku.com/dss/latest/installation/custom/advanced-customization.html#configuring-https
But after doing all the mentioned steps, I have an ERR_CONNECTION_REFUSED on my browser when doing: https://MyDataikuInstanceIp:1024
Is something more required on GCP in order to allow https traffic on the instance ?
Thanks.
In order to allow https and http traffic on a GCP instance, you should follow the next steps:
Navigate to Compute Engine > VM Instances.
Select your instance. Go to Edit.
Scroll down and locate Firewalls. Check both "Allow HTTP traffic" and "Allow HTTPS traffic".
Save your instance.
To review whether the firewall rule is enabled or disabled, you can use the following command:
gcloud compute firewall-rules describe [FIREWALL-NAME]
Also, if you have created a network tag in your instance, you will need to associate it to your firewall rule to match the target.
In the following link, you will find more information about how the firewall rules work in GCP
In addition as a best practice check if the firewall on your client is allowing connections through the TCP ports 443,1024 and the certificate from your server domain was allowed in your client.

Problem connecting 2 external IP Google Cloud Platafform

I created my VM(Google Cloud Platform), working with Windows Server 2008 R2. So i installed a program that needs the port 6900 opened to run. The program for work must connect to it own server that is: 200.229.50.3:6900. So i entered in the firewall rules of Google Cloud Platform, put ip as 0.0.0.0/0 and opened the port 6900. Also entered in the advanced configures of firewall on my VM, and also allowed the port 6900. Tried to run the program and failed, tried to run telnet to test and failed. Already checked security settings, disabled firewall, etc. I don't know whats is happening.
Follow my Google Cloud Platafform Firewall Rules bellow:
Firewall Rules
Follow my instance Firewall Rules:
Instance Firewall Rules
Follow the program getting error trying to connect on it own server:
Program error
If someone want enter in my instance to check better it, can download the RDP file from here: RDP file
my external ip: 104.198.152.164
user: lala2018
password: ^#0aQaaz)MXbMNy
The program that the error is ocurring is on the desktop with the name xstart.
Feel free to run it, and try to understand what is the problem, because i can't find reasons for it isn't running right.
Someone can help me?
Edit 1:
Follow my VPC routting:
VPC 1 VPC 2
Edit 2:
Traced Route - 200.229.50.3
After seeing the screenshot of the message you attached, it looks like you are trying to connect from a GCP instance to the server "200.229.50.3" whose IP address belongs to "LEVEL UP! INTERACTIVE LTDA" in Brasil; however, seems "200.229.50.3" is not allowing you to connect ("200.229.50.3" it doesn't respond). If this is correct, you may have to create firewall rules in "200.229.50.3" instead of creating them in GCP.
I can see you have three rules to permit ingress and egress traffic from and to the GCP instances but none of them affects to "200.229.50.3" because this server doesn't belong to the GCP project:
- The GCP firewall rule named "testeee" allows incoming connections from the IP address 200.229.50.3 to all instances within your GCP project through the port 6900.
- The Windows firewall rule named "Port 6900" allows connections from any IP outside the Windows server through the port 6900.
- The GCP firewall rules "mean-stack" and "exit900" are allowing egress traffic from GCP instances to any IP outside the GCP project through the port 6900.
I tried to establish a telnet connection to 200.229.50.3:6900 but it doesn't respond. This could be normal because there could be a firewall in that server which is not allowing connections from my IP address; however, I have to ask the following:
Can you confirm 200.229.50.3 is allowing connections through the port 6900 from your GCP Instance?

How to view website launched in Amazon EC2 instance?

I have followed the steps provided by Amazon EC2. I have installed a wordpress website in the EC2 Instance.
My public DNS is given as ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com/
and Public IP is also given as xx-xxx-xx-xxx.
How to view the website from any other machine?
Note:
EC2 Instance is created and running now.
I can view it in the localhost as well as public DNS in the EC2 instance using RDP. (http://ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com/)
If you can see the web site from the EC2 instance, but not from other machines, there is probably one of the following things wrong:
The DNS entry is not available or is wrong. Since you can RDP using that entry, this can't be the cause.
Access to the correct port is being blocked by the security group or firewall. Since the instructions you referenced specifically say to make sure that both port 80 (HTTP) and 3389 (RDP) are open, and you know that is true from port 3389, this isn't likely, but is possible. Make sure that there are security group rules for both port numbers that look the same.
The Windows server itself is refusing to allow outside access to port 80 on that address. This is unlikely, but not impossible, and the instructions specify that you should "disable Internet Explorer Enhanced Security Configuration", and at the end cover "Making Your WordPress Site Public". Make sure that the web server isn't configured to only respond to requests from localhost (127.0.0.1) and that there are no Windows firewall rules blocking port 80.
I think that the likeliest problem is number 2, above. Perhaps you forgot to open port 80 in the security group, or typed a different port number or a different address range to open it to.

Flask web app not responding to external requests on EC2

I've got a very simple Flask application that I'm hosting on an Amazon EC2 node and for whatever reason I can't see it externally. The flask app is here
from flask import Flask
app = Flask(__name__)
app.config['DEBUG'] = False
#app.route('/')
def hello_world():
return 'Hello World!'
#app.route('/p1')
def p1():
return "P1!!!"
if __name__ == '__main__':
app.run(host='0.0.0.0')
When I run the script it looks like the server is running fine, so in my browser (on a different computer) I put the following :5000 (the IP address I pull off of AWS). What's interesting is that it just seems to hang, and eventually produces an error. My guess is that I'm missing some configuration in AWS but I don't know what it is. Any help would be greatly appreciated
EDIT I tried deploying the app on my local machine. And when I try to access it from the browser using localhost:5000, it works. When I replace localhost with my IP address, it fails
Found this question while searching for a solution to the same issue.
edit run.py to enable flask to respond to requests from other than localhost.
this example enables responding to requests from anywhere. good security policies would use something more restrictive.
app.run(host='0.0.0.0')
in the AWS control panel go to EC2: select instance.
the browser should be pointed to the address from 'Public DNS (IPv4)'
(the ip# from IPv4 Public IP might also be useful)
look for 'Security groups': right-click to open the security group on a new page.
check inbound rules.
by default, flask binds to port 5000. add rule permitting incoming TCP traffic on port 5000.
while good security protocol should limit the number of ports left open and the range of IP's permitted to connect, it might be easier to permit 'anywhere' to connect over 'all tcp'.
NB: check if the default port has been changed in the flask config file run.py
ie: line below changes port from the default 5000 to 3000.
app.run(debug=True, port=3000)
Can also check if the flask instance is working locally by ssh'ing to the server and using a local instance of the lynx text browser to verify the port is responding. ie
lynx localhost:5000
Was able to ultimately answer my own question, both really
The problem I was having on AWS was that my inbound for that EC2 was not allowing access through the ports that I would need.
When I tried running it on my local machine at work, firewall settings change the address of localhost (and my IP) so that's why I couldn't access it outside of using localhost:5000
In your EC2 instance, the security group is what restricting your entry to the website.
Go to AWS portal, select your instance
Locate the security group and click the name
in the inbound rule window, select add rule
Not a recommended security practice but to get it running, select All TCP
add '0.0.0.0' in the source
your website will be running
I faced a similar issue in which the Flask app on EC2 instance was not responding. Turns out that I had to modify the inbound rules because:
The default security groups and newly created security groups include default rules that do not enable you to access your instance from the internet.
In order to modify the inbound rules, go to:
Instances dashboard > Security > Security Groups (go to your security group) > Edit Inbound Rules > Add Rule.
Fill the values:
Type -> Custom TCP
Protocol -> TCP
Port range -> 5000 (If your flask app is running on default port)
Source -> Your IP or 0.0.0.0/0 if you want to allow all traffic. You can also select My IP from source dropdown. This will automatically get your IP.
Save and you are good to go!
As you are already using host="0.0.0.0" in your app it should be accessible from anywhere. The only think blocking it is your aws security group inbound rules. Add a All TCP inbound rule for port 0-65535 (your app port should be in this range) with source 0.0.0.0/0 and it should work.