Beispiele für globale und regionale Netzwerk-Firewallrichtlinien
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Diese Seite enthält Beispiele für eine globale Netzwerk-Firewallrichtlinie und für die Implementierung von regionalen Netzwerk-Firewallrichtlinien. Es wird davon ausgegangen, dass Sie mit den Konzepten vertraut sind, die unter Globale Netzwerk-Firewallrichtlinien und Regionale Netzwerk-Firewallrichtlinien beschrieben werden.
Sie können eine globale Netzwerk-Firewallrichtlinie und mehrere regionale Netzwerk-Firewallrichtlinien an ein VPC-Netzwerk (Virtual Private Cloud) anhängen. Eine globale Netzwerk-Firewallrichtlinie gilt für alle Subnetzwerke in allen Regionen des VPC-Netzwerks. Eine regionale Netzwerk-Firewallrichtlinie gilt nur für die Subnetzwerke des VPC-Netzwerks in der Zielregion.
Abbildung 1 beschreibt den Bereich einer globalen Netzwerk-Firewallrichtlinie und einer regionalen Netzwerk-Firewallrichtlinie in einem VPC-Netzwerk.
Abbildung 1. Bereich der globalen und regionalen Netzwerk-Firewallrichtlinien.
Beispiel: Alle externen Verbindungen mit Ausnahme bestimmter Ports ablehnen
In diesem Anwendungsfall blockiert eine Firewallrichtlinie alle Verbindungen von externen Internetquellen mit Ausnahme der Verbindungen an den Zielports 80, 443 und 22. Eine eingehende Internetverbindung an anderen Ports als 80, 443 oder 22 wird blockiert. Die Regelerzwingung wird für alle Verbindungen an den Ports 80, 443 oder 22 an die regionale Netzwerk-Firewallrichtlinie delegiert.
In diesem Beispiel gilt eine region-a-Netzwerkrichtlinie, die internen Traffic von der Quelle 10.2.0.0/16 und eingehenden Traffic zu den Ports 443 und 80 von jeder Quelle zulässt. Abbildung 2 beschreibt die Konfiguration für diesen Anwendungsfall.
Abbildung 2. Alle externen Verbindungen mit Ausnahme bestimmter Zielports ablehnen.
Auf VMs angewendete geltende Richtlinie
In diesem Abschnitt wird die effektive Netzwerk-Firewallrichtlinie beschrieben, die in diesem Beispiel gilt, nachdem die Regeln in der Hierarchie ausgewertet wurden.
Eingehende Verbindungen
Alle eingehenden Verbindungen von 10.0.0.0/8 entsprechen der Regel mit der höchsten Priorität der globalen Netzwerk-Firewallrichtlinie delegate-internal-traffic und umgehen die restlichen Regeln in der globalen Netzwerk-Firewallrichtlinie. In der regionalen Netzwerk-Firewallregel sind eingehende Verbindungen von 10.2.0.0/16 zulässig und der Rest der Verbindungen wird anhand der implizierten eingehenden Regel deny ausgewertet.
Eingehende Verbindungen mit einem anderen Quell-IP-Bereich als 10.0.0.0/8 und den Zielports 22, 80 und 443 werden an die Ebene der regionalen Firewallrichtlinien-Regeln delegiert. In der Regel der regionalen Netzwerk-Firewallrichtlinie sind die Ports 80 und 443 zulässig, Port 22 jedoch nicht.
Ausgehende Verbindung
Bei den globalen Richtlinien für Netzwerkfirewalls gibt es keine Übereinstimmung. Daher gelten die impliziten Systemregeln, die ausgehende Verbindungen zulassen.
Konfiguration
Erstellen Sie eine globale Firewallrichtlinie für das Netzwerk, die die folgende Regel enthält:
gcloud compute network-firewall-policies create \
"example-firewall-policy-global" --global \
--description "Global network firewall policy with rules that apply to all VMs in the VPC network"
Verknüpfen Sie die Richtlinie mit dem VPC-Netzwerk:
Erstellen Sie eine regionale Netzwerk-Firewallrichtlinie:
gcloud compute network-firewall-policies create \
example-firewall-policy-regional --region=region-a \
--description "Regional network firewall policy with rules that apply to all VMs in region-a"
Verknüpfen Sie die regionale Netzwerk-Firewallrichtlinie mit einem VPC-Netzwerk, um die Richtlinienregeln für alle VMs innerhalb dieses Netzwerks innerhalb einer bestimmten Region zu aktivieren:
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-01 (UTC)."],[[["\u003cp\u003eGlobal network firewall policies apply to all subnetworks in all regions of a VPC network, while regional network firewall policies apply only to subnetworks in the target region.\u003c/p\u003e\n"],["\u003cp\u003eA global network firewall policy can block all connections from external internet sources except for specified ports, delegating control of those ports to regional policies.\u003c/p\u003e\n"],["\u003cp\u003eIngress connections from specific IP ranges can be delegated by global network firewall policy rules, while connections from other sources can be directed to regional policy evaluation based on destination ports.\u003c/p\u003e\n"],["\u003cp\u003eEgress connections are allowed by default if no matching rules are found in the global network firewall policy, which implies that the implicit system rules are applied.\u003c/p\u003e\n"],["\u003cp\u003eThe provided example demonstrates how to create and associate both global and regional network firewall policies, including rules to manage ingress traffic, delegate connections, and block unwanted external connections.\u003c/p\u003e\n"]]],[],null,["# Global and regional network firewall policy examples\n\nThis page shows examples of global network firewall policy and regional network\nfirewall policy implementations. It assumes that you are familiar with the\nconcepts described in [Global network firewall policies](/firewall/docs/network-firewall-policies)\nand [Regional network firewall policies](/firewall/docs/regional-firewall-policies).\n\nYou can attach one global network firewall policy and multiple regional network\nfirewall policies to a Virtual Private Cloud (VPC) network. A global network\nfirewall policy applies to all subnetworks in all regions of the VPC\nnetwork. A regional network firewall policy applies to only the subnetworks\nof the VPC network in the target region.\n\nFigure 1 describes the scope of a global network firewall policy\nand a regional network firewall policy in a VPC network.\n[](/static/firewall/images/firewall-policies/network-firewall-policy-scope.svg) **Figure 1.** Scope of global and regional network firewall policies.\n\nExample: Deny all external connections except to specific ports\n---------------------------------------------------------------\n\nIn this use case, a global network firewall policy blocks all connections from\nexternal internet sources except for connections on destination ports `80`,\n`443`, and `22`. An ingress internet connection on ports other than `80`,\n`443`, or `22` is blocked. The rules enforcement is delegated to the regional\nnetwork firewall policy for any connections on ports `80`, `443`, or `22`.\n\nIn this example, a regional network firewall policy applies to `region-a`, which\nallows internal traffic from source `10.2.0.0/16` and ingress traffic to ports\n`443` and `80` from any source. Figure 2 describes the\nconfiguration setup for this use case.\n[](/static/firewall/images/firewall-policies/network-firewall-policy-example-01.svg) **Figure 2.** Deny all external connections except to specific destination ports.\n\n### Effective policy applied in VMs\n\nThis section describes the effective network firewall policy applicable in this\nexample after evaluating the rules across the hierarchy.\n\n**Ingress connections**\n\n- Any ingress connections from `10.0.0.0/8` match the highest priority global\n network firewall policy rule `delegate-internal-traffic` and bypass the rest\n of the rules in the global network firewall policy. In the regional network\n firewall policy rule, ingress connections from `10.2.0.0/16` are allowed, and\n the rest of the connections are evaluated against the implied ingress `deny`\n rule.\n\n- Ingress connections with a source IP range other than `10.0.0.0/8`, and\n destination ports `22`, `80`, and `443`, are delegated to the regional network\n firewall policy rule level. In the regional network firewall policy rule,\n ports `80` and `443` are allowed, but port `22` is not.\n\n**Egress connection**\n\n- There is no match across the global network firewall policy rules. Therefore, the implicit system rules apply, which allows egress connections.\n\n### How to configure\n\n1. Create a global network firewall policy that contains the following rule:\n\n ```\n gcloud compute network-firewall-policies create \\\n \"example-firewall-policy-global\" --global \\\n --description \"Global network firewall policy with rules that apply to all VMs in the VPC network\"\n ```\n2. Associate the policy with the VPC network:\n\n ```\n gcloud compute network-firewall-policies associations create \\\n --firewall-policy example-firewall-policy-global \\\n --network my-example-vpc \\\n --global-firewall-policy\n ```\n3. Add a rule to match any ingress connections from `10.0.0.0/8`:\n\n ```\n gcloud compute network-firewall-policies rules create 1000 \\\n --action goto_next \\\n --description \"delegate-internal-traffic\" \\\n --layer4-configs all \\\n --firewall-policy example-firewall-policy-global \\\n --src-ip-ranges 10.0.0.0/8 \\\n --global-firewall-policy\n ```\n4. Add a rule to delegate external traffic from specific ports:\n\n ```\n gcloud compute network-firewall-policies rules create 2000 \\\n --action goto_next \\\n --description \"delegate-external-traffic-spec-ports\" \\\n --layer4-configs tcp:80,tcp:443,tcp:22 \\\n --firewall-policy example-firewall-policy-global \\\n --src-ip-ranges 0.0.0.0/0 \\\n --global-firewall-policy\n ```\n5. Add a rule to block all remaining ingress traffic:\n\n ```\n gcloud compute network-firewall-policies rules create 3000 \\\n --action deny \\\n --description \"block-external-traffic-spec-ports\" \\\n --firewall-policy example-firewall-policy-global \\\n --src-ip-ranges 0.0.0.0/0 \\\n --layer4-configs all \\\n --global-firewall-policy\n ```\n6. Create a regional network firewall policy:\n\n ```\n gcloud compute network-firewall-policies create \\\n example-firewall-policy-regional --region=region-a \\\n --description \"Regional network firewall policy with rules that apply to all VMs in region-a\"\n ```\n7. Associate the regional network firewall policy with a VPC network\n to activate the policy rules for any VMs within that network within a specific region:\n\n ```\n gcloud compute network-firewall-policies associations create \\\n --firewall-policy example-firewall-policy-regional \\\n --network my-example-vpc \\\n --firewall-policy-region=region-a \n ```\n8. Add a rule to allow internal traffic for the regional network firewall policy:\n\n ```\n gcloud compute network-firewall-policies rules create 1000 \\\n --action allow \\\n --firewall-policy example-firewall-policy-regional \\\n --description allow-internal-traffic \\\n --direction INGRESS \\\n --src-ip-ranges 10.2.0.0/16 \\\n --layer4-configs all \\\n --firewall-policy-region=region-a \n ```\n9. Add a rule to allow external traffic from specific ports:\n\n ```\n gcloud compute network-firewall-policies rules create 2000 \\\n --action allow \\\n --firewall-policy example-firewall-policy-regional \\\n --description allow-external-traffic-spec-ports \\\n --direction INGRESS \\\n --layer4-configs=tcp:80,tcp:443 \\\n --src-ip-ranges 0.0.0.0/0 \\\n --firewall-policy-region=region-a\n ```\n\nWhat's next\n-----------\n\n- To create and modify global network firewall policies and rules, see\n [Use global network firewall policies and rules](/firewall/docs/use-network-firewall-policies).\n\n- To create and modify regional network firewall policies and rules, see\n [Use regional network firewall policies and rules](/firewall/docs/use-network-firewall-policies)."]]