gcloud compute firewall-rules create NAME (--action=ACTION | --allow=PROTOCOL[:PORT[-PORT]],[…]) [--description=DESCRIPTION] [--destination-ranges=CIDR_RANGE,[CIDR_RANGE,…]] [--direction=DIRECTION] [--disabled] [--[no-]enable-logging] [--logging-metadata=LOGGING_METADATA] [--network=NETWORK; default="default"] [--priority=PRIORITY] [--resource-manager-tags=[KEY=VALUE,…]] [--rules=PROTOCOL[:PORT[-PORT]],[…]] [--source-ranges=CIDR_RANGE,[CIDR_RANGE,…]] [--source-service-accounts=EMAIL,[EMAIL,…]] [--source-tags=TAG,[TAG,…]] [--target-service-accounts=EMAIL,[EMAIL,…]] [--target-tags=TAG,[TAG,…]] [GCLOUD_WIDE_FLAG …]
gcloud compute firewall-rules create is used to create firewall
rules to allow/deny incoming/outgoing traffic.
gcloud compute firewall-rules create example-service --allow=tcp:8080 --description="Allow incoming traffic on TCP port 8080" --direction=INGRESSTo create a firewall rule that allows TCP traffic through port 80 and determines a list of specific IP address blocks that are allowed to make inbound connections, run:
gcloud compute firewall-rules create tcp-rule --allow=tcp:80 --source-ranges="10.0.0.0/22,10.0.0.0/14" --description="Narrowing TCP traffic"To list existing firewall rules, run:
gcloud compute firewall-rules listNAME--action=ACTION--rules must also be specified.
ACTION must be one of: ALLOW,
DENY.
--allow=PROTOCOL[:PORT[-PORT]],[…]
The protocols allowed over this connection. This can be the (case-sensitive)
string values tcp, udp, icmp,
esp, ah, sctp, or any IP protocol number.
An IP-based protocol must be specified for each rule. The rule applies only to
specified protocol.
For port-based protocols - tcp, udp, and
sctp - a list of destination ports or port ranges to which the rule
applies may optionally be specified. If no port or port range is specified, the
rule applies to all destination ports.
The ICMP protocol is supported, but there is no support for configuring ICMP packet filtering by ICMP code.
For example, to create a rule that allows TCP traffic through port 80 and ICMP traffic:
gcloud compute firewall-rules create MY-RULE --allow tcp:80,icmpTo create a rule that allows TCP traffic from port 20000 to 25000:
gcloud compute firewall-rules create MY-RULE --allow tcp:20000-25000To create a rule that allows all TCP traffic:
gcloud compute firewall-rules create MY-RULE --allow tcp--description=DESCRIPTION--destination-ranges=CIDR_RANGE,[CIDR_RANGE,…]--direction=DIRECTIONFor convenience, 'IN' can be used to represent ingress direction and 'OUT' can be used to represent egress direction.
DIRECTION must be one of: INGRESS,
EGRESS, IN, OUT.
--disabledgcloud compute firewall-rules update MY-RULE --no-disabled--[no-]enable-logginggcloud compute firewall-rules create MY-RULE --enable-loggingTo disable logging on an existing rule, run:
gcloud compute firewall-rules create MY-RULE --no-enable-logging--enable-logging to enable and --no-enable-logging
to disable.
--logging-metadata=LOGGING_METADATALOGGING_METADATA must be one of:
exclude-all, include-all.
--network=NETWORK; default="default"default network.
--priority=PRIORITY--resource-manager-tags=[KEY=VALUE,…]--rules=PROTOCOL[:PORT[-PORT]],[…]PROTOCOL is the IP protocol whose traffic will be checked. PROTOCOL can be either the name of a well-known protocol (e.g., tcp or icmp) or the IP protocol number. A list of IP protocols can be found at http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
A port or port range can be specified after PROTOCOL to which the firewall rule apply on traffic through specific ports. If no port or port range is specified, connections through all ranges are applied. TCP and UDP rules must include a port or port range.
If specified, the flag --action must also be specified.
For example, the following will create a rule that blocks TCP traffic through port 80 and ICMP traffic:
gcloud compute firewall-rules create MY-RULE --action deny --rules tcp:80,icmp--source-ranges=CIDR_RANGE,[CIDR_RANGE,…]
If neither --source-ranges nor --source-tags are specified, --source-ranges
defaults to 0.0.0.0/0, which means that the rule applies to all
incoming IPv4 connections from inside or outside the network. If both
--source-ranges and --source-tags are specified, the rule matches if either the
range of the source matches --source-ranges or the tag of the source matches
--source-tags.
--source-service-accounts=EMAIL,[EMAIL,…]--source-tags=TAG,[TAG,…]0.0.0.0/0,
which means that the rule applies to all incoming IPv4 connections from inside
or outside the network.
If both --source-ranges and --source-tags are specified, an inbound connection is allowed if either the range of the source matches --source-ranges or the tag of the source matches --source-tags.
Tags can be assigned to instances during instance creation.
If source tags are specified then neither a source nor target service account can also be specified.--target-service-accounts=EMAIL,[EMAIL,…]--target-tags=TAG,[TAG,…]If target tags are specified, then neither a source nor target service account can also be specified.
If both target tags and target service account are omitted, all instances on the network can receive connections that match the rule.--access-token-file,
--account, --billing-project,
--configuration,
--flags-file,
--flatten, --format, --help, --impersonate-service-account,
--log-http,
--project, --quiet, --trace-token, --user-output-enabled,
--verbosity.
Run $ gcloud help for details.
gcloud alpha compute firewall-rules creategcloud beta compute firewall-rules creategcloud preview compute firewall-rules create
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-05-27 UTC.