2017-06-19 124 views
0

總之,雖然我設置了允許tcp:80的防火牆規則,但是位於「默認」網絡中的我的GCE實例不是接受到端口80的連接。看起來只有端口22在我的實例上打開。我可以ping它,但不能在64跳以下跟蹤它。儘管有防火牆規則,無法連接到Google雲計算實例上的端口80

以下是我的調查結果。

gcloud beta compute firewall-rules list 

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:0-65535,icmp 
default-allow-rdp  default INGRESS 65534  tcp:3389 
default-allow-ssh  default INGRESS 65534  tcp:22 
temp     default INGRESS 1000  tcp:8888 


gcloud compute instances list 
NAME ZONE  MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS 
ssrf3 us-west1-c f1-micro  true   10.138.0.4 35.197.33.182 RUNNING 


gcloud compute instances describe ssrf3 
... 
name: ssrf3 
networkInterfaces: 
- accessConfigs: 
    - kind: compute#accessConfig 
    name: external-nat 
    natIP: 35.197.33.182 
    type: ONE_TO_ONE_NAT 
    kind: compute#networkInterface 
    name: nic0 
    network: https://www.googleapis.com/compute/v1/projects/hack-170416/global/networks/default 
    networkIP: 10.138.0.4 
    subnetwork: https://www.googleapis.com/compute/v1/projects/hack-170416/regions/us-west1/subnetworks/default 
... 
tags: 
    fingerprint: 6smc4R4d39I= 
    items: 
    - http-server 
    - https-server 

我ssh到35.197.33.182(這是ssrf3實例),然後運行:

sudo nc -l -vv -p 80 

在我的本地機器上,我跑:

nc 35.197.33.182 80 -vv 
hey 

但沒有任何反應。 所以我嘗試ping主機。這看起來很健康:

ping 35.197.33.182 
PING 35.197.33.182 (35.197.33.182): 56 data bytes 
64 bytes from 35.197.33.182: icmp_seq=0 ttl=57 time=69.172 ms 
64 bytes from 35.197.33.182: icmp_seq=1 ttl=57 time=21.509 ms 

Traceroute退出64跳後退出,未到達35.197.33.182目的地。

所以我檢查哪些端口是使用nmap開放:

nmap 35.197.33.182 

Starting Nmap 7.12 (https://nmap.org) at 2017-06-18 16:39 PDT 
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn 
Nmap done: 1 IP address (0 hosts up) scanned in 3.06 seconds 



nmap 35.197.33.182 -Pn 

Starting Nmap 7.12 (https://nmap.org) at 2017-06-18 16:39 PDT 
Nmap scan report for 182.33.197.35.bc.googleusercontent.com (35.197.33.182) 
Host is up (0.022s latency). 
Not shown: 999 filtered ports 
PORT STATE SERVICE 
22/tcp open ssh 

Nmap done: 1 IP address (1 host up) scanned in 6.84 seconds 

......甚至當我在35.197.33.182運行nc -l -p 80

+0

請說明你有問題用於VM其源圖像。 –

回答

1

確保VM級防火牆不干預。例如,集裝箱優化的OS的情況比較特殊相比於所有其他默認圖像:

缺省情況下,集裝箱優化的主機操作系統的防火牆僅允許發出的連接,並且僅通過SSH服務接受傳入連接。要接受容器優化的操作系統實例上的傳入連接,您必須打開服務正在偵聽的端口。

https://cloud.google.com/container-optimized-os/docs/how-to/firewall

0

快速一瞥,您的設置似乎是正確的。

  • 您已允許INGRESS tcp:80用於默認網絡中的所有實例。
  • 您的VM位於默認網絡上。

不幸的是,由於使用SDN,虛擬網絡和大量中間網絡基礎設施,Traceroute在虛擬機運行於雲提供商時不能提供良好的指示。

我注意到的一件事是您的實例有2個標籤http-serverhttps-server。其他一些防火牆規則可能會使用這些規則,這些規則可能會阻止您的虛擬機tcp:80端口的流量。

您的設置中還有其他變量,如果需要進一步調試,我很樂意進行調試。

Tag based firewall rules

你可以嘗試將應用防火牆規則只對具有特定目標標籤實例基於標籤的防火牆規則。

網絡使用網絡標籤來識別哪些實例是 受到某些防火牆規則和網絡路由的約束。例如,如果 有幾個正在爲大型網站提供服務的VM實例,請使用共享字或術語標記 這些實例,然後使用該標記 應用允許HTTP訪問這些實例的防火牆規則。標籤 也反映在元數據服務器中,因此您可以將它們用於在您的實例上運行的 應用程序。當您創建防火牆 規則時,您可以提供sourceRangessourceTags,但不能同時提供。

# 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 

這可能需要幾秒鐘到幾分鐘,以使更改生效的。

注意:由於您打開VM的外部IP端口到互聯網,請注意根據在這些端口上運行的應用程序的需要來限制訪問。

相關問題