Yandex Cloud
Search
Contact UsTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Tutorials
    • All tutorials
    • Architecture and protection of a basic web service
    • Cost analysis by resource using Object Storage
        • Solution architecture
        • Unassisted implementation with Yandex Cloud
        • Deploying S2S VPN using strongSwan in Yandex Cloud
        • SGW solution by the Yandex Cloud architect team
      • Connecting to a cloud network using OpenVPN
      • Setting up a UserGate proxy server

In this article:

  • Required paid resources
  • Get your cloud ready
  • Create a service account
  • Create a cloud network
  • Reserve a public static IP address
  • Create an SSH key pair
  • Deploy the application
  • Install the application
  • Bind the route table
  • Configure the VM
  • How to delete the resources you created
  1. Basic infrastructure
  2. VPNs
  3. Establishing network connectivity with the help of IPsec gateways
  4. Deploying S2S VPN using strongSwan in Yandex Cloud

Deploying S2S VPN using strongSwan in Yandex Cloud

Written by
Yandex Cloud
Updated at December 29, 2025
  • Required paid resources
  • Get your cloud ready
  • Create a service account
  • Create a cloud network
  • Reserve a public static IP address
  • Create an SSH key pair
  • Deploy the application
    • Install the application
    • Bind the route table
    • Configure the VM
  • How to delete the resources you created

Follow this tutorial to deploy a secure site-to-site (S2S) VPN connection between a cloud infrastructure in Yandex Cloud and a remote site using a strongSwan-based IPsec gateway. We will do this using the strongSwan S2S VPN application from the Yandex Cloud Apps folder. This application automates the deployment and basic configuration of your IPsec tunnel, allowing you to:

  • Quickly create a secure channel over the public internet.
  • Encrypt traffic between subnets.
  • Integrate cloud resources into the corporate network while maintaining control over routing.

Note

This off-the-shelf application automates infrastructure deployment in Yandex Cloud.

When using strongSwan S2S VPN at a remote location (your on-premises data center, branch office, or another cloud), manual configuration is required.

To deploy a secure connection:

  1. Get your cloud ready.
  2. Create a service account.
  3. Create a cloud network.
  4. Reserve a public static IP address.
  5. Create an SSH key pair.
  6. Deploy the application.

If you no longer need the resources you created, delete them.

Required paid resourcesRequired paid resources

The cost of infrastructure deployment for this solution includes:

  • Fee for a continuously running VM (see Yandex Compute Cloud pricing).
  • Fee for a static external IP address (see Yandex Virtual Private Cloud pricing).
  • Fee for outbound traffic (see Yandex Virtual Private Cloud pricing).

Get your cloud readyGet your cloud ready

Sign up for Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or create a new account.
  2. On the Yandex Cloud Billing page, make sure you have a billing account linked and it has the ACTIVE or TRIAL_ACTIVE status. If you do not have a billing account, create one and link a cloud to it.

If you have an active billing account, you can navigate to the cloud page to create or select a folder for your infrastructure.

Learn more about clouds and folders here.

Create a service accountCreate a service account

Create an s2s-vpn-sa service account to automatically create resources when you install the application. Assign the resource-manager.admin, iam.admin, compute.admin, and vpc.admin roles to it.

Management console
Yandex Cloud CLI
API
  1. Go to Identity and Access Management.

  2. Click Create service account.

  3. Enter a name for the service account: s2s-vpn-sa.

  4. Click Add role and select these roles:

    • resource-manager.admin
    • iam.admin
    • compute.admin
    • vpc.admin
  5. Click Create.

If you do not have the Yandex Cloud CLI installed yet, install and initialize it.

By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.

  1. Create a s2s-vpn-sa service account:

    yc iam service-account create --name s2s-vpn-sa
    

    Result:

    id: nfersamh4sjq********
    folder_id: b1gc1t4cb638********
    created_at: "2023-03-21T10:36:29.726397755Z"
    name: s2s-vpn-sa
    

    Save the ID of the s2s-vpn-sa service account (id) and the ID of the folder where you created it (folder_id).

  2. Assign the resource-manager.admin, iam.admin, compute.admin, and vpc.admin roles for the folder to the service account:

    yc resource-manager folder add-access-binding <folder_ID> \
      --role resource-manager.admin \
      --subject serviceAccount:<service_account_ID>
    
    yc resource-manager folder add-access-binding <folder_ID> \
      --role iam.admin \
      --subject serviceAccount:<service_account_ID>
    
    yc resource-manager folder add-access-binding <folder_ID> \
      --role compute.admin \
      --subject serviceAccount:<service_account_ID>
    
    yc resource-manager folder add-access-binding <folder_ID> \
      --role vpc.admin \
      --subject serviceAccount:<service_account_ID>
    

    Result:

    done (1s)
    

