É possível anexar uma política de firewall de rede global e várias políticas de firewall de rede regionais a uma rede de nuvem privada virtual (VPC). Uma política de firewall de rede global se aplica a todas as sub-redes em todas as regiões da rede VPC. Uma política de firewall de rede regional se aplica apenas às sub-redes da rede VPC na região de destino.
A Figura 1 descreve o escopo de uma política de firewall de rede global e uma política de firewall de rede regional em uma rede VPC.
Figura 1. Escopo das políticas de firewall da rede global e regional.
Exemplo: negar todas as conexões externas, exceto para portas específicas
Nesse caso de uso, uma política de firewall de rede global bloqueia todas as conexões de fontes de Internet externas, exceto para conexões nas portas 80, 443 e 22. Uma conexão de Internet de entrada em portas diferentes de 80, 443 ou 22 está bloqueada. A aplicação de regras é delegada à política de firewall da rede regional para qualquer conexão nas portas 80, 443 ou 22.
Neste exemplo, uma política de firewall de rede regional se aplica a region-a, que permite o tráfego interno da origem 10.2.0.0/16 e o tráfego de entrada para as portas 443 e 80 de qualquer origem. A figura 2 descreve a configuração deste caso de uso.
Figura 2. Negue todas as conexões externas, exceto para portas de destino específicas.
Política efetiva aplicada em VMs
Nesta seção, descrevemos a política de firewall de rede efetiva aplicável neste exemplo depois de avaliar as regras em toda a hierarquia.
Conexões de entrada
Todas as conexões de entrada de 10.0.0.0/8 correspondem à regra de política de firewall de rede global de prioridade mais alta delegate-internal-traffic e ignoram o restante das regras na política de firewall de rede global. Na regra da política de firewall da rede regional, as conexões de entrada de 10.2.0.0/16 são permitidas, e as outras conexões são avaliadas em relação à regra deny de entrada implícita.
As conexões de entrada com um intervalo de IP de origem diferente de 10.0.0.0/8 e das portas de destino 22, 80 e 443 são delegadas ao nível da regra da política de firewall da rede regional. Na regra da política de firewall de rede regional, as portas 80 e 443 são permitidas, mas a porta 22 não é.
Conexão de saída
Não há correspondência entre as regras da política de firewall de rede global. Portanto, as regras implícitas do sistema se aplicam, o que permite conexões de saída.
Como configurar
Crie uma política de firewall de rede global que contenha a seguinte regra:
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"
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"
Associe a política de firewall da rede regional a uma rede VPC para ativar as regras da política para todas as VMs nessa rede em uma região específica:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 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)."]]