Create Firewall Rule in Google Cloud Platform
A firewall rule is required to access the resources in a network. To create firewall rule in Google Cloud Platform, please login to your GCP portal. Go to the Networking section of the portal and click the “Firewall rules“. Under the “Firewall rules” page, click the “CREATE FIREWALL RULE” link.
Once you are in the “Create a firewall rule” page, provide a name for your firewall rule. In our case, we are giving it as ssh-rdp. Under the description, provide a snippet that describes your firewall rule.
Select the network from the drop down menu, for which you wish to create the firewall rule. In the Source Filter drop down menu, select the IP ranges. Then under the Source IP ranges, enter the IP address with its corresponding mask, so that only those IPs will be allowed to access your resources in this network. Under the Allowed protocols and ports section, mention the ports to be opened. If you wish allow TCP port 3389, then mention as tcp:3389. For an udp port 755, mention it as udp:755. Click the button “Create” to create the firewall rule.
Once the rule is created, the Firewall rules page will list the rule created, like the one below.
gshell method to create firewall rule in GCP
Easiest way of creating a firewall rule in Google Cloud Platform, is to use the gshell. Gshell is fairly easy to use and work with. Please use the below command after connecting to gshell prompt.
gcloud compute --project "<Your GCP project ID>" firewall-rules create "<Provide the firewall name>" --allow <Provide ports with protocols to be allowed> --description "<Description of firewall rule here>" --network "<Provide the network name here>" --source-ranges "<Provide the IP range to be allowed here>"
gcloud compute --project "composite-drive-123456" firewall-rules create "ssh-rdp" --allow tcp:3389,tcp:22 --description "Allow SSH and RDP Access to front end network" --network "frontend-network" --source-ranges "123.456.789.123/32"