To create a service account, use the create method for the ServiceAccount resource or the ServiceAccountService/Create gRPC API call.

To assign the roles for a folder to a service account, use the setAccessBindings method for the ServiceAccount resource or the ServiceAccountService/SetAccessBindings gRPC API call.

Create a cloud networkCreate a cloud network

Create a cloud network to host the VM.

Management console
Yandex Cloud CLI
API
  1. Go to Virtual Private Cloud.
  2. At the top right, click Create network.
  3. In the Name field, specify s2s-vpn-network.
  4. In the Advanced field, disable Create subnets.
  5. Click Create network.

Run this command:

yc vpc network create s2s-vpn-network

Result:

id: enp1gg8kr3pv********
folder_id: b1gt6g8ht345********
created_at: "2023-12-20T20:08:11Z"
name: s2s-vpn-network
default_security_group_id: enppne4l2eg5********

To create a cloud network, use the create REST API method for the Network resource or the NetworkService/Create gRPC API call.

Reserve a public static IP addressReserve a public static IP address

Reserve a static public IP address for the VM the application will be installed on.

Management console
  1. Go to Virtual Private Cloud.
  2. In the left-hand panel, select IP addresses and click Reserve address.
  3. In the window that opens, select ru-central1-b in the Availability zone field and click ** Reserve**.

Create an SSH key pairCreate an SSH key pair

To connect to a VM over SSH, you will need a key pair: the public key resides on the VM, and the private one is kept by the user. This method is more secure than with a username and password.

Note

SSH connections using a login and password are disabled by default on public Linux images that are provided by Yandex Cloud.

To create a key pair:

Linux/macOS
Windows 10/11
Windows 7/8
  1. Open the terminal.

  2. Use the ssh-keygen command to create a new key:

    ssh-keygen -t ed25519 -C "<optional_comment>"
    

    You can specify an empty string in the -C parameter to avoid adding a comment, or you may not specify the -C parameter at all: in this case, a default comment will be added.

    After running this command, you will be prompted to specify the name and path to the key files, as well as enter the password for the private key. If you only specify the name, the key pair will be created in the current directory. The public key will be saved in a file with the .pub extension, while the private key, in a file without extension.

    By default, the command prompts you to save the key under the id_ed25519 name in the following directory: /home/<username>/.ssh. If there is already an SSH key named id_ed25519 in this directory, you may accidentally overwrite it and lose access to the resources it is used in. Therefore, you may want to use unique names for all SSH keys.

If you do not have OpenSSH installed yet, follow this guide to install it.

  1. Run cmd.exe or powershell.exe (make sure to update PowerShell before doing so).

  2. Use the ssh-keygen command to create a new key:

    ssh-keygen -t ed25519 -C "<optional_comment>"
    

    You can specify an empty string in the -C parameter to avoid adding a comment, or you may not specify the -C parameter at all: in this case, a default comment will be added.

    After running this command, you will be prompted to specify the name and path to the key files, as well as enter the password for the private key. If you only specify the name, the key pair will be created in the current directory. The public key will be saved in a file with the .pub extension, while the private key, in a file without extension.

    By default, the command prompts you to save the key under the id_ed25519 name in the following folder: C:\Users\<username>/.ssh. If there is already an SSH key named id_ed25519 in this directory, you may accidentally overwrite it and lose access to the resources it is used in. Therefore, you may want to use unique names for all SSH keys.

Create keys using the PuTTY app:

  1. Download and install PuTTY.

  2. Add the folder with PuTTY to the PATH variable:

    1. Click Start and type Change system environment variables in the Windows search bar.
    2. Click Environment Variables... at the bottom right.
    3. In the window that opens, find the PATH parameter and click Edit.
    4. Add your folder path to the list.
    5. Click OK.
  3. Launch the PuTTYgen app.

  4. Select EdDSA as the pair type to generate. Click Generate and move the cursor in the field above it until key creation is complete.

    ssh_generate_key

  5. In Key passphrase, enter a strong password. Enter it again in the field below.

  6. Click Save private key and save the private key. Do not share its key phrase with anyone.

  7. Click Save public key and save the public key to a file named <key_name>.pub.

