Skip to content

Instantly share code, notes, and snippets.

@embarq
Created November 28, 2019 11:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save embarq/127d94882f0647449a4802ee2906d639 to your computer and use it in GitHub Desktop.
Save embarq/127d94882f0647449a4802ee2906d639 to your computer and use it in GitHub Desktop.
GCloud Compute Engine: add multiple firewall rules for desired TCP ports
#!/bin/bash
BASE_RULE_NAME="rule-allow-tcp"
TARGET_NET_TAG="frontserver" # For more info see https://cloud.google.com/vpc/docs/add-remove-network-tags
for PORT in 4201 4202 4203 4204 4205 4206 4207 4208 4209
do
# See reference https://cloud.google.com/vpc/docs/using-firewalls
gcloud compute firewall-rules create $BASE_RULE_NAME-$PORT \
--source-ranges 0.0.0.0/0 \
--allow tcp:$PORT \
--target-tags=$TARGET_NET_TAG
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment