Created
April 11, 2018 21:36
-
-
Save jmcdice/d0e06e990f6674e6927bf9a0baa1de33 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Have you ever deleted the default fw rules in your gcp project? | |
# Of course you have! Here's how to re-create them. | |
PROJECT='' | |
function create_default_ruleset() { | |
# Allow ICMP from Anywhere | |
gcloud compute --project=${PROJECT} firewall-rules create \ | |
default-allow-icmp --description=Allow\ ICMP\ --direction=INGRESS \ | |
--priority=65534 --network=default --action=ALLOW \ | |
--rules=icmp --source-ranges=0.0.0.0/0 | |
# default-allow-internal | |
gcloud compute --project=${PROJECT} firewall-rules create \ | |
default-allow-internal --description=Allow\ internal\ traffic\ on\ the\ default\ network \ | |
--direction=INGRESS --priority=65534 --network=default --action=ALLOW \ | |
--rules=tcp:0-65535,udp:0-65535,icmp --source-ranges=10.128.0.0/9 | |
# RDP | |
gcloud compute --project=${PROJECT} firewall-rules create \ | |
default-allow-rdp --description=Allow\ RDP\ from\ anywhere --direction=INGRESS \ | |
--priority=65534 --network=default --action=ALLOW \ | |
--rules=tcp:3389 --source-ranges=0.0.0.0/0 | |
# SSH | |
gcloud compute --project=${PROJECT} firewall-rules create \ | |
default-allow-ssh --description=Allow\ SSH\ from\ anywhere --direction=INGRESS \ | |
--priority=65534 --network=default --action=ALLOW \ | |
--rules=tcp:22 --source-ranges=0.0.0.0/0 | |
} | |
function delete_default_ruleset() { | |
# Might or might need to do this.. just to be tidy tho.. | |
gcloud compute firewall-rules delete default-allow-icmp | |
gcloud compute firewall-rules delete default-allow-internal | |
gcloud compute firewall-rules delete default-allow-rdp | |
gcloud compute firewall-rules delete default-allow-ssh | |
} | |
delete_default_ruleset | |
create_default_ruleset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment