WinSCP to google cloud - google-compute-engine

I have google cloud compute engine instance. I'm trying to connect using winSCP. I followed the steps by https://cloud.google.com/compute/docs/instances/connecting-to-instance
It is stating "Connection Timed out error" What should be the cause. Should I need to open firewall in google cloud? But it doesn't shown in the instruction.

Yes, you should have a GCE firewall rule added for SSH protocol to allow this traffic to the VM instances that you want to connect. This is a quote from this article:
Each network has its own firewall controlling access to the instances.
All traffic to instances, even from other instances, is blocked by the
firewall unless firewall rules are created to allow it.
The default network has automatically created firewall rules, which
are shown below. No manually created network of any type has
automatically created firewall rules. For all networks except the
default network, you must create any firewall rules you need.
Firewall rules are only "allow" rules. You cannot create "deny" rules.
If you need to restrict traffic from reaching certain instances,
create rules that allow traffic to the other instances, then remove
the firewall rule that allowed traffic to all of the instances.
The firewall rules automatically created for the default network are
as follows:
default-allow-internal
Allows network connections of any protocol and
port between instances on the network.
default-allow-ssh
Allows SSH connections from any source to any instance on the network over > TCP port 22.
default-allow-rdp
Allows RDP connections from any source to any instance on the network over > TCP port 3389.
default-allow-icmp
Allows ICMP traffic from any source to any instance on the network.

Related

connect to remote mysql server from google cloud

I have a google cloud machine which has an ubuntu Os, I have MySQL database on another server, I opened the remote connection on my SQL server, and I connect to my database from any machine else from my google cloud machine I can not, it taking long time then I have a timeout connection problem.
I think the problem is from firewall rules, so I applied this command to create rule that allow 3306 port
cloud compute firewall-rules create "mysql-remote-access" --allow tcp:3306 --source-tags "mysql-client" --target-tags "mysql-server"
but still, I can not connect to a remote MySQL server
from where can I enable it, thank you
I think your firewall rules is not correct. This one should solve the issue
gcloud compute firewall-rules create "mysql-remote-access" \
--direction=EGRESS --action=ALLOW --rules=tcp:3306 \
--destination-ranges=xxx.xxx.xxx.xxx/32 --target-tags=mysql-client
Short description: You allow the EGRESS traffic on port 3306 to the destination xxx.xxx.xxx.xxx for the traffic coming from the VM with the tag "mysql-client"
By default all the outgoing communication are allowed, but you might have a rule with higher priority that prevents this
Implied allow egress rule. An egress rule whose action is allow, destination is 0.0.0.0/0, and priority is the lowest possible (65535) lets any instance send traffic to any destination, except for traffic blocked by Google Cloud.
It the rule doesn't work, share all your existing firewall rules.

GCE instance -- cannot ping its own external IP

I can ping its external IP from my local laptop, but cannot ping from its own. I have set up firewall rules to allow icmp from all internal IPs of its subnetwork (10.45.0.0/6) . What other reasons could be?
GCE uses the Hypervisor to assign the External IP to an Instance.
That means the firewall rule applies between the external IP and the Instance and to be able to enable ping lookback, a 0.0.0.0/0 allow rule (or more restrictive) for icmp will allow the ping to reach the external IP from the Internal one. Make sure you have the default firewall rule 'default-allow-icmp' on your network details for the VM. Please see this link for more information about rules in the default network.

Google Compute Engine: How can I disable the firewall of VM instance?

I have used firewall rules but I still cannot receive traffic on vm instance. I want to allow http server incoming connection. By default google compute engine does not allow incoming traffic outside the network, so you have to create firewall rules. In google cloud platform documentation it suggests to disable operating system firewall. To disable it I need my user password, which I never created. So what to do now? I need password for my user, I am the creator of vm instance. Any help?
These are my firewall settings:
saad_hussain#saad:~$ gcloud compute firewall-rules list
NAME NETWORK SRC_RANGES RULES SRC_TAGS TARGET_TAGS
default-allow-http default 0.0.0.0/0 tcp:80 http-server
default-allow-https default 0.0.0.0/0 tcp:443 https-server
default-allow-icmp default 0.0.0.0/0 icmp
default-allow-internal default 10.128.0.0/9 tcp:0-65535,udp:0-65535,icmp
default-allow-rdp default 0.0.0.0/0 tcp:3389
default-allow-ssh default 0.0.0.0/0 tcp:22
http default 0.0.0.0/0 tcp:80
https default 0.0.0.0/0 tcp:80
Open Google Cloud Platform and log in.
Click Console at the top-right
Click Computer Engine from the left menu.
Than click VM instances from the left menu.
Click the virtual machine instance's three-dot menu(...) which you want to allow the port connection.
Select "View network details". (Now you can see rules about firewall)
Click "Firewall Rules" from left menu.
Click "CREATE FIREWALL RULE" button at the top of page.
At here you can allow any ip to connect to your vm instance or allow any port to connection. Now you can adjust firewall for vm instance good luck.
Here is some advice to troubleshoot similar issues. Have a look to:
a) Google Firewall. As per the comments and the output provided, port 80 is already opened but will only apply to instances that hold the tag ¨http-server¨.
b) Making sure that a firewall inside the VM is not filtering packets. As also mentioned in the comments most of the public images provided by Google allow the traffic by default.
c) Making sure that the service is not only listening on localhost and it is using an IPv4 address
Using nmap can help to determine if the issue is being caused by a firewall or the server not listening in the appropiate port. The lastest can also be verified using ¨netstat --listen¨