Deploy the applicationDeploy the application

Install the applicationInstall the application

As a result of the installation, the following Yandex Cloud resources will be automatically created:

  • Service account
  • Subnet
  • IP_address
  • Route table
  • Security group
  • VM

Warning

Make sure the target cloud has not reached its quota:

  • Number of service accounts
  • Number of subnets
  • Number of static public IP addresses
  • Number of routing tables
  • Number of static routes
  • Number of security groups
  • Number of instances
  • Number of disks
  • Total SSD capacity
  • Total RAM for instances

If any quota has been used up, create a quota increase request and wait for it to be granted.

Management console
  1. Go to Cloud Apps.

  2. In the left-hand panel, select Marketplace.

  3. In the Search products field, type strongswan, select strongSwan S2S VPN, and click Use.

  4. In the window that opens, specify the following:

    • Name: s2s-vpn.
    • Service account: s2s-vpn-sa.
    • VPC network: s2s-vpn-network.
    • New subnet CIDR: 10.130.0.0/24.
    • New subnet zone: ru-central1-b.
    • Remote gateway IP address: IP address of the remote VPN gateway that will be added to the strongSwan configuration.
    • Remote subnet CIDRs: Comma-separated list of subnets as CIDRs that will be automatically added to the route table.
    • SSH key: Contents of the public SSH key created earlier.
    • IPsec IKE Proposal: aes128gcm16-prfsha256-ecp256.
    • IPsec ESP Proposal: aes128gcm16.
    • IPsec PSK: IPsec Pre-Shared Key (PSK) that will be specified in the strongSwan configuration.
  5. Click Install and wait for the installation to complete.

Bind the route tableBind the route table

To route traffic between a cloud and remote networks through the VPN tunnel, bind the route table and subnet.

Management console
Yandex Cloud CLI
API
  1. Go to Virtual Private Cloud.
  2. In the left-hand panel, select Subnets.
  3. In the line of the automatically created ipsec-sgw-... subnet, click → Link routing table and select the automatically created ipsec-sgw-... table.
  4. Click Link.

Run this command:

yc vpc subnet update <name_of_automatically_created_subnet> \
  --route-table-name=<name_of_automatically_created_table>

Result:

id: e9b6n3jj3gh6********
folder_id: b1g681qpemb4********
created_at: "2024-05-19T13:24:58Z"
name: ipsec-sgw-ru-central1-b
network_id: enppoggov6ub********
zone_id: ru-central1-b
v4_cidr_blocks:
  - 10.1.0.0/16
route_table_id: enp4v8foko6s********
dhcp_options: {}

To associate a route table with a subnet, use the update REST API method for the Subnet resource or the SubnetService/Update gRPC API call.

Warning

The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the updateMask parameter as a single comma-separated string.

Configure the VMConfigure the VM

After you install the application, perform the final configuration of the IPsec gateway on the VM.

  1. Connect to the VM over SSH. To this using the admin username and the private SSH key you created earlier.

  2. Get administrator permissions:

    sudo su
    
  3. Go to the administrator's home folder and run the script:

    cd /root
    ./update.sh
    

    The system will create the ipsec-*.txt files in the /root folder. You can use these files as an example when configuring a connection on a remote endpoint.

    Tip

    If the IP ranges of Yandex Cloud and the remote network match, you may need to use Source NAT. To do this, run this command:

    iptables \
      -t nat \
      -A POSTROUTING \
      -s <local_subnet> \
      -d <remote_subnet> \
      -j SNAT \
      --to-source <new_address>
    

How to delete the resources you createdHow to delete the resources you created

To stop paying for the resources you created:

  • Uninstall strongSwan S2S VPN:

    1. Go to Cloud Apps.

    2. In the line with the application, click → Delete and confirm the deletion.

      Deleting the application will delete all resources associated with it.

  • Delete the route table.

  • Delete the service account.

  • Delete the static public IP address.

  • Delete the cloud network.

Was the article helpful?

Previous
Unassisted implementation with Yandex Cloud
Next
SGW solution by the Yandex Cloud architect team
© 2025 Direct Cursus Technology L.L.C.