title: Connect to google cloud instance fail
body: <p>I am trying to connect to google cloud instance from my ios app project. But I stuck in connecting to google cloud. Watched this tutorial but is outdated. <a href="https://www.youtube.com/watch?v=gxZvofAvgHQ&amp;t=179s" rel="nofollow noreferrer">https://www.youtube.com/watch?v=gxZvofAvgHQ&amp;t=179s</a></p>
  
  <p><strong>Here is the code I will use in my app</strong></p>
  
  <pre><code>Alamofire.request("http://external_ip:80/test.php", method: .post, parameters: ["test": String(1)]).responseString { (response) in
      switch response.result {
      case .success(let data):
          print(response.result)
      case .failure(let error):
          print(error)
      }
  }
  </code></pre>
  
  <p><strong>Steps to try connecting to google cloud.</strong></p>
  
  <ol>
  <li>use safari to connect <a href="https://external_ip:80" rel="nofollow noreferrer">https://external_ip:80</a></li>
  </ol>
  
  <p><code>Failed to open page</code></p>
  
  <ol start="2">
  <li><code>gcloud beta compute firewall-rules list</code></li>
  </ol>
  
  <p><code>NAME                    NETWORK  DIRECTION  PRIORITY  ALLOW                        DENY
  default-allow-http      default  INGRESS    1000      tcp:80
  default-allow-https     default  INGRESS    1000      tcp:443
  default-allow-icmp      default  INGRESS    65534     icmp
  default-allow-internal  default  INGRESS    65534     tcp:0-65535,udp:065535,icmp
  default-allow-rdp       default  INGRESS    65534     tcp:3389
  default-allow-ssh       default  INGRESS    65534     tcp:22
  rule-allow-tcp-80       default  INGRESS    1000      tcp:80</code></p>
  
  <ol start="3">
  <li><code>gcloud compute instances list</code></li>
  </ol>
  
  <p><code>NAME    ZONE          MACHINE_TYPE  PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP     STATUS
  outbuy  asia-east1-a  f1-micro                   internal_ip   external_ip  RUNNING</code></p>
  
  <ol start="4">
  <li><code>gcloud compute ssh &lt;my_pj&gt;</code> then <code>sudo nc -l -vv -p 80</code></li>
  </ol>
  
  <p>nc: listen: Address already in use</p>
  
  <ol start="5">
  <li>Try both solutions in here <a href="https://stackoverflow.com/questions/44620723/cant-connect-to-port-80-on-google-cloud-compute-instance-despite-firewall-rule">Can&#39;t connect to port 80 on Google Cloud Compute instance despite firewall rule</a></li>
  </ol>
  
  <p>Added this</p>
  
  <pre><code>// On your workstation:
  SUBNETWORK_URI=$(gcloud compute instances describe ${COS_INSTANCE_NAME} | grep -w 'subnetwork:' | awk '{ print $2 }')
  SUBNET_PREFIX=$(gcloud compute networks subnets describe ${SUBNETWORK_URI} | grep -w 'ipCidrRange:' | awk '{ print $2 }')
  // On your Container-Optimized OS instance:
  sudo iptables -w -A INPUT -p tcp -s ${SUBNET_PREFIX} -j ACCEPT
  sudo iptables -w -A INPUT -p udp -s ${SUBNET_PREFIX} -j ACCEPT
  </code></pre>
  
  <p>And </p>
  
  <pre><code>// Add a new tag based firewall rule to allow ingress tcp:80
  gcloud compute firewall-rules create rule-allow-tcp-80 --source-ranges 0.0.0.0/0 --target-tags allow-tcp-80 --allow tcp:80
  // Add the allow-tcp-80 target tag to the VM ssrf3
  gcloud compute instances add-tags ssrf3 --tags allow-tcp-80
  </code></pre>
  
  <p>Still no change. </p>
  
  <p>Any suggestion? </p>