• April 27, 2018

Creating a Secure Connection Between Oracle Cloud Infrastructure and Other Cloud Providers

Gilson Melo
Senior Principal Product Manager

In today's world, having a secure, encrypted, point-to-point channel through which your data can travel from a specific location to the cloud contributes to a safer solution if you want to avoid breaches and data loss. There are different ways to allow multiple locations to establish secure connections with each other over a public network, such as the internet-like user-based-authentication VPN, IPSec site-to-site technologies, and other third-party application options.

This blog post explains how to create a secure and encrypted IPSec site-to-site tunnel between Oracle Cloud Infrastructure and another third-party cloud provider like Amazon Web Services (AWS) by using Libreswan. This process can also be used with Oracle Cloud Infrastructure Classic and other cloud platforms like Microsoft Azure and Google Cloud, or to connect to your own on-premises data centers. Minor adjustments to the steps, below, might be required for other cloud providers.

Getting Started

The following components are the main requirements for enabling a secure channel between Oracle Cloud Infrastructure and an external third-party network:

  • Provision and configure Oracle Cloud Infrastructure dynamic routing gateways (DRGs) and customer-premises equipment (CPE) through the dashboard
  • A third-party cloud Libreswan instance
  • There is no need of additional hardware 

Configuration Diagram

The following diagram illustrates this configuration:

Configuration Process

At a high level, these are the steps required to create a secure and encrypted IPSec site-to-site tunnel between Oracle Cloud Infrastructure and another third-party cloud provider by using Libreswan. Our example uses AWS as the third-party cloud provider:

  1. Architecture Review.
  2. Provision an AWS Libreswan VM.
  3. Start the Libreswan configuration.
  4. Configure AWS network rules.
  5. Configure the Oracle Cloud Infrastructure DRG and CPE.
  6. Configure the Oracle Cloud Infrastructure network rules.
  7. Configure the Oracle Cloud Infrastructure route information.
  8. Finish the AWS Libreswan configuration by using Oracle Cloud Infrastructure information.
  9. Test the IPSec communication between Oracle Cloud Infrastructure and AWS.


Libreswan uses the terms "left" and "right" to describe endpoints. Left is going to be represented by Oracle Cloud Infrastructure and AWS for right.

The following table shows how to set up these components:

Left Side: Oracle Cloud Infrastructure DRG/CPE

Right Side: Third-Party Cloud Provider Libreswan VM



DRG Public IP: 

Public IP / ID: / i-016ab864b43cb368e


Internal IP:

Location: Oracle Cloud Infrastructure - US-Phoenix-1

Location: Amazon Web Services (AWS) - US East (N. Virginia)


Configure Libreswan on the Third-Party Cloud Provider (AWS, Right Side)

  1. Create a Libreswan VM on AWS by using its provisioning process. Use Oracle Linux, CentOS, or Red Hat as the main operating system.
  2. After the new instance starts, connect to it through SSH and install the libreswan package.
    $ sudo yum -y install libreswan 
  3. Disable source and destination checks on the Libreswan VM instance by right-clicking the instance in the console, selecting Networking, selecting Change Source/Dest. Check, and then clicking Yes, Disable.

  4. Configure IP_forward to allow AWS clients to send and receive traffic through the Libreswan VM. In the /etc/sysctl.conf file, set the following values and apply the updates with sudo sysctl -p.
    net.ipv4.conf.all.accept_redirects = 0
    net.ipv4.conf.all.send_redirects = 0
    net.ipv4.conf.default.send_redirects = 0
    net.ipv4.conf.eth0.send_redirects = 0
    net.ipv4.conf.default.accept_redirects = 0
    net.ipv4.conf.eth0.accept_redirects = 0    
  5. Edit your AWS route table to add a rule that has the Oracle Cloud Infrastructure subnet CIDR ( as the destination and the AWS Libreswan instance ID (i-016ab864b43cb368e) as the target.

  6. Edit AWS security groups and network ACLs, and add TCP/UDP ports 4500 and 500 to allow Oracle Cloud Infrastructure DRG/CPE IPSec communication with the AWS Libreswan VM (the source option can be the Oracle Cloud Infrastructure public IP instead of

  7. Create the Libreswan IPSec configuration file.
    $ sudo mv /etc/ipsec.conf /etc/ipsec.conf.bck
    $ sudo vi /etc/ipsec.conf and include the following
    config setup
    include /etc/ipsec.d/*.conf    

Configure DRG and CPE on Oracle Cloud Infrastructure (Left Side)

  1. Create a customer-premises equipment (CPE) that points to the Libreswan AWS instance public IP address (

  2. Create a DRG and attach it to the Oracle Cloud Infrastructure local VCN (

  3. Create an IPSec connection and point it to the AWS VPC CIDR (

    Initially the IPSec tunnel will be in the DOWN state (offline) because some additional configurations need to be done on the AWS Libreswan VM.

  4. Open ports 500 and 4500 (TCP/UDP) in the Oracle Cloud Infrastructure security list for, as you did with AWS security groups and networks ACLs. You can use the AWS Libreswan VM public IP address instead of if it's a persistent public IP. In addition to that, open ports/protocols for the AWS CIDR (

  5. Add a route rule to the AWS VPC network ( using the DRG and CPE that you just created.

Finish the Third-Party Cloud Provider (AWS) Libreswan Configuration

  1. Connect through SSH to the AWS Libreswan instance and create the Libreswan IPSec connection file.
    $ sudo vi /etc/ipsec.d/oci.conf and include the below options
    conn oci1
         leftid=       #OCI DRG IPSec Public IP
         left=         #OCI DRG IPSec Public IP
         leftsubnets=   #OCI VCN CIDR
         right=            #AWS Libreswan local VPC internal address
         rightid=     #AWS Libreswan Public IP address
         rightsubnet=    #AWS VPC CIDR 
         mark=5/0xffffffff # Needs to be unique across all tunnels
         ikev2=no # To use IKEv2, change to ikev2=insist
     NOTE:Review Access to other Clouds with Libreswan public documentation for current options.
  2. For authentication, use the pre-shared key (PSK) option to create a secret file with a format similar to the following one:
    $ sudo vi /etc/ipsec.secrets
    #OCI_DRG-Public-IP-IPSEC-Tunel1  AWS_OpenSWAN-PublicIP   :   PSK    "DRG Secret Key"    :    PSK    "OCI DRG IPSec Secret Key"	
  3. Run sudo service ipsec restart  to start IPsec and sudo ipsec auto --status |grep "==="  to verify that the tunnels were started correctly.
    $ [centos@ip-10-0-0-10 ~]$  sudo ipsec auto --status |grep "==="
    000 "oci1/1x0":<>[]...<>===; erouted; eroute owner: #7
    000 "v6neighbor-hole-in": ::/0===::1<::1>:58/34560...%any:58/34816===::/0; prospective erouted; eroute owner: #0 
    000 "v6neighbor-hole-out": ::/0===::1<::1>:58/34816...%any:58/34560===::/0; prospective erouted; eroute owner: #0	

The configuration is complete, and in the Oracle Cloud Infrastructure Console, the IPSec tunnel should be the UP state.

Quick IPSec Communication Test Between Oracle Cloud Infrastructure and AWS

Setup has been finalized so it's time to validate the configuration and check if an OCI VM (Left Side) can communicate through an IPSec tunnel with an AWS VM (Right Side). One easy way to check the communication is through the ping command.

The below table explains both sides configuration.

Left Side: Oracle Cloud Infrastructure VM

Right Side - AWS VM

Public IP:

Public IP:

VCN Local IP:

VPC Local IP:


and as the following image illustrates, both Cloud providers VMs can "talk" to each other.


This blog explained how to create a secure and encrypted site-to-site IPSec tunnel between Oracle and Amazon environments allowing the VMs to be able to communicate with each other through their private IP addresses as if they were in the same network segment.

Additional Resources

Join the discussion

Comments ( 2 )
  • Kishlay chaubey Monday, January 28, 2019
    IF i have to make a VPN tunnel between OCI and Azure virtual network , do i still need a Libreswan VM ? Please assist
  • Marcel Boermann-Pfeifer Tuesday, February 12, 2019
    Cool, good example!
    Do You also have the Oracle-side configuration available as oci-cli script somewhere? I could use it instantly with a dear cloud prospect of mine :-)
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.