Block offending IP from Google Compute Instance

Is there a network-level IP address blocking/blacklist capability to a Google Compute Engine instance? For example, a site is hosted on a GCE instance to allow public users access. However, a malicious script runs several times/second which is not legitimate traffic. Ideally, the IP of the offending user could be placed on a block list so traffic would not be routed to the instance, rather than just server side only mechanism (apache modules, IPtables, etc) which still requires CPU/RAM/disk resources.
You can setup an HTTP load balancer for your instances, and allow traffic only from the LB IP address to your instances. More information can be found in this Help Center article.
GCP does not provide WAF natively. You can use marketplace WAF (like Brocade WAF) to block IPs.
https://cloud.google.com/launcher/solution/brocade-public-1063/stm-csub-1000-h-saf?q=brocade
This is absolutely not the recommended way to manage your firewall blacklist.
However...
In the compute GUI, you can create a firewall rule set action on match to "deny" and protocols and port to "deny all". Then set source IPs.
compute GUI
You could then run a cron job to update your firewall through gcloud compute firewall-rules update to update source IPs should your list change.
Note (from Google - https://cloud.google.com/vpc/docs/using-firewalls):
gcloud compute firewall-rules update is used to update firewall rules that allow/deny incoming/outgoing traffic. The firewall rule will only be updated for arguments that are specifically passed. Other attributes will remain unaffected. The action flag (whether to allow or deny matching traffic) cannot be defined when updating a firewall rule
Yes you can block it using Gcloud Firewall.
Try creating the firewall rule from the command line or by logging into Google Cloud.
Example:
gcloud compute firewall-rules create tcp-deny --network example-network --source-ranges 10.0.0.0/8 --allow !tcp:80
Above Rule will block the range 10.0.0.0/8 to port 80 (tcp).
Same can be done to block other IP Ranges over tcp and udp.
For more info check this: glcoud network config

Troubleshooting Google Compute Engine Network Firewall VPN

How can I troubleshoot GCE firewall issues? We're running some GCE servers and connecting to a non-google network via ipsec using google beta vpn service (although I had the same problem with GCE and my own StrongSwan instance in the past and could never fix it there either).
I'm trying to connect to 192.168.4.176 (a linux box with no firewall running) and I'm pretty sure google is blocking the traffic. The VPN is fine. I can ping 192.168.4.180. But I can't ping 192.168.4.176. And nc 192.168.4.176 22 just times out.
I can run a SSL VPN from a gce instance and can ping 192.168.4.176 without issue.
Here's a screenshot of the GCE network. I also tried routes/firewall rules with 192.168.4.1/24 but those didn't work either for connecting to .176 but .180 was fine. Any ideas on what to try?
Here are the gce network details
Here's the gce vpn screen
Here's the gce vpn detail screen
And from the remote network I can ping my 10.x gce instances from 192.168.4.180 (which I should since I'm allowing that). But I can't ping any gce 10.x addresses from 192.168.4.176 (which I interpret that the google firewall is blocking the traffic even though I have it configured to let it through).
can you confirm that the secret key for the .176 VPN is correctly configured on both ends?
the firewall rule for .176 VPN - is that added in GCE firewall section, mapping the right network where the VPN tunnel was created.
Does the VPN UI status show a Green tick mark for both the tunnels?
You could also View VPN Logs from GCP UI : from the UI Console,left menu Monitoring -> Logs, and then select "Compute Engine"-> "targetVPNgateway" and select the tunnels and "ipsec_events" dropdown. Check the log when you access the .176 VPN to observe the likely packet flow.