Set up intrusion detection and prevention service in your network Stay organized with collections Save and categorize content based on your preferences.
Intrusion detection and prevention servicemonitors your Google Cloud workload traffic for any malicious activity andtakes preemptive actions to prevent it. To enable this service on your network,you must set up multiple Cloud Next Generation Firewall components. This tutorial describesthe end-to-end workflow to configure intrusion detection and prevention service in your network.
Objectives
This tutorial shows you how to complete the following tasks:
- Create a Virtual Private Cloud (VPC) network with two subnets.
- Create a server virtual machine (VM) instance in the first subnet of theVPC network and install the Apache server on the VM.
- Create a client VM instance in the second subnet of the VPCnetwork.
- Create a security profile and a security profile group.
- Create a firewall endpoint and associate it with the VPCnetwork.
- Add a global network firewall policy with the following firewall rules:
- A firewall rule to enable Identity-Aware Proxy (IAP) access to the VMinstances in the VPC network.
- A firewall rule to direct all ingress traffic for Layer 7 inspection.
- Verify whether malicious traffic to the server VM instance is blocked.
- Clean up the resources.
The following diagram shows the high-level architecture of the deployment setupin this tutorial. The firewall policyfw-policy-ips on VPCvpc-ips, redirects the ingress traffic to the firewall endpoint in zoneasia-southeast1-a. The firewall endpointendpoint-ips inspects the trafficfor any threats. If any threat is detected, it applies the preventive actions byusing the directions specified in the security profilesec-profile-ips.
Costs
There is a cost associated with creating the firewall endpoints. For pricingdetails, seeCloud Next Generation Firewall pricing.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- Create a project: To create a project, you need the Project Creator role (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission.Learn how to grant roles.
Verify that billing is enabled for your Google Cloud project.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- Create a project: To create a project, you need the Project Creator role (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission.Learn how to grant roles.
Verify that billing is enabled for your Google Cloud project.
- Enable theCompute Engine API for your project.
- Enable theNetwork Security API for your project.
- Enable theIdentity-Aware Proxy API for your project.
- Have theCompute Network Admin (
roles/compute.networkAdmin) IAM role on your organization. - If you prefer to work from the command line, install the Google Cloud CLI.For conceptual and installation information about the tool, seegcloud CLI overview.
Note: If you haven't run the gcloud CLI previously, firstrun
gcloud initto initializeyour gcloud CLI directory.
Create a custom VPC network with subnets
In this section, you create a custom mode VPC network with twoIPv4 subnets.
Console
In the Google Cloud console, go to theVPC networks page.
ClickCreate VPC network.
ForName, enter
vpc-ips.ForDescription, enter
VPC network to set up intrusion detection and prevention service.ForSubnet creation mode, selectCustom.
In theNew subnet section, specify the following configuration parameters for a subnet:
- Name:
subnet-ips-server - Region:
asia-southeast1 - IPv4 range:
10.0.0.0/24
- Name:
ClickDone.
ClickAdd subnet and specify the following configuration parameters:
- Name:
subnet-ips-client - Region:
us-central1 - IPv4 range:
192.168.10.0/24
- Name:
ClickDone.
ClickCreate.
gcloud
To create a VPC network, run the following command:
gcloud compute networks create vpc-ips \ --subnet-mode custom \ --description "VPC network to set up intrusion detection and prevention service."
In theAuthorize cloud shell dialog, clickAuthorize.
To create a subnet, run the following command:
gcloud compute networks subnets create subnet-ips-server \ --network vpc-ips \ --region asia-southeast1 \ --range 10.0.0.0/24
To create another subnet, run the following command:
gcloud compute networks subnets create subnet-ips-client \ --network vpc-ips \ --region us-central1 \ --range 192.168.10.0/24
Create a Cloud Router and a Cloud NAT gateway
Before you create client and server Linux VM instances without public IPv4 addresses inthe next section, you must create a Cloud Router and a Cloud NAT gateway,which enables these VMs to access the public internet.
Console
In the Google Cloud console, go to theCloud NAT page.
ClickGet started orCreate Cloud NAT gateway.
ForGateway name, enter
gateway-ips.ForNAT type, selectPublic.
In theSelect Cloud Router section, specify the following configuration parameters:
- Network:
vpc-ips - Region:
asia-southeast1 - Cloud Router:Create new router.
- ForName, enter
router-ips. - ClickCreate.
- ForName, enter
- Network:
ClickCreate.
gcloud
To create a Cloud Router, run the following command:
gcloud compute routers create router-ips \ --network=vpc-ips \ --region=asia-southeast1
To create a Cloud NAT gateway, run the following command:
gcloud compute routers nats create gateway-ips \ --router=router-ips \ --region=asia-southeast1 \ --auto-allocate-nat-external-ips \ --nat-all-subnet-ip-ranges
Create VM instances
In this section, you create server and client VM instances.
Create the server VM instance
In this section, you create a VM instance in the subnetsubnet-ips-server andinstall the Apache server on it.
Console
In the Google Cloud console, go to theCreate an instance page.
In theMachine configuration pane, do the following:
- ForName, enter
vm-server-ips. - ForRegion, select
asia-southeast1 (Singapore). - ForZone, select
asia-southeast1-a.
- ForName, enter
In the navigation menu, clickOS and Storage.
In theOperating system and storage section, verify thatImage isDebian GNU/Linux 12 (bookworm). If it isn't, clickChange and set theOperating system field toDebian and theVersion field toDebian GNU/Linux 12 (bookworm).
In the navigation menu, clickNetworking.
- In theNetwork interfaces section, click
defaultandspecify the following configuration parameters:- Network:
vpc-ips - Subnetwork:
subnet-ips-server IPv4 (10.0.0.0/24) - External IPv4 address:None
- Network:
- ClickDone.
- In theNetwork interfaces section, click
In the navigation menu, clickAdvanced and enter the following script in theStartup script field:
#! /bin/bashaptupdateapt-yinstallapache2cat<<EOF >/var/www/html/index.html<html><body><p>Helloworld.</p></body></html>EOFClickCreate.
Make a note of theExternal IP address of the server VM after it is created.
gcloud
To create the server VM, run the following command:
gcloud compute instances create vm-server-ips \ --network vpc-ips \ --zone asia-southeast1-a \ --subnet subnet-ips-server \ --stack-type IPV4_ONLY \ --image-project debian-cloud \ --image-family debian-11 \ --metadata=startup-script='#! /bin/bash apt update apt -y install apache2 cat <<EOF > /var/www/html/index.html <html><body><p>Hello World.</p></body></html> EOF'
Make a note of the external IP address of the VM in the returned status.
Create the client VM instance
In this section, you create a VM instance in the subnetsubnet-ips-client.
Console
In the Google Cloud console, go to theCreate an instance page.
In theMachine configuration pane, do the following:
- ForName, enter
vm-client-ips. - ForRegion, select
us-central1 (Iowa). - ForZone, select
us-central1-a.
- ForName, enter
In the navigation menu, clickNetworking.
- In theNetwork interfaces section, click
defaultandspecify the following configuration parameters:- Network:
vpc-ips - Subnetwork:
subnet-ips-client IPv4 (192.168.10.0/24)
- Network:
- ClickDone.
- In theNetwork interfaces section, click
ClickCreate.
gcloud
To create the client VM, run the following command:
gcloud compute instances create vm-client-ips \ --network vpc-ips \ --zone us-central1-a \ --subnet subnet-ips-client \ --stack-type IPV4_ONLY
Create a security profile
In this section, you create a security profile of typethreat-prevention inyour organization. To view the permissions required to create a securityprofile, seeCreate a threat prevention security profile.
Console
In the Google Cloud console, go to theSecurity profiles page.
In the project selector menu, select your organization.
Select theSecurity profiles tab.
ClickCreate profile.
ForName, enter
sec-profile-ips.ForDescription, enter
Security profile to set up intrusion detection and prevention service.ClickContinue.
ClickCreate.
gcloud
To create a security profile, run the following command:
gcloud network-security security-profiles \ threat-prevention \ create sec-profile-ips \ --organizationORGANIZATION_ID \ --location global \ --projectPROJECT_ID \ --description "Security profile to set up intrusion detection and prevention service."
Replace the following:
ORGANIZATION_ID: the organization where the security profile is created.PROJECT_ID: a project ID to use for quotas and access restrictions on the security profile.
Create a security profile group
In this section, you create a security profile group to include the securityprofile that you created in the preceding section. To view the permissionsrequired to create a security profile group,seePermissions required for this task.
Console
In the Google Cloud console, go to theSecurity profiles page.
In the project selector menu, select your organization.
Select theSecurity profile groups tab.
ClickCreate profile group.
ForName, enter
sec-profile-group-ips.ForDescription, enter
Security profile group to set up intrusion detection and prevention service.In theThreat prevention profile list, select
sec-profile-ips.ClickCreate.
gcloud
To create a security profile group, run the following command:
gcloud network-security security-profile-groups \ create sec-profile-group-ips \ --organizationORGANIZATION_ID \ --location global \ --projectPROJECT_ID \ --threat-prevention-profile \ organizations/ORGANIZATION_ID/locations/global/securityProfiles/sec-profile-ips \ --description "Security profile group to set up intrusion detection and prevention service."
Replace the following:
ORGANIZATION_ID: the organization where the security profile group is created.PROJECT_ID: a project ID to use for quotas and access restrictions on the security profile group.
Create a firewall endpoint
In this section you create a firewall endpoint in a specific zone. To view thepermissions required to create a firewall endpoint,seePermissions required for this task.
Note: When you create a firewall endpoint, the state ofthe firewall endpoint is set toCreating. After the firewall endpoint isready, the state changes toActive.
Console
In the Google Cloud console, go to theFirewall endpoints page.
In the project selector menu, select your organization.
ClickCreate.
In theRegion list, select
asia-southeast1 (Singapore).In theZone list, select
asia-southeast1-a.ForName, enter
endpoint-ips.ClickCreate.
gcloud
To create a firewall endpoint, run the following command:
gcloud network-security firewall-endpoints \ create endpoint-ips \ --organizationORGANIZATION_ID \ --zone asia-southeast1-a \ --billing-projectPROJECT_ID
Replace the following:
ORGANIZATION_ID: the organization where the firewall endpoint is created.PROJECT_ID: a project ID to use for the billing of the firewall endpoint.
Create a firewall endpoint association
In this section, you associate the firewall endpoint to the VPCnetwork that you created in the preceding step.
Console
In the Google Cloud console, go to theVPC networks page.
Click the
vpc-ipsnetwork to show itsVPC network details page.Select theFirewall endpoint tab.
ClickAdd endpoint association.
In theRegion list, select
asia-southeast1.In theZone list, select
asia-southeast1-a.In theFirewall endpoint list, select
endpoint-ips.ClickCreate.
gcloud
To create a firewall endpoint association, run the following command:
gcloud network-security firewall-endpoint-associations \ create endpoint-association-ips \ --endpoint organizations/ORGANIZATION_ID/locations/asia-southeast1-a/firewallEndpoints/endpoint-ips \ --network vpc-ips \ --zone asia-southeast1-a \ --projectPROJECT_ID
Replace the following:
ORGANIZATION_ID: the organization where the firewall endpoint is created.PROJECT_ID: a project ID where the association is created.
Create a global network firewall policy
In this section, you create a global network firewall policy that contains thefollowing two firewall rules:
- An ingress firewall rule with priority
100to allow TCP traffic to ports3389and22. This rule enables IAP access to the VMinstances in the VPC network. - An ingress firewall rule with priority
200to perform Layer 7 inspection onthe incoming traffic to the server VM in a specific zone.
Console
In the Google Cloud console, go to theFirewall policies page.
In the project selector list, select your project within your organization.
ClickCreate firewall policy.
ForName, enter
fw-policy-ips.ForDeployment scope, selectGlobal.
ClickContinue, and then clickAdd rule.
In thePriority field, enter
100.ForLogs, selectOn.
ForDirection of traffic, selectIngress.
ForAction on match, selectAllow.
For theSource filter, selectIPv4, and then in theIP rangefield enter
35.235.240.0/20.In theProtocols and ports section, selectSpecified protocols and ports.
SelectTCP, and forPorts, enter
22,3389.ClickCreate.
ClickAdd rule.
In thePriority field, enter
200.ForLogs, selectOn.
ForDirection of traffic, selectIngress.
ForAction on match, selectApply security profile group.
In theSecurity profile group list, select
sec-profile-group-ips.In theDestination filter, selectIPv4, and then in theIP rangefield enter the external IP address of the server VMthat you created in theCreate the server VM instancessection.
ClickCreate.
ClickContinue.
ClickAssociate policy with VPC networks.
Select
vpc-ipsnetwork.ClickAssociate.
ClickCreate.
gcloud
To create a global network firewall policy, run the following command:
gcloud compute network-firewall-policies \ create fw-policy-ips \ --global \ --projectPROJECT_ID
Replace the following:
PROJECT_ID: a project ID where the global networkfirewall policy is created.
To add the firewall rule to enable IAP access, run the following command:
gcloud compute network-firewall-policies rules create 100 \ --firewall-policy fw-policy-ips \ --direction INGRESS \ --action ALLOW \ --src-ip-ranges 35.235.240.0/20 \ --layer4-configs tcp:22, tcp:3389 \ --global-firewall-policy \ --enable-logging
To add the firewall rule to enable Layer 7 inspection for threat preventionand detection, run the following command:
gcloud compute network-firewall-policies rules create 200 \ --direction INGRESS \ --firewall-policy fw-policy-ips \ --action apply_security_profile_group \ --dest-ip-rangesSERVER_VM_IP \ --layer4-configs tcp:0-65535 \ --global-firewall-policy \ --security-profile-group \ //networksecurity.googleapis.com/organizations/ORGANIZATION_ID \ /locations/global/securityProfileGroups/sec-profile-group-ips \ --enable-logging
Replace the following:
SERVER_VM_IP: the external IP address of theserver VM that you created in theCreate the server VM instances section.ORGANIZATION_ID: the organization where the secureprofile group is created.
To associate the firewall policy with the VPC network, run thefollowing command:
gcloud compute network-firewall-policies associations create \ --firewall-policy fw-policy-ips \ --network vpc-ips \ --name fw-pol-association-ips \ --global-firewall-policy \ --projectPROJECT_ID
Replace the following:
PROJECT_ID: the project ID where theVPC association is created.
Test the setup
In this section, you test the setup by generating traffic that isintercepted by the endpoint, and the global network firewall policy is appliedto perform Layer 7 inspection.
Console
In the Google Cloud console, go to theVM instances page.
From theExternal IP column of the
vm-server-ipsVM, copy theexternal IP address of the VM.In theConnect column of the
vm-client-ipsVM, clickSSH.In theSSH-in-browser dialog, clickAuthorize and wait for theconnection to establish.
To verify whether a non-threat request isn't blocked, run the followingcommand:
curlEXTERNAL_IP -m 2
Replace
EXTERNAL_IPwith the external IP of thevm-server-ipsVM.The expected response message is as follows:
<!doctype html><html><body><h1>Hello World!</h1></body></html>To verify that a malicious request is blocked, run the following command.This command sends a request to access the password file, which isforbidden.
curl -m 2EXTERNAL_IP:80/cgi-bin/../../../../bin/cat%20/etc/passwd/
Replace
EXTERNAL_IPwith the external IP ofvm-server-ipsVM.A
Connection timed outmessage is expected because the firewall endpointdetects the threat in the request and blocks the packet.Close theSSH-in-browser dialog.
gcloud
To connect to the
vm-client-ipsVM, run the following command:gcloud compute ssh vm-client-ips \ --zone=us-central1-a \ --tunnel-through-iap
When prompted, pressY to confirm, and then pressEnter.
Note: While the SSH to thevm-client-ipsVM is connected, ignore any warning messages that you see.To verify whether a non-threat request isn't blocked, run the following command:
curlEXTERNAL_IP -m 2
Replace
EXTERNAL_IPwith the external IP of thevm-server-ipsVM.The expected response message is as follows:
<!doctype html><html><body><h1>Hello World!</h1></body></html>To verify that a malicious request is blocked, run the following command:
curl -m 2EXTERNAL_IP:80/cgi-bin/../../../../bin/cat%20/etc/passwd/
Replace
EXTERNAL_IPwith the external IP of thevm-server-ipsVM.A
Connection timed outmessage is expected because the firewall endpointdetects the threat in the request and blocks the packet.To close theSSH-in-browser, enter
exit.
View the threat logs
In the Google Cloud console, go to theThreats page.
If necessary, select your Google Cloud project.
In theThreat section, you can see the logs entry for the threatdetected on your
vpc-ipsnetwork.
Clean up
To avoid incurring charges to your Google Cloud account for the resourcesused in this tutorial, either delete the project that contains the resources,or keep the project and delete the individual resources.
In this section, you delete the resources created in this tutorial.
Delete the firewall endpoint association
Console
In the Google Cloud console, go to theVPC networks page.
Click the
vpc-ipsnetwork to show itsVPC network details page.Select theFirewall endpoint tab. The tab shows a list of configuredfirewall endpoint associations.
Select the checkbox next to
endpoint-ips, and then clickDelete.ClickDelete again to confirm.
gcloud
To delete the firewall endpoint association, run the following command:
gcloud network-security firewall-endpoint-association \ delete endpoint-ips \ --zone asia-southeast1-a
Delete the firewall endpoint
Console
In the Google Cloud console, go to theFirewall endpoints page.
Select
endpoint-ips, and then clickDelete.ClickDelete again to confirm.
gcloud
To delete the firewall endpoint, run the following commands:
gcloud network-security firewall-endpoints delete endpoint-ips \ --organizationORGANIZATION_ID \ --zone asia-southeast1-a
Replace the following:
ORGANIZATION_ID: the organization where the endpoint is created.
Delete the global network firewall endpoint policy
Console
In the Google Cloud console, go to theFirewall policies page.
In the project selector menu, select your project that contains the policy.
Click
fw-policy-ips.Click theAssociations tab.
Select all associations.
ClickRemove Associations.
After all associations are removed, clickDelete.
gcloud
To remove the association between firewall policy and VPCnetwork, run the following command:
Note: If you set up the association between the firewall policy and the VPC network through Google Cloud console, don't use the gcloud CLI command to remove the association. If you can't remember how you created the association or get thegcloud compute network-firewall-policies associations delete \ --name fw-pol-association-ips \ --firewall-policy fw-policy-ips \ --global-firewall-policy
The network firewall policy does not have an association with pol-association-fw-ruleserror when you run the command, use the Google Cloud console to remove the association.Delete the firewall policy.
gcloud compute network-firewall-policies delete fw-policy-ips --global
When prompted, pressY to confirm, and then pressEnter.
Delete the security profile group
Console
In the Google Cloud console, go to theSecurity profiles page.
Select theSecurity profile groups tab.
Select
sec-profile-group-ips, and then clickDelete.ClickDelete again to confirm.
gcloud
To delete the security profile group, run the following command:
gcloud network-security security-profile-groups \ delete sec-profile-group-ips \ --organizationORGANIZATION_ID \ --location global
Replace the following:
ORGANIZATION_ID: the organization where the securityprofile group is created.
Delete the security profile
Console
In the Google Cloud console, go to theSecurity profiles page.
Select theSecurity profiles tab. The tab shows a list of configuredsecurity profiles.
Select
sec-profile-ips, and then clickDelete.ClickDelete again to confirm.
gcloud
To delete the security profile, run the following command:
gcloud network-security security-profiles threat-prevention \ delete sec-profile-ips \ --organizationORGANIZATION_ID \ --location global
Replace the following:
ORGANIZATION_ID: the organization where the securityprofile is created.
Delete the VMs
Console
In the Google Cloud console, go to theVM instances page.
Select the checkboxes of both the
vm-client-ipsandvm-server-ipsVMs.ClickDelete.
In theDelete 2 instances? dialog, clickDelete.
gcloud
To delete the
vm-client-ipsVM, run the following command:gcloud compute instances delete vm-client-ips \ --zone us-central1-a
When prompted, pressY to confirm, and then pressEnter.
To delete the
vm-server-ipsVM, run the following command:gcloud compute instances delete vm-server-ips \ --zone asia-southeast1-a
When prompted, pressY to confirm, and then pressEnter.
Delete the VPC network and its subnets
Console
In the Google Cloud console, go to theVPC networks page.
In theName column, click
vpc-ips.ClickDelete VPC network.
In theDelete a network dialog, clickDelete.
When you delete a VPC, its subnets are also deleted.
gcloud
To delete the subnet
subnet-ips-clientof thevpc-ipsVPC network,run the following command:gcloud compute networks subnets delete subnet-ips-client \ --region us-central1
When prompted, pressY to confirm, and then pressEnter.
To delete the subnet
subnet-ips-serverof thevpc-ipsVPC network,run the following command:gcloud compute networks subnets delete subnet-ips-server \ --region=asia-southeast1
When prompted, pressY to confirm, and then pressEnter.
To delete the
vpc-ipsVPC network, run the following command:gcloud compute networks delete vpc-ips
What's next
- For conceptual information about intrusion detection and prevention service, seeIntrusion detection and prevention service overview.
- For conceptual information about firewall policies, seeFirewall policies.
- For conceptual information about firewall policy rules, seeFirewall policy rules.
- To determine costs, seeCloud NGFW pricing.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-16 UTC.