Scenario C: Public and Private Subnets with a VPN

This topic explains how to set up Scenario C, which is a simple example of a multi-tier setup. It consists of a virtual cloud network (VCN) with a regional public subnet  to hold public servers (such as web servers), and a regional private subnet  to hold private servers (such as database servers). There are servers in separate availability domains  for redundancy.

The VCN has a dynamic routing gateway  (DRG) and IPSec VPN  for connectivity to your on-premises network. Instances in the public subnet have direct access to the internet by way of an internet gateway . Instances in the private subnet can initiate connections to the internet by way of a NAT gateway  (for example, to get software updates), but cannot receive inbound connections from the internet through that gateway.

Each subnet uses the default security list, which has default rules that are designed to make it easy to get started with Oracle Cloud Infrastructure. The rules enable typical required access (for example, inbound SSH connections and any type of outbound connections). Remember that security list rules only allow traffic. Any traffic not explicitly covered by a security list rule is denied.

Tip

Security lists are one way to control traffic in and out of the VCN's resources. You can also use network security groups, which let you apply a set of security rules to a set of resources that all have the same security posture.

Each subnet also has its own custom security list and custom route table with rules specific to the needs of the subnet's instances. In this scenario, the VCN's default route table (which is always empty to start with) is not used.

See the following figure.

This image shows Scenario C: a VCN with both a public and private subnet, an internet gateway, NAT gateway, and a VPN IPSec connection.

Tip

The scenario uses an IPSec VPN for connectivity. However, you could instead use Oracle Cloud Infrastructure FastConnect.

Prerequisites

To set up the VPN in this scenario, you need to get the following information from a network administrator:

  • Public IP address of the customer-premises equipment  (CPE) at your end of the VPN
  • Static routes for your on-premises network (this scenario uses static routing for the VPN tunnels, but you could instead use BGP dynamic routing)

You will provide Oracle this information and in return receive the information your network administrator needs in order to configure the on-premises router at your end of the VPN.

Required IAM Policy

To use Oracle Cloud Infrastructure, you must be given the required type of access in a policy  written by an administrator, whether you're using the Console or the REST API with an SDK, CLI, or other tool. If you try to perform an action and get a message that you don’t have permission or are unauthorized, confirm with your administrator the type of access you've been granted and which compartment  you should work in.

If you're a member of the Administrators group, you already have the required access to execute Scenario C. Otherwise, you need access to Networking, and you need the ability to launch instances. See IAM Policies for Networking.

Setting Up Scenario C

Setup is easy in the Console. Alternatively, you can use the Oracle Cloud Infrastructure API, which lets you execute the individual operations yourself.

Warning

Avoid entering confidential information when assigning descriptions, tags, or friendly names to your cloud resources through the Oracle Cloud Infrastructure Console, API, or CLI.
Important

Most of this process involves working with the Console or API (whichever you choose) for a short period to set up the desired Networking components. But there's also a critical step that requires a network administrator in your organization to take information you receive from setting up the components and use it to configure the on-premises router at your end of the VPN. Therefore you can't complete this process in one short session. You'll need to break for an unknown period of time while the network administrator completes the configuration and then return afterward to confirm communication with your instances over the VPN.

Using the Console

Task 1: Set up the VCN and subnets
  1. Create the VCN:

    1. Open the navigation menu. Under Core Infrastructure, go to Networking and click Virtual Cloud Networks.
    2. Choose a compartment you have permission to work in (on the left side of the page). The page updates to display only the resources in that compartment. If you're not sure which compartment to use, contact an administrator. For more information, see Access Control.
    3. Click Create Virtual Cloud Network.
    4. Enter the following:

      • Name: A friendly name for the VCN. It doesn't have to be unique, and it cannot be changed later in the Console (but you can change it with the API). Avoid entering confidential information.
      • Create in Compartment: Leave as is.
      • CIDR Block: A single, contiguous CIDR block for the VCN. For example: 172.16.0.0/16. You cannot change this value later. See Allowed VCN Size and Address Ranges. For reference, here's a CIDR calculator.
      • Enable IPv6 Address Assignment: This option is available only if the VCN is in the US Government Cloud. For more information, see IPv6 Addresses.
      • Use DNS Hostnames in this VCN: Required for assignment of DNS hostnames to hosts in the VCN, and required if you plan to use the VCN's default DNS feature (called the Internet and VCN Resolver). If the check box is selected, you can specify a DNS label for the VCN, or the Console will generate one for you. The dialog box automatically displays the corresponding DNS Domain Name for the VCN (<VCN DNS label>.oraclevcn.com). For more information, see DNS in Your Virtual Cloud Network.
      • Tags: Leave as is. You can add tags later if you want. For more information, see Resource Tags.
    5. Click Create Virtual Cloud Network.

      The VCN is then created and displayed on the Virtual Cloud Networks page in the compartment you chose.

  2. Create an internet gateway for your VCN:

    1. Under Resources, click Internet Gateways.
    2. Click Create Internet Gateway.
    3. Enter the following:

      • Name: A friendly name for the internet gateway. It doesn't have to be unique, and it cannot be changed later in the Console (but you can change it with the API). Avoid entering confidential information.
      • Create in Compartment: Leave as is.
      • Tags: Leave as is. You can add tags later if you want. For more information, see Resource Tags.
    4. Click Create Internet Gateway.

      The internet gateway is then created and listed on the page.

  3. Create a NAT gateway for your VCN:

    1. Under Resources, click NAT Gateways.
    2. Click Create NAT Gateway.
    3. Enter the following:

      • Name: A friendly name for the NAT gateway. It doesn't have to be unique, and it cannot be changed later in the Console (but you can change it with the API). Avoid entering confidential information.
      • Create in Compartment: Leave as is.
      • Tags: Leave as is. You can add tags later if you want. For more information, see Resource Tags.
    4. Click Create NAT Gateway.

      The NAT gateway is then created and listed on the page.

  4. Create the custom route table for the public subnet (which you will create later):

    1. Under Resources, click Route Tables.
    2. Click Create Route Table.
    3. Enter the following:

      • Name: A friendly name for the route table (for example, Public Subnet Route Table). It doesn't have to be unique, and it cannot be changed later in the Console (but you can change it with the API). Avoid entering confidential information.
      • Create in Compartment: Leave the default value (the compartment you're currently working in).
      • Click + Additional Route Rule and enter the following:

        • Target Type: Internet Gateway.
        • Destination CIDR Block: 0.0.0.0/0 (which means that all non-intra-VCN traffic that is not already covered by other rules in the route table will go to the target specified in this rule).
        • Compartment: Leave as is.
        • Target: The internet gateway you just created.
        • Description: An optional description of the rule.
    4. Tags: Leave as is. You can add tags later if you want. For more information, see Resource Tags.
    5. Click Create Route Table.

      The route table is then created and listed on the page.

  5. Create the custom route table for the private subnet (which you will create later):

    1. Click Create Route Table.
    2. Enter the following:

      • Name: A friendly name for the route table (for example, Private Subnet Route Table). It doesn't have to be unique, and it cannot be changed later in the Console (but you can change it with the API). Avoid entering confidential information.
      • Create in Compartment: Leave the default value (the compartment you're currently working in).
      • Click + Additional Route Rule and enter the following:

        • Target Type: NAT Gateway.
        • Destination CIDR Block: 0.0.0.0/0 (which means that all non-intra-VCN traffic that is not already covered by other rules in the route table will go to the target specified in this rule).
        • Compartment: Leave as is.
        • Target: The NAT gateway you just created.
        • Description: An optional description of the rule.
    3. Tags: Leave as is. You can add tags later if you want. For more information, see Resource Tags.
    4. Click Create Route Table.

      The route table is then created and listed on the page. Later on after you've set up the IPSec VPN, you will update the Private Subnet Route Table so it routes traffic from the private subnet to the on-premises network by way of the DRG.

  6. Update the default security list to include rules to allow the types of connections that your instances in the VCN will need:

    1. Under Resources, click Security Lists.
    2. Click the default security list to view its details. By default, you land on the Ingress Rules page.
    3. Edit each of the existing stateful ingress rules so that the Source CIDR is the CIDR for your on-premises network (10.0.0.0/16 in this example) and not 0.0.0.0/0. To edit an existing rule, click the Actions icon (three dots) for the rule, and then click Edit.
    4. If you plan to launch Windows instances, add a rule to enable RDP access:

  7. Create a custom security list for the public subnet:

    1. Return to the Security Lists page for the VCN.
    2. Click Create Security List.
    3. Enter the following:

      • Name: Enter a friendly name for the list (for example, Public Subnet Security List). It doesn't have to be unique, and it cannot be changed later in the Console (but you can change it with the API). Avoid entering confidential information.
      • Create in Compartment: Leave the default value (the compartment you're currently working in).
    4. Add the following ingress rules:

      Example: Ingress HTTP access
      • Type: Ingress
      • Stateless: Unselected (this is a stateful rule)
      • Source Type: CIDR
      • Source CIDR: 0.0.0.0/0
      • IP Protocol: TCP
      • Source Port Range: All
      • Destination Port Range: 80
      • Description: An optional description of the rule.
      Example: Ingress HTTPS access
      • Type: Ingress
      • Stateless: Unselected (this is a stateful rule)
      • Source Type: CIDR
      • Source CIDR: 0.0.0.0/0
      • IP Protocol: TCP
      • Source Port Range: All
      • Destination Port Range: 443
      • Description: An optional description of the rule.
    5. Add the following egress rule:

    6. Click Create Security List.

      The custom security list for the public subnet is then created and listed on the page.

  8. Create a custom security list for the private subnet:

    1. Click Create Security List.
    2. Enter the following:

      • Name: Enter a friendly name for the list (for example, Private Subnet Security List). It doesn't have to be unique, and it cannot be changed later in the Console (but you can change it with the API). Avoid entering confidential information.
      • Create in Compartment: Leave the default value (the compartment you're currently working in).
    3. Add the following ingress rules:

      Example: Ingress SQL*Net access from clients in the public subnet
      • Type: Ingress
      • Stateless: Unselected (this is a stateful rule)
      • Source Type: CIDR
      • Source CIDR: CIDR for the public subnet (172.16.2.0/24 in this example)
      • IP Protocol: TCP
      • Source Port Range: All
      • Destination Port Range: 1521
      • Description: An optional description of the rule.
      Example: Ingress SQL*Net access from clients in the private subnet
      • Type: Ingress
      • Stateless: Unselected (this is a stateful rule)
      • Source Type: CIDR
      • Source CIDR: CIDR for the private subnet (172.16.2.1/24 in this example)
      • IP Protocol: TCP
      • Source Port Range: All
      • Destination Port Range: 1521
      • Description: An optional description of the rule.
    4. Add the following egress rules:

    5. Click Create Security List.

      The custom security list for the private subnet is then created and listed on the page.

  9. Create the subnets in the VCN:

    1. Under Resources, click Subnets.
    2. Click Create Subnet.
    3. Enter the following:

      • Name: A friendly name for the regional public subnet (for example, Regional Private Subnet). It doesn't have to be unique, and it cannot be changed later in the Console (but you can change it with the API). Avoid entering confidential information.
      • Regional or Availability Domain-Specific: Select Regional (recommended), which means the subnet spans all availability domains in the region. Later when you launch an instance, you can create it any availability domain in the region. For more information, see Overview of VCNs and Subnets.
      • CIDR Block: A single, contiguous CIDR block within the VCN's CIDR block. For example: 172.16.1.0/24. You cannot change this value later. For reference, here's a CIDR calculator.
      • Enable IPv6 Address Assignment: This option is available only if the VCN is in the US Government Cloud. For more information, see IPv6 Addresses.
      • Route Table: Select the Private Subnet Route Table you created earlier.
      • Private or public subnet: Select Private Subnet, which means VNICs in the subnet are not allowed to have public IP addresses. For more information, see Access to the Internet.
      • Use DNS Hostnames in this Subnet: This option is available only if you provided a DNS label for the VCN during creation. The option is required for assignment of DNS hostnames to hosts in the subnet, and required if you plan to use the VCN's default DNS feature (called the Internet and VCN Resolver). If the check box is selected, you can specify a DNS label for the subnet, or the Console will generate one for you. The dialog box automatically displays the corresponding DNS Domain Name for the subnet (<subnet_DNS_label>.<VCN_DNS_label>.oraclevcn.com). For more information, see DNS in Your Virtual Cloud Network.
      • DHCP Options: Select the default set of DHCP options.
      • Security Lists: Select two security lists: Both the default security list and the Private Subnet Security List you created earlier.
    4. Click Create Subnet.

      The private subnet is then created and displayed on the Subnets page.

    5. Repeat the preceding steps a-d to create the regional public subnet. Instead use a name such as Regional Public Subnet, select Public Subnet instead of Private Subnet, use the Public Subnet Route Table, and use both the default security list and Public Subnet Security List you created earlier.
Example: Ingress RDP access required for Windows instances
  • Type: Ingress
  • Stateless: Unselected (this is a stateful rule)
  • Source Type: CIDR
  • Source CIDR: Your on-premises network (10.0.0.0/16 in this example)
  • IP Protocol: TCP
  • Source Port Range: All
  • Destination Port Range: 3389
  • Description: An optional description of the rule.
Example: Egress SQL*Net access to Oracle databases
  • Type: Egress
  • Stateless: Unselected (this is a stateful rule)
  • Destination Type: CIDR
  • Destination CIDR: CIDR for the private subnet (172.16.1.0/24 in this example)
  • IP Protocol: TCP
  • Source Port Range: All
  • Destination Port Range: 1521
  • Description: An optional description of the rule.
Example: Egress SQL*Net access to instances in the private subnet
  • Type: Egress
  • Stateless: Unselected (this is a stateful rule)
  • Destination Type: CIDR
  • Destination CIDR: CIDR for the private subnet (172.16.1.0/24 in this example)
  • IP Protocol: TCP
  • Source Port Range: All
  • Destination Port Range: 1521
  • Description: An optional description of the rule.
Task 2: Create instances in separate availability domains

You can now create one or more instances in the subnet (see Launching an Instance). The scenario's diagram shows instances in two different availability domains. When you create the instance, you choose the AD, which VCN and subnet to use, and several other characteristics.

For each instance in the public subnet, make sure to assign the instance a public IP address. Otherwise, you won't be able to reach the instance from your on-premises network.

You can't yet reach the instances in the private subnet because there's no gateway connecting the VCN to your on-premises network. The next procedure walks you through creating an IPSec VPN connection to enable that communication.

Task 3: Add an IPSec VPN to your VCN
  1. Create a customer-premises equipment object:

    1. Open the navigation menu. Under Core Infrastructure, go to Networking and click Customer-Premises Equipment.

    2. Click Create Customer-Premises Equipment.
    3. Enter the following:

      • Create in Compartment: Leave the default value (the compartment you're currently working in).
      • Name: A friendly name for the customer-premises equipment object. It doesn't have to be unique, and it cannot be changed later in the Console (but you can change it with the API). Avoid entering confidential information.
      • IP Address: The IP address of the on-premises router at your end of the VPN (see Prerequisites).
    4. Click Create.

    The CPE object is in the "Provisioning" state for a short period.

  2. Create a dynamic routing gateway (DRG):

    1. Open the navigation menu. Under Core Infrastructure, go to Networking and click Dynamic Routing Gateways.

    2. Click Create Dynamic Routing Gateway.
    3. For Create in Compartment: Leave the default value (the compartment you're currently working in).
    4. Enter a friendly name for the DRG. It doesn't have to be unique, and it cannot be changed later in the Console (but you can change it with the API). Avoid entering confidential information.
    5. Click Create.

    The DRG will be in the "Provisioning" state for a short period. Make sure it is done being provisioned before continuing.

  3. Attach the DRG to your VCN:

    1. Click the DRG that you just created.
    2. Under Resources, click Virtual Cloud Networks.
    3. Click Attach to Virtual Cloud Network.
    4. Select the VCN. Ignore the section for advanced options, which is only for an advanced routing scenario called transit routing, which is not relevant here.
    5. Click Attach.

    The attachment will be in the "Attaching" state for a short period before it's ready.

  4. Update the private subnet's route table (which already has one rule for the NAT gateway):

    1. Open the navigation menu. Under Core Infrastructure, go to Networking and click Virtual Cloud Networks.
    2. Click your VCN.
    3. Click Route Tables, and then click the Private Subnet Route Table you created earlier.
    4. Click Add Route Rule.
    5. Enter the following:

      • Target Type: Dynamic Routing Gateway. The VCN's attached DRG is automatically selected as the target, and you don't have to specify the target yourself.
      • Destination CIDR Block: 0.0.0.0/0 (which means that all non-intra-VCN traffic that is not already covered by other rules in the route table will go to the target specified in this rule).
      • Description: An optional description of the rule.
    6. Click Add Route Rule.

      The table is updated to route any traffic destined for your on-premises network to the DRG. The original rule for 0.0.0.0/0 routes any remaining traffic leaving the subnet to the NAT gateway.

  5. Create an IPSec Connection:

    1. Open the navigation menu. Under Core Infrastructure, go to Networking and click IPSec Connections.

    2. Click Create IPSec Connection.
    3. Enter the following:

      • Create in Compartment: Leave the default value (the compartment you're currently working in).
      • Name: Enter a friendly name for the IPSec connection. It doesn't have to be unique. Avoid entering confidential information.
      • Customer-Premises Equipment Compartment: Leave as is (the VCN's compartment).
      • Customer-Premises Equipment: Select the CPE object you created earlier.
      • Dynamic Routing Gateway Compartment: Leave as is (the VCN's compartment).
      • Dynamic Routing Gateway: Select the DRG that you created earlier.
      • Static Route CIDR: Enter at least one static route CIDR (see Prerequisites). If you need to add another, click Add Static Route. You can enter up to 10 static routes, and you can change the static routes later if you like.
    4. Click Show Advanced Options and optionally provide the following items:
    5. Click Create IPSec Connection.

      The IPSec connection is created and displayed on the page. It will be in the Provisioning state for a short period.

      The displayed tunnel information includes the IP address of the VPN headend and the tunnel's IPSec status (possible values are Up, Down, and Down for Maintenance). At this point, the status is Down. To view the tunnel's shared secret, click the Actions icon (three dots), and then click View Shared Secret.

    6. Copy the Oracle VPN IP address and shared secret for each of the tunnels to an email or other location so you can deliver it to the network engineer who will configure the on-premises router.

      For more information, see CPE Configuration. You can view this tunnel information here in the Console at any time.

You have now created all the components required for the IPSec VPN. But your network administrator must configure the on-premises router before network traffic can flow between your on-premises network and VCN.

Task 4: Configure your on-premises router (CPE)

These instructions are for the network administrator.

  1. Make sure you have the tunnel configuration information that Oracle provided during VPN setup. See Task 3: Add an IPSec VPN to your VCN.
  2. Configure your on-premises router according to the information in CPE Configuration.

If there are already instances in one of the subnets, you can confirm the IPSec connection is up and running by connecting to the instances from your on-premises network. To connect to instances in the public subnet, you must connect to the instance's public IP address.

Using the API

For information about using the API and signing requests, see REST APIs and Security Credentials. For information about SDKs, see Software Development Kits and Command Line Interface.

Use the following operations:

  1. CreateVcn: Make sure to include a DNS label if you want the VCN to use the VCN Resolver (see DNS in Your Virtual Cloud Network).
  2. CreateInternetGateway
  3. CreateNatGateway
  4. CreateRouteTable: Call it to create the Public Subnet Route Table. To enable communication by way of the internet gateway, add a route rule with destination = 0.0.0.0/0, and destination target = the internet gateway you created earlier.
  5. CreateRouteTable: Call it again to create the Private Subnet Route Table. To enable communication by way of the NAT gateway, add a route rule with destination = 0.0.0.0/0, and destination target = the NAT gateway you created earlier.
  6. First call GetSecurityList to get the default security list, and then call UpdateSecurityList:

    • Change the existing stateful ingress rules to use your on-premises network's CIDR as the source CIDR, instead of 0.0.0.0/0.
    • If you plan to launch Windows instances, add this stateful ingress rule: Source type = CIDR, source CIDR = your on-premises network on TCP, source port = all, destination port = 3389 (for RDP).
  7. CreateSecurityList: Call it to create the Public Subnet Security List with these rules:

    • Stateful ingress: Source type = CIDR, source 0.0.0.0/0 on TCP, source port = all, destination port = 80 (HTTP)
    • Stateful ingress: Source type = CIDR, source 0.0.0.0/0 on TCP, source port = all, destination port = 443 (HTTPS)
    • Stateful egress: Destination type = CIDR, destination CIDR blocks of private subnets on TCP, source port = all, destination port = 1521 (for Oracle databases)
  8. CreateSecurityList: Call it again to create the Private Subnet Security List with these rules:

    • Stateful ingress: Source type = CIDR, source CIDR blocks of public subnets on TCP, source port = all, destination port = 1521 (for Oracle databases)
    • Stateful ingress: Source type = CIDR, source CIDR blocks of private subnets on TCP, source port = all, destination port = 1521 (for Oracle databases)
    • Stateful egress: Destination type = CIDR, destination CIDR blocks of private subnets on TCP, source port = all, destination port = 1521 (for Oracle databases)
  9. CreateSubnet: Call it to create regional public subnet. Include a DNS label for the subnet if you want the VCN Resolver to resolve hostnames for VNICs in the subnet. Use the Public Subnet Route Table you created earlier. Use both the default security list and the Public Subnet Security List that you created earlier. Use the default set of DHCP options.
  10. CreateSubnet: Call it again to create regional private subnet. Include a DNS label for the subnet if you want the VCN Resolver to resolve hostnames for VNICs in the subnet. Use the Private Subnet Route Table you created earlier. Use both the default security list and the Private Subnet Security List that you created earlier. Use the default set of DHCP options.
  11. CreateDrg: This creates a new dynamic routing gateway (DRG).
  12. CreateDrgAttachment: This attaches the DRG to the VCN.
  13. CreateCpe: Here you provide the IP address of the router at your end of the VPN (see Prerequisites).
  14. CreateIPSecConnection: Here you provide the static routes for your on-premises network (see Prerequisites). In return, you receive the configuration information your network administrator needs in order to configure your router. If you need that information later, you can get it with GetIPSecConnectionDeviceConfig. For more information about the configuration, see CPE Configuration.
  15. First call GetRouteTable to get the Private Subnet Route Table. Then call UpdateRouteTable to add a route rule with destination = the on-premises network CIDR (10.0.0.0/16 in this example), and destination target = the DRG you created earlier.
  16. LaunchInstance: Launch at least one instance in each subnet. By default, the instances in the public subnets are assigned public IP addresses. For more information, see Launching an Instance.

You can now communicate from your on-premises network with the instances in the public subnet over the internet gateway.

Important

Although you can launch instances into the private subnets, you can't communicate with them from your on-premises network until your network administrator configures your on-premises router (see CPE Configuration). After that, your IPSec connection should be up and running. You can confirm its status by using GetIPSecConnectionDeviceStatus. You can also confirm the IPSec connection is up by connecting to the instances from your on-premises network.